mirror of https://github.com/status-im/consul.git
consul: State store can return the tables for a query, and watch for changes
This commit is contained in:
parent
f0205e1974
commit
985e3a0529
|
@ -30,6 +30,7 @@ type StateStore struct {
|
||||||
checkTable *MDBTable
|
checkTable *MDBTable
|
||||||
tables MDBTables
|
tables MDBTables
|
||||||
watch map[*MDBTable]*NotifyGroup
|
watch map[*MDBTable]*NotifyGroup
|
||||||
|
queryTables map[string]MDBTables
|
||||||
}
|
}
|
||||||
|
|
||||||
// StateSnapshot is used to provide a point-in-time snapshot
|
// StateSnapshot is used to provide a point-in-time snapshot
|
||||||
|
@ -190,9 +191,27 @@ func (s *StateStore) initialize() error {
|
||||||
// Setup a notification group per table
|
// Setup a notification group per table
|
||||||
s.watch[table] = &NotifyGroup{}
|
s.watch[table] = &NotifyGroup{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Setup the query tables
|
||||||
|
// TODO: Other queries...
|
||||||
|
s.queryTables = map[string]MDBTables{
|
||||||
|
"Nodes": MDBTables{s.nodeTable},
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Watch is used to subscribe a channel to a set of MDBTables
|
||||||
|
func (s *StateStore) Watch(tables MDBTables, notify chan struct{}) {
|
||||||
|
for _, t := range tables {
|
||||||
|
s.watch[t].Wait(notify)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryTables returns the Tables that are queried for a given query
|
||||||
|
func (s *StateStore) QueryTables(q string) MDBTables {
|
||||||
|
return s.queryTables[q]
|
||||||
|
}
|
||||||
|
|
||||||
// EnsureNode is used to ensure a given node exists, with the provided address
|
// EnsureNode is used to ensure a given node exists, with the provided address
|
||||||
func (s *StateStore) EnsureNode(index uint64, node structs.Node) error {
|
func (s *StateStore) EnsureNode(index uint64, node structs.Node) error {
|
||||||
// Start a new txn
|
// Start a new txn
|
||||||
|
|
Loading…
Reference in New Issue