@@ -3778,14 +3778,44 @@ void ClusterQueueHelper::restoreStateCluster(int partitionId)
37783778 const ClusterStatePartitionInfo* pinfo = 0 ;
37793779
37803780 if (!allPartitions) {
3781- pinfo = activeAvailablePrimaryPartition (&isSelfPrimaryAndLeader,
3782- partitionId);
3783-
3784- if (!pinfo) {
3781+ pinfo = &(d_clusterState_p->partition (partitionId));
3782+ BSLS_ASSERT_SAFE (pinfo);
3783+ if (!hasActiveAvailablePrimary (partitionId)) {
3784+ BALL_LOG_INFO << d_cluster_p->description () << " Partition ["
3785+ << partitionId
3786+ << " ]: Not restoring partition state because there "
3787+ << " is no primary or primary isn't ACTIVE. Current "
3788+ << " primary: "
3789+ << (pinfo->primaryNode ()
3790+ ? pinfo->primaryNode ()->nodeDescription ()
3791+ : " ** null **" )
3792+ << " , primary status: " << pinfo->primaryStatus ();
37853793 return ; // RETURN
37863794 }
3795+
3796+ // Primary for this partitionId is ACTIVE. Check if self is the
3797+ // primary and leader. If self is primary but not leader, this is
3798+ // primary-leader divergence and we should not proceed with state
3799+ // restore.
3800+
3801+ isSelfPrimaryAndLeader =
3802+ pinfo->primaryNode () == d_clusterData_p->membership ().selfNode () &&
3803+ d_clusterData_p->electorInfo ().isSelfLeader ();
37873804 }
37883805
3806+ // / TODO (FSM); remove after switching to FSM
3807+ if (!d_cluster_p->isFSMWorkflow () && isSelfPrimaryAndLeader) {
3808+ // Note that this fails if there are data
3809+ mqbc::ClusterState::AssignmentVisitor doubleAssignmentVisitor =
3810+ bdlf::BindUtil::bindS (d_allocator_p,
3811+ &mqbi::StorageManager::unregisterQueue,
3812+ d_storageManager_p,
3813+ bdlf::PlaceHolders::_1, // uri
3814+ bdlf::PlaceHolders::_2); // partitionId),
3815+
3816+ d_clusterState_p->iterateDoubleAssignments (partitionId,
3817+ doubleAssignmentVisitor);
3818+ }
37893819 ConditionalAdvance<QueueContextMapConstIter> conditional;
37903820 for (QueueContextMapConstIter cit = d_queues.cbegin ();
37913821 cit != d_queues.cend ();
@@ -3822,13 +3852,26 @@ void ClusterQueueHelper::restoreStateCluster(int partitionId)
38223852 }
38233853
38243854 // Proceed as if a specific partitionId is specified.
3825-
3826- pinfo = activeAvailablePrimaryPartition (
3827- &isSelfPrimaryAndLeader,
3828- queueContext->partitionId ());
3829- if (!pinfo) {
3830- continue ;
3855+ partitionId = queueContext->partitionId ();
3856+ pinfo = &(d_clusterState_p->partition (partitionId));
3857+
3858+ if (!hasActiveAvailablePrimary (partitionId)) {
3859+ BMQ_LOGTHROTTLE_INFO
3860+ << d_cluster_p->description ()
3861+ << " Not performing restore of queue ["
3862+ << queueContext->uri ()
3863+ << " ] because there is no primary or primary isn't "
3864+ " ACTIVE. Current primary: "
3865+ << (pinfo->primaryNode ()
3866+ ? pinfo->primaryNode ()->nodeDescription ()
3867+ : " ** null **" )
3868+ << " , primary status: " << pinfo->primaryStatus ();
3869+ continue ; // CONTINUE
38313870 }
3871+ isSelfPrimaryAndLeader =
3872+ pinfo->primaryNode () ==
3873+ d_clusterData_p->membership ().selfNode () &&
3874+ d_clusterData_p->electorInfo ().isSelfLeader ();
38323875 }
38333876 else if (queueContext->partitionId () != partitionId) {
38343877 // Skip the queue as its assigned to a different partitionId.
@@ -6240,54 +6283,5 @@ void ClusterQueueHelper::match(bsl::vector<bsl::string>* added,
62406283 }
62416284}
62426285
6243- const mqbc::ClusterStatePartitionInfo*
6244- ClusterQueueHelper::activeAvailablePrimaryPartition (
6245- bool * isSelfPrimaryAndLeader,
6246- int partitionId)
6247- {
6248- BSLS_ASSERT_SAFE (isSelfPrimaryAndLeader);
6249-
6250- const ClusterStatePartitionInfo* pinfo = &(
6251- d_clusterState_p->partition (partitionId));
6252- BSLS_ASSERT_SAFE (pinfo);
6253- if (!hasActiveAvailablePrimary (partitionId)) {
6254- BALL_LOG_INFO << d_cluster_p->description () << " Partition ["
6255- << partitionId
6256- << " ]: Not restoring partition state because there "
6257- << " is no primary or primary isn't ACTIVE. Current "
6258- << " primary: "
6259- << (pinfo->primaryNode ()
6260- ? pinfo->primaryNode ()->nodeDescription ()
6261- : " ** null **" )
6262- << " , primary status: " << pinfo->primaryStatus ();
6263- return 0 ; // RETURN
6264- }
6265-
6266- // Primary for this partitionId is ACTIVE. Check if self is the
6267- // primary and leader. If self is primary but not leader, this is
6268- // primary-leader divergence and we should not proceed with state
6269- // restore.
6270-
6271- *isSelfPrimaryAndLeader = pinfo->primaryNode () ==
6272- d_clusterData_p->membership ().selfNode () &&
6273- d_clusterData_p->electorInfo ().isSelfLeader ();
6274-
6275- // / TODO (FSM); remove after switching to FSM
6276- if (!d_cluster_p->isFSMWorkflow () && *isSelfPrimaryAndLeader) {
6277- // Note that this fails if there are data
6278- mqbc::ClusterState::AssignmentVisitor doubleAssignmentVisitor =
6279- bdlf::BindUtil::bindS (d_allocator_p,
6280- &mqbi::StorageManager::unregisterQueue,
6281- d_storageManager_p,
6282- bdlf::PlaceHolders::_1, // uri
6283- bdlf::PlaceHolders::_2); // partitionId),
6284-
6285- d_clusterState_p->iterateDoubleAssignments (partitionId,
6286- doubleAssignmentVisitor);
6287- }
6288-
6289- return pinfo;
6290- }
6291-
62926286} // close package namespace
62936287} // close enterprise namespace
0 commit comments