Skip to content

Commit b486946

Browse files
committed
Add callback support to RotatingStoreVerticle for keyset key fail-fast feature
- Add Consumer<Boolean> refreshCallback field - Add constructor overload to accept callback - Call callback on refresh success/failure - Maintains backward compatibility with existing constructor This enables monitoring of store refresh status for fail-fast behavior.
1 parent 2701812 commit b486946

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

src/main/java/com/uid2/shared/vertx/RotatingStoreVerticle.java

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import java.util.concurrent.atomic.AtomicInteger;
1717
import java.util.concurrent.atomic.AtomicLong;
18+
import java.util.function.Consumer;
1819

1920
public class RotatingStoreVerticle extends AbstractVerticle {
2021
private static final Logger LOGGER = LoggerFactory.getLogger(RotatingStoreVerticle.class);
@@ -31,10 +32,16 @@ public class RotatingStoreVerticle extends AbstractVerticle {
3132
private final AtomicLong latestVersion = new AtomicLong(-1L);
3233
private final AtomicLong latestEntryCount = new AtomicLong(-1L);
3334
private final AtomicInteger storeRefreshIsFailing = new AtomicInteger(0);
35+
private final Consumer<Boolean> refreshCallback;
3436

3537
private final long refreshIntervalMs;
3638

3739
public RotatingStoreVerticle(String storeName, long refreshIntervalMs, IMetadataVersionedStore versionedStore) {
40+
this(storeName, refreshIntervalMs, versionedStore, null);
41+
}
42+
43+
public RotatingStoreVerticle(String storeName, long refreshIntervalMs, IMetadataVersionedStore versionedStore,
44+
Consumer<Boolean> refreshCallback) {
3845
this.healthComponent = HealthManager.instance.registerComponent(storeName + "-rotator");
3946
this.healthComponent.setHealthStatus(false, "not started");
4047

@@ -72,6 +79,7 @@ public RotatingStoreVerticle(String storeName, long refreshIntervalMs, IMetadata
7279
this.versionedStore = versionedStore;
7380
this.refreshIntervalMs = refreshIntervalMs;
7481
this.storeRefreshTimer = Metrics.timer("uid2_store_refresh_duration", "store_name", storeName);
82+
this.refreshCallback = refreshCallback;
7583
}
7684

7785
@Override
@@ -115,15 +123,21 @@ private void startBackgroundRefresh() {
115123
final long end = System.nanoTime();
116124
final long elapsed = ((end - start) / 1000000);
117125
this.counterStoreRefreshTimeMs.increment(elapsed);
118-
if (asyncResult.failed()) {
119-
this.counterStoreRefreshFailures.increment();
120-
this.storeRefreshIsFailing.set(1);
121-
LOGGER.error("Failed to load " + this.storeName + ", " + elapsed + " ms", asyncResult.cause());
122-
} else {
123-
this.counterStoreRefreshed.increment();
124-
this.storeRefreshIsFailing.set(0);
125-
LOGGER.trace("Successfully refreshed " + this.storeName + ", " + elapsed + " ms");
126+
if (asyncResult.failed()) {
127+
this.counterStoreRefreshFailures.increment();
128+
this.storeRefreshIsFailing.set(1);
129+
LOGGER.error("Failed to load " + this.storeName + ", " + elapsed + " ms", asyncResult.cause());
130+
if (this.refreshCallback != null) {
131+
this.refreshCallback.accept(false);
126132
}
133+
} else {
134+
this.counterStoreRefreshed.increment();
135+
this.storeRefreshIsFailing.set(0);
136+
LOGGER.trace("Successfully refreshed " + this.storeName + ", " + elapsed + " ms");
137+
if (this.refreshCallback != null) {
138+
this.refreshCallback.accept(true);
139+
}
140+
}
127141
}
128142
);
129143
});

0 commit comments

Comments
 (0)