Просмотр исходного кода

rafthttp: make "ActiveSince" non-blocking on write lock

"ActiveSince" is read-only, and should be able to call
concurrently, as long as there is no routine holding
write lock (send, send snapshot).

e.g. "ActiveSince" is used around etcd server
"processInternalRaftRequestOnce", should be non-blocking

Signed-off-by: Gyuho Lee <gyuhox@gmail.com>
Gyuho Lee 8 лет назад
Родитель
Сommit
fbe6767570
1 измененных файлов с 2 добавлено и 2 удалено
  1. 2 2
      rafthttp/transport.go

+ 2 - 2
rafthttp/transport.go

@@ -338,8 +338,8 @@ func (t *Transport) UpdatePeer(id types.ID, us []string) {
 }
 
 func (t *Transport) ActiveSince(id types.ID) time.Time {
-	t.mu.Lock()
-	defer t.mu.Unlock()
+	t.mu.RLock()
+	defer t.mu.RUnlock()
 	if p, ok := t.peers[id]; ok {
 		return p.activeSince()
 	}