refactor: standardized code

master
710leo 5 years ago
parent 7f1a947226
commit 9c129acdb4

File diff suppressed because it is too large Load Diff

@ -36,49 +36,49 @@ func NewIndexCacheBase(max int) *IndexCacheBase {
return &IndexCacheBase{maxSize: max, data: make(map[interface{}]*dataobj.TsdbItem)}
}
func (this *IndexCacheBase) Put(key interface{}, item *dataobj.TsdbItem) {
this.Lock()
defer this.Unlock()
this.data[key] = item
func (i *IndexCacheBase) Put(key interface{}, item *dataobj.TsdbItem) {
i.Lock()
defer i.Unlock()
i.data[key] = item
}
func (this *IndexCacheBase) Get(key interface{}) *dataobj.TsdbItem {
this.RLock()
defer this.RUnlock()
return this.data[key]
func (i *IndexCacheBase) Get(key interface{}) *dataobj.TsdbItem {
i.RLock()
defer i.RUnlock()
return i.data[key]
}
func (this *IndexCacheBase) ContainsKey(key interface{}) bool {
this.RLock()
defer this.RUnlock()
return this.data[key] != nil
func (i *IndexCacheBase) ContainsKey(key interface{}) bool {
i.RLock()
defer i.RUnlock()
return i.data[key] != nil
}
func (this *IndexCacheBase) Size() int {
this.RLock()
defer this.RUnlock()
return len(this.data)
func (i *IndexCacheBase) Size() int {
i.RLock()
defer i.RUnlock()
return len(i.data)
}
func (this *IndexCacheBase) Keys() []interface{} {
this.RLock()
defer this.RUnlock()
func (i *IndexCacheBase) Keys() []interface{} {
i.RLock()
defer i.RUnlock()
count := len(this.data)
count := len(i.data)
if count == 0 {
return []interface{}{}
}
keys := make([]interface{}, 0, count)
for key := range this.data {
for key := range i.data {
keys = append(keys, key)
}
return keys
}
func (this *IndexCacheBase) Remove(key interface{}) {
this.Lock()
defer this.Unlock()
delete(this.data, key)
func (i *IndexCacheBase) Remove(key interface{}) {
i.Lock()
defer i.Unlock()
delete(i.data, key)
}

@ -11,25 +11,25 @@ type ConsistentHashRing struct {
ring *consistent.Consistent
}
func (this *ConsistentHashRing) GetNode(pk string) (string, error) {
this.RLock()
defer this.RUnlock()
func (c *ConsistentHashRing) GetNode(pk string) (string, error) {
c.RLock()
defer c.RUnlock()
return this.ring.Get(pk)
return c.ring.Get(pk)
}
func (this *ConsistentHashRing) Set(r *consistent.Consistent) {
this.Lock()
defer this.Unlock()
this.ring = r
func (c *ConsistentHashRing) Set(r *consistent.Consistent) {
c.Lock()
defer c.Unlock()
c.ring = r
return
}
func (this *ConsistentHashRing) GetRing() *consistent.Consistent {
this.RLock()
defer this.RUnlock()
func (c *ConsistentHashRing) GetRing() *consistent.Consistent {
c.RLock()
defer c.RUnlock()
return this.ring
return c.ring
}
func NewConsistentHashRing(replicas int32, nodes []string) *ConsistentHashRing {

Loading…
Cancel
Save