Merge branch 'feat/raft'

# Conflicts:
#	cluster/cluster.go
#	cluster/router.go
#	config/config.go
#	database/database.go
#	database/server.go
This commit is contained in:
finley
2023-06-10 23:01:30 +08:00
56 changed files with 3147 additions and 714 deletions

View File

@@ -219,7 +219,7 @@ func (dict *ConcurrentDict) PutIfExistsWithLock(key string, val interface{}) (re
}
// Remove removes the key and return the number of deleted key-value
func (dict *ConcurrentDict) Remove(key string) (result int) {
func (dict *ConcurrentDict) Remove(key string) (val interface{}, result int) {
if dict == nil {
panic("dict is nil")
}
@@ -229,15 +229,15 @@ func (dict *ConcurrentDict) Remove(key string) (result int) {
s.mutex.Lock()
defer s.mutex.Unlock()
if _, ok := s.m[key]; ok {
if val, ok := s.m[key]; ok {
delete(s.m, key)
dict.decreaseCount()
return 1
return val, 1
}
return 0
return nil, 0
}
func (dict *ConcurrentDict) RemoveWithLock(key string) (result int) {
func (dict *ConcurrentDict) RemoveWithLock(key string) (val interface{}, result int) {
if dict == nil {
panic("dict is nil")
}
@@ -245,12 +245,12 @@ func (dict *ConcurrentDict) RemoveWithLock(key string) (result int) {
index := dict.spread(hashCode)
s := dict.getShard(index)
if _, ok := s.m[key]; ok {
if val, ok := s.m[key]; ok {
delete(s.m, key)
dict.decreaseCount()
return 1
return val, 1
}
return 0
return val, 0
}
func (dict *ConcurrentDict) addCount() int32 {