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)
| 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 |
| 88 | func (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 |
| 109 | func (p *PeerDataNodeServerImpl) ReleaseToken(tableName string, shardID uint32) { |
nothing calls this directly
no test coverage detected