@@ -224,6 +224,10 @@ func (p *Service) processRaftStateCommand(stopCh chan struct{}) {
224224 // until the state is consistent.
225225 logApplyConcurrency <- struct {}{}
226226 go func () {
227+ // We lock dissemination to ensure the updates can complete before the table is disseminated.
228+ p .disseminateLock .Lock ()
229+ defer p .disseminateLock .Unlock ()
230+
227231 updated , raftErr := p .raftNode .ApplyCommand (op .cmdType , op .host )
228232 if raftErr != nil {
229233 log .Errorf ("fail to apply command: %v" , raftErr )
@@ -247,40 +251,44 @@ func (p *Service) processRaftStateCommand(stopCh chan struct{}) {
247251 case raft .TableDisseminate :
248252 // TableDisseminate will be triggered by disseminateTimer.
249253 // This disseminates the latest consistent hashing tables to Dapr runtime.
250- nStreamConnPool := len (p .streamConnPool )
251- nTargetConns := len (p .raftNode .FSM ().State ().Members )
252-
253- monitoring .RecordRuntimesCount (nStreamConnPool )
254- monitoring .RecordActorRuntimesCount (nTargetConns )
255-
256- // ignore dissemination if there is no member update.
257- if cnt := p .memberUpdateCount .Load (); cnt > 0 {
258- state := p .raftNode .FSM ().PlacementState ()
259- log .Infof (
260- "Start disseminating tables. memberUpdateCount: %d, streams: %d, targets: %d, table generation: %s" ,
261- cnt , nStreamConnPool , nTargetConns , state .Version )
262- p .performTablesUpdate (p .streamConnPool , state )
263- log .Infof (
264- "Completed dissemination. memberUpdateCount: %d, streams: %d, targets: %d, table generation: %s" ,
265- cnt , nStreamConnPool , nTargetConns , state .Version )
266- p .memberUpdateCount .Store (0 )
267-
268- // set faultyHostDetectDuration to the default duration.
269- p .faultyHostDetectDuration = faultyHostDetectDefaultDuration
270- }
254+ p .performTableDissemination ()
271255 }
272256 }
273257 }
274258}
275259
260+ func (p * Service ) performTableDissemination () {
261+ nStreamConnPool := len (p .streamConnPool )
262+ nTargetConns := len (p .raftNode .FSM ().State ().Members )
263+
264+ monitoring .RecordRuntimesCount (nStreamConnPool )
265+ monitoring .RecordActorRuntimesCount (nTargetConns )
266+
267+ // ignore dissemination if there is no member update.
268+ if cnt := p .memberUpdateCount .Load (); cnt > 0 {
269+ p .disseminateLock .Lock ()
270+ defer p .disseminateLock .Unlock ()
271+
272+ state := p .raftNode .FSM ().PlacementState ()
273+ log .Infof (
274+ "Start disseminating tables. memberUpdateCount: %d, streams: %d, targets: %d, table generation: %s" ,
275+ cnt , nStreamConnPool , nTargetConns , state .Version )
276+ p .performTablesUpdate (p .streamConnPool , state )
277+ log .Infof (
278+ "Completed dissemination. memberUpdateCount: %d, streams: %d, targets: %d, table generation: %s" ,
279+ cnt , nStreamConnPool , nTargetConns , state .Version )
280+ p .memberUpdateCount .Store (0 )
281+
282+ // set faultyHostDetectDuration to the default duration.
283+ p .faultyHostDetectDuration = faultyHostDetectDefaultDuration
284+ }
285+ }
286+
276287// performTablesUpdate updates the connected dapr runtimes using a 3 stage commit.
277288// It first locks so no further dapr can be taken it. Once placement table is locked
278289// in runtime, it proceeds to update new table to Dapr runtimes and then unlock
279290// once all runtimes have been updated.
280291func (p * Service ) performTablesUpdate (hosts []placementGRPCStream , newTable * v1pb.PlacementTables ) {
281- p .disseminateLock .Lock ()
282- defer p .disseminateLock .Unlock ()
283-
284292 // TODO: error from disseminationOperation needs to be handle properly.
285293 // Otherwise, each Dapr runtime will have inconsistent hashing table.
286294 p .disseminateOperation (hosts , "lock" , nil )
0 commit comments