From aa4d32dfdc7ce6da09d77fcaaaa79307d103a003 Mon Sep 17 00:00:00 2001 From: Hendrik Muhs Date: Wed, 24 Feb 2021 16:02:33 +0100 Subject: [PATCH] when the indexer is shutting down it sets the state _before_ it persists the latest state, during the 2 stages a new run might get triggered and run into a race condition where a new state persists runs while the old has not finished yet. This change prevents the trigger if the indexer is in the described intermediate state fixes #67121 --- .../transform/transforms/TransformIndexer.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformIndexer.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformIndexer.java index 68557ce21c347..79d8a3bb863af 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformIndexer.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/TransformIndexer.java @@ -588,6 +588,22 @@ public synchronized boolean maybeTriggerAsyncJob(long now) { return false; } + /* + * ignore if indexer thread is shutting down (after finishing a checkpoint) + * shutting down means: + * - indexer has finished a checkpoint and called onFinish + * - indexer state has changed from indexing to started + * - state persistence has been called but has _not_ returned yet + * + * If we trigger the indexer in this situation the 2nd indexer thread might + * try to save state at the same time, causing a version conflict + * see gh#67121 + */ + if (indexerThreadShuttingDown) { + logger.debug("[{}] indexer thread is shutting down. Ignoring trigger.", getJobId()); + return false; + } + return super.maybeTriggerAsyncJob(now); }