From a8c366e9dfd6bb8cbb17a4bacc2000acc5eebf5b Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Tue, 4 Feb 2014 12:32:05 -0800 Subject: [PATCH] consul: Add a NotifyGroup to the MDBTable --- consul/mdb_table.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/consul/mdb_table.go b/consul/mdb_table.go index f1ad49a8b..4662f23fc 100644 --- a/consul/mdb_table.go +++ b/consul/mdb_table.go @@ -28,12 +28,19 @@ const ( using a row id, while maintaining any number of secondary indexes. */ type MDBTable struct { - lastRowID uint64 // Last used rowID - Env *mdb.Env - Name string // This is the name of the table, must be unique - Indexes map[string]*MDBIndex - Encoder func(interface{}) []byte - Decoder func([]byte) interface{} + Env *mdb.Env + Name string // This is the name of the table, must be unique + Indexes map[string]*MDBIndex + 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 } // MDBTables is used for when we have a collection of tables @@ -97,6 +104,9 @@ 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 {