Improve client change counter management in HTTP Server View (#13010)

* Avoid calling resolveWaitingFutures if there are no changes made

* Avoid telling HTTP serveview client to reset counter when their counter is valid
This commit is contained in:
Lucas Capistrant 2023-02-20 06:02:27 -06:00 committed by GitHub
parent e788f1ae6b
commit 46eafa57e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View File

@ -94,6 +94,11 @@ public class ChangeRequestHistory<T>
if (singleThreadedExecutor.isShutdown()) {
return;
}
// We don't want to resolve our futures if there aren't actually any change requests being added!
if (requests.isEmpty()) {
return;
}
for (T request : requests) {
changes.add(new Holder<>(request, getLastCounter().inc()));
}
@ -162,10 +167,20 @@ public class ChangeRequestHistory<T>
{
Counter lastCounter = getLastCounter();
if (counter.counter >= lastCounter.counter) {
if (counter.counter == lastCounter.counter) {
// We don't want to trigger a counter reset if the client counter matches the last counter! Return an empty list
// of changes instead.
if (counter.matches(lastCounter)) {
return ChangeRequestsSnapshot.success(counter, new ArrayList<>());
} else {
return ChangeRequestsSnapshot.fail(
StringUtils.format("counter[%s] failed to match with [%s]", counter, lastCounter)
);
}
} else if (counter.counter > lastCounter.counter) {
return ChangeRequestsSnapshot.fail(
StringUtils.format(
"counter[%s] >= last counter[%s]",
"counter[%s] > last counter[%s]",
counter,
lastCounter
)

View File

@ -19,6 +19,7 @@
package org.apache.druid.server.coordination;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
@ -166,6 +167,11 @@ public class ChangeRequestHistoryTest
Assert.assertFalse(future.isDone());
// An empty list of changes should not trigger the future to return!
history.addChangeRequests(ImmutableList.of());
Assert.assertFalse(future.isDone());
history.addChangeRequest(new SegmentChangeRequestNoop());
ChangeRequestsSnapshot snapshot = future.get(1, TimeUnit.MINUTES);