diff --git a/cluster.go b/cluster.go index aed23c3a2..2046f9f46 100644 --- a/cluster.go +++ b/cluster.go @@ -1526,8 +1526,7 @@ func (c *cluster) completeCurrentJob(state string) error { func (c *cluster) unprotectedCompleteCurrentJob(state string) error { // Create a snapshot of the cluster to use for node/partition calculations. snap := topology.NewClusterSnapshot(c.unprotectedNoder, c.Hasher, c.ReplicaN) - // TODO: this needs to become: IsPrimaryFieldTranslationNode(c.Node.ID) - if !snap.IsCoordinatorNode(c.Node.ID) { + if !snap.IsPrimaryFieldTranslationNode(c.Node.ID) { return ErrNodeNotCoordinator } if c.currentJob == nil { diff --git a/holder.go b/holder.go index a36beef14..01e628398 100644 --- a/holder.go +++ b/holder.go @@ -1628,8 +1628,7 @@ func (s *holderSyncer) stopTranslationSync() error { // partition. Field stores are writable if the node is the coordinator. func (s *holderSyncer) setTranslateReadOnlyFlags(snap *topology.ClusterSnapshot) { s.Cluster.mu.RLock() - // TODO: this needs to become: IsPrimaryFieldTranslationNode(s.Cluster.Node.ID) { - isPrimaryFieldTranslator := snap.IsCoordinatorNode(s.Cluster.Node.ID) + isPrimaryFieldTranslator := snap.IsPrimaryFieldTranslationNode(s.Cluster.Node.ID) for _, index := range s.Holder.Indexes() { // There is a race condition here: @@ -1723,8 +1722,7 @@ func (s *holderSyncer) initializeIndexTranslateReplication(snap *topology.Cluste // initializeFieldTranslateReplication connects the coordinator to stream field data. func (s *holderSyncer) initializeFieldTranslateReplication(snap *topology.ClusterSnapshot) error { // Skip if coordinator. - // TODO: this needs to become: IsPrimaryFieldTranslationNode(s.Cluster.Node.ID) { - if !snap.IsCoordinatorNode(s.Cluster.Node.ID) { + if !snap.IsPrimaryFieldTranslationNode(s.Cluster.Node.ID) { return nil } diff --git a/http/client_test.go b/http/client_test.go index 1ffe80ef9..c89ee7dd4 100644 --- a/http/client_test.go +++ b/http/client_test.go @@ -1226,19 +1226,7 @@ func TestClientTransactions(t *testing.T) { defer c.Close() coord := c.GetCoordinator() - if coord == nil { - t.Fatal("no coordinator node") - } - var other *test.Command - - node0 := c.GetNode(0) - node1 := c.GetNode(1) - - if coord == node0 { - other = node1 - } else { - other = node0 - } + other := c.GetNonCoordinator() client0 := MustNewClient(coord.URL(), http.GetHTTPClient(nil)) client1 := MustNewClient(other.URL(), http.GetHTTPClient(nil)) diff --git a/test/cluster.go b/test/cluster.go index a72ccc497..d7dd224c2 100644 --- a/test/cluster.go +++ b/test/cluster.go @@ -147,6 +147,7 @@ func (c *Cluster) GetCoordinator() *Command { return nil } +// GetNonCoordinator gets first first non-coordinator node in the list of nodes. func (c *Cluster) GetNonCoordinator() *Command { for _, n := range c.Nodes { if !n.IsCoordinator() { @@ -156,6 +157,17 @@ func (c *Cluster) GetNonCoordinator() *Command { return nil } +// GetNonCoordinators gets all nodes except the coordinator. +func (c *Cluster) GetNonCoordinators() []*Command { + rtn := make([]*Command, 0) + for _, n := range c.Nodes { + if !n.IsCoordinator() { + rtn = append(rtn, n) + } + } + return rtn +} + // nodePlace represents a node's ID and its index into the c.Nodes slice. type nodePlace struct { id string diff --git a/topology/snapshot.go b/topology/snapshot.go index cb79b7582..da87aa522 100644 --- a/topology/snapshot.go +++ b/topology/snapshot.go @@ -139,27 +139,19 @@ func (c *ClusterSnapshot) PartitionNodes(partitionID int) []*Node { // field keys. The primary could be any node in the cluster, but we arbitrarily // define it to be the node responsible for partition 0. func (c *ClusterSnapshot) PrimaryFieldTranslationNode() *Node { + // return c.PrimaryPartitionNode(0) for _, n := range c.Nodes { if n.IsCoordinator { return n } } return nil - - // return c.PrimaryPartitionNode(0) } // IsPrimaryFieldTranslationNode returns true if nodeID represents the primary // node responsible for field translation. func (c *ClusterSnapshot) IsPrimaryFieldTranslationNode(nodeID string) bool { - return c.IsCoordinatorNode(nodeID) - //c.PrimaryFieldTranslationNode().ID == nodeID -} - -// IsCoordinatorNode returns true if nodeID represents the coordinator -// node responsible for field translation. TODO: this is temporary until -// we transition over to using primary -func (c *ClusterSnapshot) IsCoordinatorNode(nodeID string) bool { + // return c.PrimaryFieldTranslationNode().ID == nodeID for i := range c.Nodes { if c.Nodes[i].ID == nodeID && c.Nodes[i].IsCoordinator { return true