From 420417861a1371927147ef36da2861c5657c52f3 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 4 Feb 2014 18:37:38 -0800 Subject: [PATCH] consul: Move notification group from MDBTable into the state store --- consul/mdb_table.go | 8 -------- consul/state_store.go | 9 +++++++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/consul/mdb_table.go b/consul/mdb_table.go index acafb68fa2..f08dc9b809 100644 --- a/consul/mdb_table.go +++ b/consul/mdb_table.go @@ -34,11 +34,6 @@ type MDBTable struct { Encoder func(interface{}) []byte Decoder func([]byte) interface{} - // NotifyGroup is created in init, it can be used to - // watch a table for changes. It is not invoked internally, - // but can be used by clients of the table. - NotifyGroup *NotifyGroup - // Last used rowID lastRowID uint64 } @@ -104,9 +99,6 @@ func (t *MDBTable) Init() error { return fmt.Errorf("Missing table indexes") } - // Create the notify group - t.NotifyGroup = &NotifyGroup{} - // Ensure we have a unique id index id, ok := t.Indexes["id"] if !ok { diff --git a/consul/state_store.go b/consul/state_store.go index 8aa0c6fad4..f5f6840041 100644 --- a/consul/state_store.go +++ b/consul/state_store.go @@ -29,6 +29,7 @@ type StateStore struct { serviceTable *MDBTable checkTable *MDBTable tables MDBTables + watch map[*MDBTable]*NotifyGroup } // StateSnapshot is used to provide a point-in-time snapshot @@ -60,8 +61,9 @@ func NewStateStore() (*StateStore, error) { } s := &StateStore{ - path: path, - env: env, + path: path, + env: env, + watch: make(map[*MDBTable]*NotifyGroup), } // Ensure we can initialize @@ -184,6 +186,9 @@ func (s *StateStore) initialize() error { if err := table.Init(); err != nil { return err } + + // Setup a notification group per table + s.watch[table] = &NotifyGroup{} } return nil }