Skip to content

Commit 4844f06

Browse files
authored
[9.0] ESQL: Fix Driver creating status with a live list of operators (#132260) (#132341)
Manual 9.0 backport of #132260
1 parent 89f95c3 commit 4844f06

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

docs/changelog/132260.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 132260
2+
summary: FIx Driver creating status with a live list of operators
3+
area: ES|QL
4+
type: bug
5+
issues:
6+
- 131564

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/operator/Driver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ private void updateStatus(long extraCpuNanos, int extraIterations, DriverStatus.
531531
prev.cpuNanos() + extraCpuNanos,
532532
prev.iterations() + extraIterations,
533533
status,
534-
statusOfCompletedOperators,
534+
List.copyOf(statusOfCompletedOperators),
535535
activeOperators.stream().map(op -> new DriverStatus.OperatorStatus(op.toString(), op.status())).toList(),
536536
sleeps
537537
);

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/operator/DriverTests.java

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050

5151
import static org.hamcrest.Matchers.either;
5252
import static org.hamcrest.Matchers.equalTo;
53+
import static org.hamcrest.Matchers.not;
54+
import static org.hamcrest.Matchers.sameInstance;
5355

5456
public class DriverTests extends ESTestCase {
5557
/**
@@ -253,6 +255,59 @@ public void testProfileAndStatusInterval() {
253255
assertThat(driver.profile().iterations(), equalTo((long) inPages.size()));
254256
}
255257

258+
public void testUnchangedStatus() {
259+
DriverContext driverContext = driverContext();
260+
List<Page> inPages = randomList(2, 100, DriverTests::randomPage);
261+
List<Page> outPages = new ArrayList<>();
262+
263+
long startEpoch = randomNonNegativeLong();
264+
long startNanos = randomLong();
265+
long waitTime = randomLongBetween(10000, 100000);
266+
long tickTime = randomLongBetween(10000, 100000);
267+
long statusInterval = randomLongBetween(1, 10);
268+
269+
Driver driver = new Driver(
270+
"unset",
271+
"test",
272+
startEpoch,
273+
startNanos,
274+
driverContext,
275+
() -> "unset",
276+
new CannedSourceOperator(inPages.iterator()),
277+
List.of(),
278+
new TestResultPageSinkOperator(outPages::add),
279+
TimeValue.timeValueNanos(statusInterval),
280+
() -> {}
281+
);
282+
283+
NowSupplier nowSupplier = new NowSupplier(startNanos, waitTime, tickTime);
284+
285+
int iterationsPerTick = randomIntBetween(1, 10);
286+
287+
for (int i = 0; i < inPages.size(); i += iterationsPerTick) {
288+
DriverStatus initialStatus = driver.status();
289+
long completedOperatorsHash = initialStatus.completedOperators().hashCode();
290+
long activeOperatorsHash = initialStatus.activeOperators().hashCode();
291+
long sleepsHash = initialStatus.sleeps().hashCode();
292+
293+
driver.run(TimeValue.timeValueDays(10), iterationsPerTick, nowSupplier);
294+
295+
DriverStatus newStatus = driver.status();
296+
assertThat(newStatus, not(sameInstance(initialStatus)));
297+
assertThat(
298+
newStatus.completedOperators() != initialStatus.completedOperators()
299+
|| newStatus.completedOperators().hashCode() == completedOperatorsHash,
300+
equalTo(true)
301+
);
302+
assertThat(
303+
newStatus.activeOperators() != initialStatus.activeOperators()
304+
|| newStatus.activeOperators().hashCode() == activeOperatorsHash,
305+
equalTo(true)
306+
);
307+
assertThat(newStatus.sleeps() != initialStatus.sleeps() || newStatus.sleeps().hashCode() == sleepsHash, equalTo(true));
308+
}
309+
}
310+
256311
class NowSupplier implements LongSupplier {
257312
private final long startNanos;
258313
private final long waitTime;

0 commit comments

Comments
 (0)