mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Cleanup networkdb state when the network is deleted locally
Signed-off-by: Santhosh Manohar <santhosh@docker.com>
This commit is contained in:
parent
0a1c09d685
commit
2bab9b6bdb
3 changed files with 45 additions and 2 deletions
|
@ -305,7 +305,10 @@ func (nDB *NetworkDB) gossip() {
|
||||||
func (nDB *NetworkDB) bulkSyncTables() {
|
func (nDB *NetworkDB) bulkSyncTables() {
|
||||||
var networks []string
|
var networks []string
|
||||||
nDB.RLock()
|
nDB.RLock()
|
||||||
for nid := range nDB.networks[nDB.config.NodeName] {
|
for nid, network := range nDB.networks[nDB.config.NodeName] {
|
||||||
|
if network.leaving {
|
||||||
|
continue
|
||||||
|
}
|
||||||
networks = append(networks, nid)
|
networks = append(networks, nid)
|
||||||
}
|
}
|
||||||
nDB.RUnlock()
|
nDB.RUnlock()
|
||||||
|
|
|
@ -75,6 +75,15 @@ func (nDB *NetworkDB) handleTableEvent(tEvent *TableEvent) bool {
|
||||||
// time.
|
// time.
|
||||||
nDB.tableClock.Witness(tEvent.LTime)
|
nDB.tableClock.Witness(tEvent.LTime)
|
||||||
|
|
||||||
|
// Ignore the table events for networks that are in the process of going away
|
||||||
|
nDB.RLock()
|
||||||
|
networks := nDB.networks[nDB.config.NodeName]
|
||||||
|
network, ok := networks[tEvent.NetworkID]
|
||||||
|
nDB.RUnlock()
|
||||||
|
if !ok || network.leaving {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
if entry, err := nDB.getEntry(tEvent.TableName, tEvent.NetworkID, tEvent.Key); err == nil {
|
if entry, err := nDB.getEntry(tEvent.TableName, tEvent.NetworkID, tEvent.Key); err == nil {
|
||||||
// We have the latest state. Ignore the event
|
// We have the latest state. Ignore the event
|
||||||
// since it is stale.
|
// since it is stale.
|
||||||
|
|
|
@ -398,7 +398,8 @@ func (nDB *NetworkDB) JoinNetwork(nid string) error {
|
||||||
// this event across the cluster. This triggers this node leaving the
|
// this event across the cluster. This triggers this node leaving the
|
||||||
// sub-cluster of this network and as a result will no longer
|
// sub-cluster of this network and as a result will no longer
|
||||||
// participate in the network-scoped gossip and bulk sync for this
|
// participate in the network-scoped gossip and bulk sync for this
|
||||||
// network.
|
// network. Also remove all the table entries for this network from
|
||||||
|
// networkdb
|
||||||
func (nDB *NetworkDB) LeaveNetwork(nid string) error {
|
func (nDB *NetworkDB) LeaveNetwork(nid string) error {
|
||||||
ltime := nDB.networkClock.Increment()
|
ltime := nDB.networkClock.Increment()
|
||||||
if err := nDB.sendNetworkEvent(nid, NetworkEventTypeLeave, ltime); err != nil {
|
if err := nDB.sendNetworkEvent(nid, NetworkEventTypeLeave, ltime); err != nil {
|
||||||
|
@ -407,6 +408,36 @@ func (nDB *NetworkDB) LeaveNetwork(nid string) error {
|
||||||
|
|
||||||
nDB.Lock()
|
nDB.Lock()
|
||||||
defer nDB.Unlock()
|
defer nDB.Unlock()
|
||||||
|
var (
|
||||||
|
paths []string
|
||||||
|
entries []*entry
|
||||||
|
)
|
||||||
|
|
||||||
|
nwWalker := func(path string, v interface{}) bool {
|
||||||
|
entry, ok := v.(*entry)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
paths = append(paths, path)
|
||||||
|
entries = append(entries, entry)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
nDB.indexes[byNetwork].WalkPrefix(fmt.Sprintf("/%s", nid), nwWalker)
|
||||||
|
for _, path := range paths {
|
||||||
|
params := strings.Split(path[1:], "/")
|
||||||
|
tname := params[1]
|
||||||
|
key := params[2]
|
||||||
|
|
||||||
|
if _, ok := nDB.indexes[byTable].Delete(fmt.Sprintf("/%s/%s/%s", tname, nid, key)); !ok {
|
||||||
|
logrus.Errorf("Could not delete entry in table %s with network id %s and key %s as it does not exist", tname, nid, key)
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, ok := nDB.indexes[byNetwork].Delete(fmt.Sprintf("/%s/%s/%s", nid, tname, key)); !ok {
|
||||||
|
logrus.Errorf("Could not delete entry in network %s with table name %s and key %s as it does not exist", nid, tname, key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nodeNetworks, ok := nDB.networks[nDB.config.NodeName]
|
nodeNetworks, ok := nDB.networks[nDB.config.NodeName]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("could not find self node for network %s while trying to leave", nid)
|
return fmt.Errorf("could not find self node for network %s while trying to leave", nid)
|
||||||
|
|
Loading…
Add table
Reference in a new issue