forked from canonical/go-dqlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app: Replace node index with clusterState struct holding also metadata
- Loading branch information
1 parent
9eead0c
commit 958ac62
Showing
2 changed files
with
67 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package app | ||
|
||
import ( | ||
"github.com/canonical/go-dqlite/client" | ||
) | ||
|
||
// Map each node to its metadata. If the node is offline, map to nil. | ||
type clusterState map[client.NodeInfo]*client.NodeMetadata | ||
|
||
// Count returns the number of online or offline nodes with the given role. | ||
func (c clusterState) Count(role client.NodeRole, online bool) int { | ||
return len(c.List(role, online)) | ||
} | ||
|
||
// List returns the online or offline nodes with the given role. | ||
func (c clusterState) List(role client.NodeRole, online bool) []client.NodeInfo { | ||
nodes := []client.NodeInfo{} | ||
for node, metadata := range c { | ||
if node.Role == role && metadata != nil == online { | ||
nodes = append(nodes, node) | ||
} | ||
} | ||
return nodes | ||
} | ||
|
||
const minVoters = 3 |