Skip to content

Commit

Permalink
[fix][broker] fix broker may lost rack information (apache#23331)
Browse files Browse the repository at this point in the history
Co-authored-by: fanjianye <[email protected]>
(cherry picked from commit a7d9d8f)
  • Loading branch information
TakaHiR07 authored and nikhil-ctds committed Feb 19, 2025
1 parent 945c130 commit aa5643a
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,13 @@ private CompletableFuture<Versioned<Set<BookieId>>> getBookiesThenFreshCache(Str
@Override
public CompletableFuture<Void> watchWritableBookies(RegistrationListener registrationListener) {
writableBookiesWatchers.add(registrationListener);
// trigger all listeners in writableBookiesWatchers one by one. It aims to keep a sync way
// to make sure the previous listener has finished when a new listener is register.
// Though it would bring duplicate trigger listener problem, but since watchWritableBookies
// is only executed when bookieClient construct, the duplicate problem is acceptable.
return getWritableBookies()
.thenAcceptAsync(registrationListener::onBookiesChanged, executor);
.thenAcceptAsync(bookies ->
writableBookiesWatchers.forEach(w -> w.onBookiesChanged(bookies)), executor);
}

@Override
Expand All @@ -193,8 +198,13 @@ public void unwatchWritableBookies(RegistrationListener registrationListener) {
@Override
public CompletableFuture<Void> watchReadOnlyBookies(RegistrationListener registrationListener) {
readOnlyBookiesWatchers.add(registrationListener);
// trigger all listeners in readOnlyBookiesWatchers one by one. It aims to keep a sync way
// to make sure the previous listener has finished when a new listener is register.
// Though it would bring duplicate trigger listener problem, but since watchReadOnlyBookies
// is only executed when bookieClient construct, the duplicate problem is acceptable.
return getReadOnlyBookies()
.thenAcceptAsync(registrationListener::onBookiesChanged, executor);
.thenAcceptAsync(bookies ->
readOnlyBookiesWatchers.forEach(w -> w.onBookiesChanged(bookies)), executor);
}

@Override
Expand Down

0 comments on commit aa5643a

Please sign in to comment.