From f0c8baaddef53cddd054c08f52bc9ba4b2b11b01 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Thu, 1 Feb 2024 09:43:09 -0800 Subject: [PATCH] Harden assertions when checking target indices (#105001) We should have checked and failed if there is an inconsistent pair of data node plan and target indices. This PR strengthens these checks and adds assertions to fail hard in tests. Relates #10480 --- .../xpack/esql/plugin/ComputeService.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/ComputeService.java b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/ComputeService.java index d1a099fc406bc6..6be228a7c1077a 100644 --- a/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/ComputeService.java +++ b/x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/ComputeService.java @@ -149,8 +149,13 @@ public void execute( var concreteIndices = PlannerUtils.planConcreteIndices(physicalPlan); QueryPragmas queryPragmas = configuration.pragmas(); - - if (concreteIndices.isEmpty()) { + if (dataNodePlan == null) { + if (concreteIndices.isEmpty()) { + String error = "expected no concrete indices without data node plan; got " + concreteIndices; + assert false : error; + listener.onFailure(new IllegalStateException(error)); + return; + } var computeContext = new ComputeContext(sessionId, List.of(), configuration, null, null); runCompute( rootTask, @@ -160,6 +165,12 @@ public void execute( ); return; } + if (concreteIndices.isEmpty()) { + var error = "expected concrete indices with data node plan but got empty; data node plan " + dataNodePlan; + assert false : error; + listener.onFailure(new IllegalStateException(error)); + return; + } QueryBuilder requestFilter = PlannerUtils.requestFilter(dataNodePlan); LOGGER.debug("Sending data node plan\n{}\n with filter [{}]", dataNodePlan, requestFilter);