@@ -89,8 +89,7 @@ namespace BloombergLP {
8989namespace mqbblp {
9090
9191namespace {
92- const char k_MAXIMUM_NUMBER_OF_QUEUES_REACHED[] =
93- " maximum number of queues reached" ;
92+
9493const char k_SELF_NODE_IS_STOPPING[] = " self node is stopping" ;
9594
9695const int k_MAX_INSTANT_MESSAGES = 10 ;
@@ -393,8 +392,7 @@ void ClusterQueueHelper::afterPartitionPrimaryAssignment(
393392 }
394393}
395394
396- mqbi::ClusterStateManager::QueueAssignmentResult::Enum
397- ClusterQueueHelper::assignQueue (const QueueContextSp& queueContext)
395+ void ClusterQueueHelper::assignQueue (const QueueContextSp& queueContext)
398396{
399397 // executed by the cluster *DISPATCHER* thread
400398
@@ -407,30 +405,31 @@ ClusterQueueHelper::assignQueue(const QueueContextSp& queueContext)
407405 // Assigning a queue in a remote, is simply giving it a new queueId.
408406 queueContext->d_liveQInfo .d_id = getNextQueueId ();
409407 onQueueContextAssigned (queueContext);
410- return QueueAssignmentResult::k_ASSIGNMENT_OK; // RETURN
411408 }
412-
413- if (d_clusterData_p->electorInfo ().hasActiveLeader ()) {
409+ else if (d_clusterData_p->electorInfo ().hasActiveLeader ()) {
414410 if (d_clusterData_p->electorInfo ().isSelfLeader ()) {
415- return d_clusterStateManager_p->assignQueue (queueContext->uri ());
416- // RETURN
411+ bmqp_ctrlmsg::Status status (d_allocator_p);
412+
413+ if (!d_clusterStateManager_p->assignQueue (queueContext->uri (),
414+ &status)) {
415+ processRejectedQueueAssignment (queueContext.get (), status);
416+ }
417+ // else, all other failure are transient. will retry.
417418 }
418419 else {
419420 requestQueueAssignment (queueContext->uri ());
420- return QueueAssignmentResult::k_ASSIGNMENT_OK; // RETURN
421421 }
422422 }
423+ else {
424+ // Queue not yet assigned, because we don't have a leader (or leader is
425+ // not active) at the moment, nothing to be done; the queue will
426+ // automatically be re-processed once we have an active leader.
423427
424- // Queue not yet assigned, because we don't have a leader (or leader is not
425- // active) at the moment, nothing to be done; the queue will automatically
426- // be re-processed once we have an active leader.
427-
428- BALL_LOG_INFO << d_cluster_p->description ()
429- << " Cannot proceed with queueAssignment of "
430- << " '" << queueContext->uri ()
431- << " ' (waiting for an ACTIVE leader)." ;
432-
433- return QueueAssignmentResult::k_ASSIGNMENT_OK;
428+ BALL_LOG_INFO << d_cluster_p->description ()
429+ << " Cannot proceed with queueAssignment of '"
430+ << queueContext->uri ()
431+ << " ' (waiting for an ACTIVE leader)." ;
432+ }
434433}
435434
436435void ClusterQueueHelper::requestQueueAssignment (const bmqt::Uri& uri)
@@ -564,6 +563,7 @@ void ClusterQueueHelper::onQueueAssignmentResponse(
564563 // exists and the queue is assigned, because the
565564 // 'queueAssignmentAdvisory' message may have been dropped due to
566565 // change of leader.
566+
567567 BALL_LOG_INFO << d_cluster_p->description ()
568568 << " Received queueAssignment response from '"
569569 << responder->nodeDescription ()
@@ -589,24 +589,22 @@ void ClusterQueueHelper::onQueueAssignmentResponse(
589589 // time.
590590 }
591591 else if (requestContext->result () == bmqt::GenericResult::e_REFUSED) {
592- if (requestContext->response ().choice ().status ().code () ==
593- mqbi::ClusterErrorCode::e_NOT_LEADER) {
592+ if (status.code () == mqbi::ClusterErrorCode::e_NOT_LEADER) {
594593 // The leader changed by the time our request reached it; we
595594 // don't have to do anything here: since the leader changed, we
596595 // must have (or will shortly) received a notification about
597596 // the new leader, and in the 'onClusterLeader' one thing we do
598597 // is re-emit an assignmentRequest for any unassigned queue,
599598 // this current one being part of them.
600599 }
601- else if (requestContext->response ().choice ().status ().code () ==
602- mqbi::ClusterErrorCode::e_LIMIT) {
600+ else if (status.code () == mqbi::ClusterErrorCode::e_LIMIT ||
601+ status.code () == mqbi::ClusterErrorCode::e_CSL_FAILURE ||
602+ status.code () == mqbi::ClusterErrorCode::e_UNKNOWN) {
603603 QueueContextMapIter qit = d_queues.find (uri);
604604 BSLS_ASSERT_SAFE (qit != d_queues.end ());
605- bdlma::LocalSequentialAllocator<256 > localAllocator (
606- d_allocator_p);
607- bsl::vector<QueueContext*> rejected (1 , &localAllocator);
608- *rejected.begin () = qit->second .get ();
609- processRejectedQueueAssignments (rejected);
605+ const QueueContext* rejected = qit->second .get ();
606+
607+ processRejectedQueueAssignment (rejected, status);
610608 }
611609 }
612610 else {
@@ -3399,35 +3397,27 @@ void ClusterQueueHelper::restoreState(int partitionId)
33993397 }
34003398}
34013399
3402- void ClusterQueueHelper::processRejectedQueueAssignments (
3403- const bsl::vector<QueueContext*>& rejected)
3400+ void ClusterQueueHelper::processRejectedQueueAssignment (
3401+ const QueueContext* rejected,
3402+ const bmqp_ctrlmsg::Status& status)
34043403{
34053404 // executed by the cluster *DISPATCHER* thread
34063405
34073406 // PRECONDITIONS
34083407 BSLS_ASSERT_SAFE (
34093408 d_cluster_p->dispatcher ()->inDispatcherThread (d_cluster_p));
34103409
3411- bmqp_ctrlmsg::Status failure;
3412- failure.category () = bmqp_ctrlmsg::StatusCategory::E_REFUSED ;
3413- failure.code () = mqbi::ClusterErrorCode::e_LIMIT;
3414- failure.message () = k_MAXIMUM_NUMBER_OF_QUEUES_REACHED;
3415-
3416- for (bsl::vector<QueueContext*>::const_iterator sIt = rejected.begin ();
3417- sIt != rejected.end ();
3418- ++sIt ) {
3419- for (bsl::vector<OpenQueueContextSp>::iterator
3420- cIt = (*sIt )->d_liveQInfo .d_pending .begin (),
3421- cLast = (*sIt )->d_liveQInfo .d_pending .end ();
3422- cIt != cLast;
3423- ++cIt) {
3424- (*cIt)->d_callback (failure,
3425- 0 ,
3426- bmqp_ctrlmsg::OpenQueueResponse (),
3427- mqbi::Cluster::OpenQueueConfirmationCookie ());
3428- }
3429- d_queues.erase ((*sIt )->uri ());
3430- }
3410+ for (bsl::vector<OpenQueueContextSp>::const_iterator
3411+ cIt = rejected->d_liveQInfo .d_pending .begin (),
3412+ cLast = rejected->d_liveQInfo .d_pending .end ();
3413+ cIt != cLast;
3414+ ++cIt) {
3415+ (*cIt)->d_callback (status,
3416+ 0 ,
3417+ bmqp_ctrlmsg::OpenQueueResponse (),
3418+ mqbi::Cluster::OpenQueueConfirmationCookie ());
3419+ }
3420+ d_queues.erase (rejected->uri ());
34313421}
34323422
34333423void ClusterQueueHelper::restoreStateRemote ()
@@ -3450,9 +3440,6 @@ void ClusterQueueHelper::restoreStateRemote()
34503440 }
34513441
34523442 // Attempt to re-issue open-queue requests for all applicable queues.
3453- bdlma::LocalSequentialAllocator<1024 > localAllocator (d_allocator_p);
3454- bsl::vector<QueueContext*> rejected (&localAllocator);
3455- rejected.reserve (d_queues.size ());
34563443
34573444 for (QueueContextMapConstIter cit = d_queues.cbegin ();
34583445 cit != d_queues.cend ();
@@ -3473,10 +3460,9 @@ void ClusterQueueHelper::restoreStateRemote()
34733460
34743461 if (!isQueueAssigned (*queueContext.get ())) {
34753462 // Queue is not assigned to a partition; get it assigned.
3476- if (QueueAssignmentResult::k_ASSIGNMENT_REJECTED ==
3477- assignQueue (queueContext)) {
3478- rejected.push_back (queueContext.get ());
3479- }
3463+
3464+ assignQueue (queueContext);
3465+
34803466 continue ; // CONTINUE
34813467 }
34823468
@@ -3508,8 +3494,6 @@ void ClusterQueueHelper::restoreStateRemote()
35083494
35093495 onQueueContextAssigned (queueContext);
35103496 }
3511-
3512- processRejectedQueueAssignments (rejected);
35133497}
35143498
35153499void ClusterQueueHelper::restoreStateCluster (int partitionId)
@@ -3595,10 +3579,6 @@ void ClusterQueueHelper::restoreStateCluster(int partitionId)
35953579 d_clusterData_p->membership ().selfNode ();
35963580 }
35973581
3598- bdlma::LocalSequentialAllocator<1024 > localAllocator (d_allocator_p);
3599- bsl::vector<QueueContext*> rejected (&localAllocator);
3600- rejected.reserve (d_queues.size ());
3601-
36023582 for (QueueContextMapConstIter cit = d_queues.cbegin ();
36033583 cit != d_queues.cend ();
36043584 ++cit) {
@@ -3626,10 +3606,9 @@ void ClusterQueueHelper::restoreStateCluster(int partitionId)
36263606 // Queue is not assigned to a partition; get it assigned. If
36273607 // self is leader, it will assign it locally, if not it will
36283608 // send a request to the leader, etc.
3629- if (QueueAssignmentResult::k_ASSIGNMENT_REJECTED ==
3630- assignQueue (queueContext)) {
3631- rejected.push_back (queueContext.get ());
3632- }
3609+
3610+ assignQueue (queueContext);
3611+
36333612 continue ; // CONTINUE
36343613 }
36353614 }
@@ -3757,8 +3736,6 @@ void ClusterQueueHelper::restoreStateCluster(int partitionId)
37573736 }
37583737 }
37593738 }
3760-
3761- processRejectedQueueAssignments (rejected);
37623739}
37633740
37643741bmqt::GenericResult::Enum
@@ -4699,14 +4676,7 @@ void ClusterQueueHelper::openQueue(
46994676 queueContext->d_liveQInfo .d_pending .push_back (context);
47004677
47014678 // Initiate the assignment.
4702- if (QueueAssignmentResult::k_ASSIGNMENT_REJECTED ==
4703- assignQueue (queueContext)) {
4704- bdlma::LocalSequentialAllocator<1024 > localAllocator (
4705- d_allocator_p);
4706- bsl::vector<QueueContext*> rejected (&localAllocator);
4707- rejected.push_back (queueContext.get ());
4708- processRejectedQueueAssignments (rejected);
4709- }
4679+ assignQueue (queueContext);
47104680 }
47114681}
47124682
0 commit comments