1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

2x faster to converge

- Introduced back the Invalidate
- optimized the rebroadcast logic

Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
Flavio Crisciani 2017-07-11 13:18:58 -07:00
parent c20c075e20
commit e77c245e45
2 changed files with 10 additions and 9 deletions

View file

@ -114,7 +114,8 @@ type tableEventMessage struct {
} }
func (m *tableEventMessage) Invalidates(other memberlist.Broadcast) bool { func (m *tableEventMessage) Invalidates(other memberlist.Broadcast) bool {
return false otherm := other.(*tableEventMessage)
return m.tname == otherm.tname && m.id == otherm.id && m.key == otherm.key
} }
func (m *tableEventMessage) Message() []byte { func (m *tableEventMessage) Message() []byte {

View file

@ -216,15 +216,11 @@ func (nDB *NetworkDB) handleTableEvent(tEvent *TableEvent) bool {
network, ok := networks[tEvent.NetworkID] network, ok := networks[tEvent.NetworkID]
nDB.RUnlock() nDB.RUnlock()
if !ok || network.leaving { if !ok || network.leaving {
return true // I'm out of the network so do not propagate
}
e, err := nDB.getEntry(tEvent.TableName, tEvent.NetworkID, tEvent.Key)
if err != nil && tEvent.Type == TableEventTypeDelete {
// If it is a delete event and we don't have the entry here nothing to do.
return false return false
} }
e, err := nDB.getEntry(tEvent.TableName, tEvent.NetworkID, tEvent.Key)
if err == nil { if 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.
@ -249,6 +245,11 @@ func (nDB *NetworkDB) handleTableEvent(tEvent *TableEvent) bool {
nDB.indexes[byNetwork].Insert(fmt.Sprintf("/%s/%s/%s", tEvent.NetworkID, tEvent.TableName, tEvent.Key), e) nDB.indexes[byNetwork].Insert(fmt.Sprintf("/%s/%s/%s", tEvent.NetworkID, tEvent.TableName, tEvent.Key), e)
nDB.Unlock() nDB.Unlock()
if err != nil && tEvent.Type == TableEventTypeDelete {
// If it is a delete event and we didn't have the entry here don't repropagate
return true
}
var op opType var op opType
switch tEvent.Type { switch tEvent.Type {
case TableEventTypeCreate: case TableEventTypeCreate:
@ -289,8 +290,7 @@ func (nDB *NetworkDB) handleTableMessage(buf []byte, isBulkSync bool) {
return return
} }
// Do not rebroadcast a bulk sync if rebroadcast := nDB.handleTableEvent(&tEvent); rebroadcast {
if rebroadcast := nDB.handleTableEvent(&tEvent); rebroadcast && !isBulkSync {
var err error var err error
buf, err = encodeRawMessage(MessageTypeTableEvent, buf) buf, err = encodeRawMessage(MessageTypeTableEvent, buf)
if err != nil { if err != nil {