consul: Move notification group from MDBTable into the state store

This commit is contained in:
Armon Dadgar 2014-02-04 18:37:38 -08:00
parent 67a7d25e1c
commit 420417861a
2 changed files with 7 additions and 10 deletions

View File

@ -34,11 +34,6 @@ type MDBTable struct {
Encoder func(interface{}) []byte Encoder func(interface{}) []byte
Decoder func([]byte) interface{} 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 // Last used rowID
lastRowID uint64 lastRowID uint64
} }
@ -104,9 +99,6 @@ func (t *MDBTable) Init() error {
return fmt.Errorf("Missing table indexes") return fmt.Errorf("Missing table indexes")
} }
// Create the notify group
t.NotifyGroup = &NotifyGroup{}
// Ensure we have a unique id index // Ensure we have a unique id index
id, ok := t.Indexes["id"] id, ok := t.Indexes["id"]
if !ok { if !ok {

View File

@ -29,6 +29,7 @@ type StateStore struct {
serviceTable *MDBTable serviceTable *MDBTable
checkTable *MDBTable checkTable *MDBTable
tables MDBTables tables MDBTables
watch map[*MDBTable]*NotifyGroup
} }
// StateSnapshot is used to provide a point-in-time snapshot // StateSnapshot is used to provide a point-in-time snapshot
@ -62,6 +63,7 @@ func NewStateStore() (*StateStore, error) {
s := &StateStore{ s := &StateStore{
path: path, path: path,
env: env, env: env,
watch: make(map[*MDBTable]*NotifyGroup),
} }
// Ensure we can initialize // Ensure we can initialize
@ -184,6 +186,9 @@ func (s *StateStore) initialize() error {
if err := table.Init(); err != nil { if err := table.Init(); err != nil {
return err return err
} }
// Setup a notification group per table
s.watch[table] = &NotifyGroup{}
} }
return nil return nil
} }