mirror of https://github.com/apache/druid.git
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:
parent
e788f1ae6b
commit
46eafa57e1
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue