-
Notifications
You must be signed in to change notification settings - Fork 582
Topology recovery retry fixes for auto-delete queues #692
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,9 @@ | |
import com.rabbitmq.client.AMQP; | ||
import com.rabbitmq.client.ShutdownSignalException; | ||
import com.rabbitmq.utility.Utility; | ||
import java.util.LinkedHashSet; | ||
import java.util.Set; | ||
import java.util.Map.Entry; | ||
import java.util.function.BiPredicate; | ||
import static com.rabbitmq.client.impl.recovery.TopologyRecoveryRetryHandlerBuilder.builder; | ||
|
||
|
@@ -62,7 +65,7 @@ public abstract class TopologyRecoveryRetryLogic { | |
if (context.entity() instanceof RecordedQueue) { | ||
final RecordedQueue recordedQueue = context.queue(); | ||
AutorecoveringConnection connection = context.connection(); | ||
connection.recoverQueue(recordedQueue.getName(), recordedQueue, false); | ||
connection.recoverQueue(recordedQueue.getName(), recordedQueue); | ||
} | ||
return null; | ||
}; | ||
|
@@ -76,9 +79,7 @@ public abstract class TopologyRecoveryRetryLogic { | |
AutorecoveringConnection connection = context.connection(); | ||
RecordedQueue recordedQueue = connection.getRecordedQueues().get(binding.getDestination()); | ||
if (recordedQueue != null) { | ||
connection.recoverQueue( | ||
recordedQueue.getName(), recordedQueue, false | ||
); | ||
connection.recoverQueue(recordedQueue.getName(), recordedQueue); | ||
} | ||
} | ||
return null; | ||
|
@@ -122,9 +123,7 @@ public abstract class TopologyRecoveryRetryLogic { | |
AutorecoveringConnection connection = context.connection(); | ||
RecordedQueue recordedQueue = connection.getRecordedQueues().get(consumer.getQueue()); | ||
if (recordedQueue != null) { | ||
connection.recoverQueue( | ||
recordedQueue.getName(), recordedQueue, false | ||
); | ||
connection.recoverQueue(recordedQueue.getName(), recordedQueue); | ||
} | ||
} | ||
return null; | ||
|
@@ -165,14 +164,52 @@ public abstract class TopologyRecoveryRetryLogic { | |
} else if (consumer.getChannel() == channel) { | ||
final RetryContext retryContext = new RetryContext(consumer, context.exception(), context.connection()); | ||
RECOVER_CONSUMER_QUEUE.call(retryContext); | ||
context.connection().recoverConsumer(consumer.getConsumerTag(), consumer, false); | ||
context.connection().recoverConsumer(consumer.getConsumerTag(), consumer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. similar concept here as with the recoverQueue... we want this to throw an exception rather than deliver to the exceptionhandler and swallow the exception |
||
RECOVER_CONSUMER_QUEUE_BINDINGS.call(retryContext); | ||
} | ||
} | ||
return context.consumer().getConsumerTag(); | ||
} | ||
return null; | ||
}; | ||
|
||
/** | ||
* Recover earlier auto-delete or exclusive queues that share the same channel as this retry context | ||
*/ | ||
public static final DefaultRetryHandler.RetryOperation<Void> RECOVER_PREVIOUS_AUTO_DELETE_QUEUES = context -> { | ||
if (context.entity() instanceof RecordedQueue) { | ||
AutorecoveringConnection connection = context.connection(); | ||
RecordedQueue queue = context.queue(); | ||
// recover all queues for the same channel that had already been recovered successfully before this queue failed. | ||
// If the previous ones were auto-delete or exclusive, they need recovered again | ||
for (Entry<String, RecordedQueue> entry : Utility.copy(connection.getRecordedQueues()).entrySet()) { | ||
if (entry.getValue() == queue) { | ||
// we have gotten to the queue in this context. Since this is an ordered map we can now break | ||
// as we know we have recovered all the earlier queues on this channel | ||
break; | ||
} else if (queue.getChannel() == entry.getValue().getChannel() | ||
&& (entry.getValue().isAutoDelete() || entry.getValue().isExclusive())) { | ||
connection.recoverQueue(entry.getKey(), entry.getValue()); | ||
} | ||
} | ||
} else if (context.entity() instanceof RecordedQueueBinding) { | ||
AutorecoveringConnection connection = context.connection(); | ||
Set<String> queues = new LinkedHashSet<>(); | ||
for (Entry<String, RecordedQueue> entry : Utility.copy(connection.getRecordedQueues()).entrySet()) { | ||
if (context.entity().getChannel() == entry.getValue().getChannel() | ||
&& (entry.getValue().isAutoDelete() || entry.getValue().isExclusive())) { | ||
connection.recoverQueue(entry.getKey(), entry.getValue()); | ||
queues.add(entry.getValue().getName()); | ||
} | ||
} | ||
for (final RecordedBinding binding : Utility.copy(connection.getRecordedBindings())) { | ||
if (binding instanceof RecordedQueueBinding && queues.contains(binding.getDestination())) { | ||
binding.recover(); | ||
} | ||
} | ||
} | ||
return null; | ||
}; | ||
|
||
/** | ||
* Pre-configured {@link TopologyRecoveryRetryHandlerBuilder} that retries recovery of bindings and consumers | ||
|
@@ -188,11 +225,13 @@ public abstract class TopologyRecoveryRetryLogic { | |
.bindingRecoveryRetryCondition(CHANNEL_CLOSED_NOT_FOUND) | ||
.consumerRecoveryRetryCondition(CHANNEL_CLOSED_NOT_FOUND) | ||
.queueRecoveryRetryOperation(RECOVER_CHANNEL | ||
.andThen(RECOVER_QUEUE)) | ||
.andThen(RECOVER_QUEUE) | ||
.andThen(RECOVER_PREVIOUS_AUTO_DELETE_QUEUES)) | ||
.bindingRecoveryRetryOperation(RECOVER_CHANNEL | ||
.andThen(RECOVER_BINDING_QUEUE) | ||
.andThen(RECOVER_BINDING) | ||
.andThen(RECOVER_PREVIOUS_QUEUE_BINDINGS)) | ||
.andThen(RECOVER_PREVIOUS_QUEUE_BINDINGS) | ||
.andThen(RECOVER_PREVIOUS_AUTO_DELETE_QUEUES)) | ||
.consumerRecoveryRetryOperation(RECOVER_CHANNEL | ||
.andThen(RECOVER_CONSUMER_QUEUE) | ||
.andThen(RECOVER_CONSUMER) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before: if this failed to recover the queue, the error was delivered to the exception handler and swalled from the perspective of this retry logic. So the queue never got recovered.
Now: this recoverQueue method will now throw an exception if an error occurs and the retry logic will catch that and continue to retry as long as the max retry attempts haven't been reached.