Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -727,8 +727,10 @@ protected void startLeaderElectionService() {
resourceQuotaUpdateInterval, TimeUnit.MILLISECONDS);
}
} else {
LOG.info("This broker is a follower. Current leader is {}",
leaderElectionService.getCurrentLeader());
if (leaderElectionService != null) {
LOG.info("This broker is a follower. Current leader is {}",
leaderElectionService.getCurrentLeader());
}
if (loadSheddingTask != null) {
loadSheddingTask.cancel(false);
loadSheddingTask = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ public interface MetadataCache<T> {
* if the object is not present in the metadata store.
*/
CompletableFuture<Void> delete(String path);

/**
* Force the invalidation of an object in the metadata cache.
*
* @param path the path of the object in the metadata store
*/
void invalidate(String path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ public CompletableFuture<List<String>> getChildren(String path) {
return store.getChildren(path);
}

@Override
public void invalidate(String path) {
objCache.synchronous().invalidate(path);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ private synchronized CompletableFuture<LeaderElectionState> tryToBecomeLeader()
if (ex.getCause() instanceof BadVersionException) {
// There was a conflict between 2 participants trying to become leaders at same time. Retry
// to fetch info on new leader.

// We force the invalidation of the cache entry. Since we received a BadVersion error, we
// already know that the entry is out of date. If we don't invalidate, we'd be retrying the
// leader election many times until we finally receive the notification that invalidates the
// cache.
cache.invalidate(path);
elect()
.thenAccept(lse -> result.complete(lse))
.exceptionally(ex2 -> {
Expand Down Expand Up @@ -259,10 +265,12 @@ public void accept(Notification notification) {
log.warn("Exception in state change listener", t);
}

executor.schedule(() -> {
log.info("Retrying Leader election for path {}");
elect();
}, LEADER_ELECTION_RETRY_DELAY_SECONDS, TimeUnit.SECONDS);
if (internalState != InternalState.Closed) {
executor.schedule(() -> {
log.info("Retrying Leader election for path {}");
elect();
}, LEADER_ELECTION_RETRY_DELAY_SECONDS, TimeUnit.SECONDS);
}
}
return null;
});
Expand Down