Skip to content

Commit

Permalink
Merge pull request #5 from mavenugo/master
Browse files Browse the repository at this point in the history
Populate distributed cache from local on first node-update
  • Loading branch information
mavenugo committed Jan 11, 2015
2 parents 79b9bcf + 2e6ea1c commit adff38e
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions ecc.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

var started bool
var OfflineSupport bool = true
var listener eccListener

func Start(serverMode bool, bootstrap bool, bindInterface string, dataDir string) error {
watches = make(map[WatchType]watchData)
Expand All @@ -51,14 +52,14 @@ func Start(serverMode bool, bootstrap bool, bindInterface string, dataDir string
}
}
errCh := make(chan int)
go RegisterForNodeUpdates(listener)
go startConsul(serverMode, bootstrap, bindAddress, dataDir, errCh)

select {
case <-errCh:
return errors.New("Error starting Consul Agent")
case <-time.After(time.Second * 5):
}
go populateKVStoreFromCache()
return nil
}

Expand Down Expand Up @@ -337,7 +338,7 @@ func deleteFromCache(storeName string, key string) eccerror {
}

func populateKVStoreFromCache() {
if !OfflineSupport {
if !OfflineSupport || started {
return
}
started = true
Expand Down Expand Up @@ -380,6 +381,20 @@ type Listener interface {
NotifyStoreUpdate(NotifyUpdateType, string, map[string][]byte)
}

type eccListener struct {
}

func (e eccListener) NotifyNodeUpdate(nType NotifyUpdateType, nodeAddress string) {
if nType == NOTIFY_UPDATE_ADD && !started {
populateKVStoreFromCache()
}
}

func (e eccListener) NotifyKeyUpdate(nType NotifyUpdateType, key string, data []byte) {
}
func (e eccListener) NotifyStoreUpdate(nType NotifyUpdateType, store string, data map[string][]byte) {
}

func contains(wtype WatchType, key string, elem interface{}) bool {
ws, ok := watches[wtype]
if !ok {
Expand Down Expand Up @@ -483,6 +498,7 @@ func updateNodeListeners(clusterNodes []*consulapi.Node) {
listener.NotifyNodeUpdate(NOTIFY_UPDATE_DELETE, deleteNode.Address)
}
}

for _, addNode := range toAdd {
for _, listener := range listeners {
listener.NotifyNodeUpdate(NOTIFY_UPDATE_ADD, addNode.Address)
Expand Down

0 comments on commit adff38e

Please sign in to comment.