+
+ @Override
+ public CompletionStage<ShardBackendInfo> getBackendInfo(final Long cookie) {
+ /*
+ * We cannot perform a simple computeIfAbsent() here because we need to control sequencing of when the state
+ * is inserted into the map and retired from it (based on the stage result).
+ *
+ * We do not want to hook another stage one processing completes and hooking a removal on failure from a compute
+ * method runs the inherent risk of stage completing before the insertion does (i.e. we have a removal of
+ * non-existent element.
+ */
+ final ShardState existing = backends.get(cookie);
+ if (existing != null) {
+ return existing.getStage();
+ }
+