From 985e3a0529ea8bec7a6f7d179ad68f51efe5eeda Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Wed, 5 Feb 2014 10:37:28 -0800 Subject: [PATCH] consul: State store can return the tables for a query, and watch for changes --- consul/state_store.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/consul/state_store.go b/consul/state_store.go index 87a53a16b7..52e051d88c 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -30,6 +30,7 @@ type StateStore struct { checkTable *MDBTable tables MDBTables watch map[*MDBTable]*NotifyGroup + queryTables map[string]MDBTables } // 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 s.watch[table] = &NotifyGroup{} } + + // Setup the query tables + // TODO: Other queries... + s.queryTables = map[string]MDBTables{ + "Nodes": MDBTables{s.nodeTable}, + } 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 func (s *StateStore) EnsureNode(index uint64, node structs.Node) error { // Start a new txn