mirror of https://github.com/tikv/client-go.git
util: make reduce tsset object allocation (#218)
Signed-off-by: tiancaiamao <tiancaiamao@gmail.com>
This commit is contained in:
parent
16fb6792bf
commit
a1adc5b85b
|
|
@ -104,7 +104,7 @@ type KVSnapshot struct {
|
|||
keyOnly bool
|
||||
vars *kv.Variables
|
||||
replicaReadSeed uint32
|
||||
resolvedLocks *util.TSSet
|
||||
resolvedLocks util.TSSet
|
||||
scanBatchSize int
|
||||
|
||||
// Cache the result of BatchGet.
|
||||
|
|
@ -146,7 +146,6 @@ func newTiKVSnapshot(store *KVStore, ts uint64, replicaReadSeed uint32) *KVSnaps
|
|||
priority: PriorityNormal,
|
||||
vars: kv.DefaultVars,
|
||||
replicaReadSeed: replicaReadSeed,
|
||||
resolvedLocks: util.NewTSSet(5),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -164,8 +163,6 @@ func (s *KVSnapshot) SetSnapshotTS(ts uint64) {
|
|||
s.mu.Lock()
|
||||
s.mu.cached = nil
|
||||
s.mu.Unlock()
|
||||
// And also the minCommitTS pushed information.
|
||||
s.resolvedLocks = util.NewTSSet(5)
|
||||
}
|
||||
|
||||
// BatchGet gets all the keys' value from kv-server and returns a map contains key/value pairs.
|
||||
|
|
@ -328,7 +325,7 @@ func (s *KVSnapshot) batchGetKeysByRegions(bo *Backoffer, keys [][]byte, collect
|
|||
}
|
||||
|
||||
func (s *KVSnapshot) batchGetSingleRegion(bo *Backoffer, batch batchKeys, collectF func(k, v []byte)) error {
|
||||
cli := NewClientHelper(s.store, s.resolvedLocks)
|
||||
cli := NewClientHelper(s.store, &s.resolvedLocks)
|
||||
s.mu.RLock()
|
||||
if s.mu.stats != nil {
|
||||
cli.Stats = make(map[tikvrpc.CmdType]*locate.RPCRuntimeStats)
|
||||
|
|
@ -497,7 +494,7 @@ func (s *KVSnapshot) get(ctx context.Context, bo *Backoffer, k []byte) ([]byte,
|
|||
}
|
||||
})
|
||||
|
||||
cli := NewClientHelper(s.store, s.resolvedLocks)
|
||||
cli := NewClientHelper(s.store, &s.resolvedLocks)
|
||||
|
||||
s.mu.RLock()
|
||||
if s.mu.stats != nil {
|
||||
|
|
|
|||
|
|
@ -40,17 +40,18 @@ type TSSet struct {
|
|||
m map[uint64]struct{}
|
||||
}
|
||||
|
||||
// NewTSSet creates a set to store timestamps.
|
||||
func NewTSSet(capacity int) *TSSet {
|
||||
return &TSSet{
|
||||
m: make(map[uint64]struct{}, capacity),
|
||||
}
|
||||
}
|
||||
|
||||
// Put puts timestamps into the map.
|
||||
func (s *TSSet) Put(tss ...uint64) {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
|
||||
// Lazy initialization..
|
||||
// Most of the time, there is no transaction lock conflict.
|
||||
// So allocate this in advance is unnecessary and bad for performance.
|
||||
if s.m == nil {
|
||||
s.m = make(map[uint64]struct{}, 5)
|
||||
}
|
||||
|
||||
for _, ts := range tss {
|
||||
s.m[ts] = struct{}{}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue