mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-09-07 00:55:55 +00:00
more coordinator/primary cleanup
This commit is contained in:
parent
f5c1454a0d
commit
b80f5099b2
5 changed files with 18 additions and 29 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue