Merge pull request #417 from kuba--/rev-mtx

Change order of cluster/index locks
This commit is contained in:
Kuba Podgórski 2020-06-03 15:37:20 +02:00 committed by GitHub
commit 0bba9c81e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View file

@ -1044,6 +1044,11 @@ func (c *cluster) partitionNodes(partitionID int) []*Node {
func (c *cluster) ownsPartition(nodeID string, partition int) bool {
c.mu.RLock()
defer c.mu.RUnlock()
return c.unprotectedOwnsPartition(nodeID, partition)
}
// unprotectedOwnsPartition returns true if a host owns a partition.
func (c *cluster) unprotectedOwnsPartition(nodeID string, partition int) bool {
return Nodes(c.partitionNodes(partition)).ContainsID(nodeID)
}

View file

@ -1120,7 +1120,8 @@ func (s *holderSyncer) stopTranslationSync() error {
// writing new translation keys. Index stores are writable if the node owns the
// partition. Field stores are writable if the node is the coordinator.
func (s *holderSyncer) setTranslateReadOnlyFlags() {
isCoordinator := s.Cluster.isCoordinator()
s.Cluster.mu.RLock()
isCoordinator := s.Cluster.unprotectedIsCoordinator()
for _, index := range s.Holder.Indexes() {
// There is a race condition here:
@ -1140,7 +1141,7 @@ func (s *holderSyncer) setTranslateReadOnlyFlags() {
// done using it.
index.mu.RLock()
for partitionID := 0; partitionID < s.Cluster.partitionN; partitionID++ {
ownsPartition := s.Cluster.ownsPartition(s.Node.ID, partitionID)
ownsPartition := s.Cluster.unprotectedOwnsPartition(s.Node.ID, partitionID)
if ts := index.TranslateStore(partitionID); ts != nil {
ts.SetReadOnly(!ownsPartition)
}
@ -1151,6 +1152,7 @@ func (s *holderSyncer) setTranslateReadOnlyFlags() {
field.TranslateStore().SetReadOnly(!isCoordinator)
}
}
s.Cluster.mu.RUnlock()
}
// initializeIndexTranslateReplication connects to each node that is the