MCPcopy Index your code
hub / github.com/uber/aresdb / AcquireToken

Method AcquireToken

datanode/bootstrap/bootstrap_server.go:88–106  ·  view source on GitHub ↗

AcquireToken is to check if any bootstrap is running in the table/shard if no bootstrap session is running on the table/shard, it will increase the token count, and return true the caller need to release the usage by calling ReleaseToken

(tableName string, shardID uint32)

Source from the content-addressed store, hash-verified

86// if no bootstrap session is running on the table/shard, it will increase the token count, and return true
87// the caller need to release the usage by calling ReleaseToken
88func (p *PeerDataNodeServerImpl) AcquireToken(tableName string, shardID uint32) bool {
89 p.Lock()
90 defer p.Unlock()
91
92 // lazy clean the obsolete orphan sessions
93 now := utils.Now()
94 for sid, session := range p.sessions {
95 if now.After(session.lastLiveTime.Add(time.Second * time.Duration(session.ttl))) {
96 p.cleanSession(sid, false)
97 }
98 }
99
100 key := tableShardPair{table: tableName, shardID: shardID}
101 sessionIDs, ok := p.tableShardSessions[key]
102 if !ok || len(sessionIDs) == 0 {
103 return true
104 }
105 return false
106}
107
108// AcquireToken release the token count, must call this when call AcquireToken success
109func (p *PeerDataNodeServerImpl) ReleaseToken(tableName string, shardID uint32) {

Callers

nothing calls this directly

Calls 5

cleanSessionMethod · 0.95
NowFunction · 0.92
AddMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by

no test coverage detected