From 3e4b971fadf2e7e362d94a480cb86eb9b075ae68 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 d1a099fc406bc..e30b3db4da84f 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() == false) { + 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);