fix(opensearch): use direct HEAD check in indexExists(), guard null cih in clearIndex()#35397
fix(opensearch): use direct HEAD check in indexExists(), guard null cih in clearIndex()#35397fabrizzio-dotCMS wants to merge 5 commits intomainfrom
Conversation
…ih in clearIndex() (#35303) ESIndexAPI.indexExists() relied on pattern-based listIndices() which can silently return an empty set when DOTCMS_CLUSTER_ID is configured and there is any cluster-ID mismatch or transient ES error, causing clearIndex() to always throw 400 "Index does not exist". Replace with a single direct indices().exists() HEAD request that resolves both logical and physical names via getNameWithClusterIDPrefix(). Also normalize the index name to its logical form before the getClusterHealth() map lookup in clearIndex() to prevent NPE when a physical name is passed. Refs: #35303 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous fix used RestHighLevelClientProvider.getInstance().getClient() .indices().exists() — a vendor-specific ES call that shouldn't be added during the ES→OS migration. Root cause of the original failure: ClusterFactory.getClusterId() prioritises the dot_cluster DB row. When the DB cluster_id diverges from DOT_DOTCMS_CLUSTER_ID (e.g. stale DB row or env var introduced after first startup), IndexType.getPattern() constructs a wildcard that matches no ES indices. The exception inside getIndices() is caught and swallowed, so listIndices() silently returns an empty set and indexExists() always returns false. Fix: query the DB-backed indicies table first (via APILocator.getIndiciesAPI().loadIndicies()). The stored physical names carry the cluster prefix that was real at activation time, so the comparison is immune to any DB/env-var cluster-ID mismatch. Fall back to the existing listIndices() ES scan for indices not yet tracked in the DB (bootstrap, direct createIndex calls, integration tests). Keeps the clearIndex() guards from the previous commit: - normalise to logical name before getClusterHealth() lookup - null-guard on cih with a clear DotStateException Refs: #35303 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Claude finished @fabrizzio-dotCMS's task in 2m 48s —— View job PR Review
The root-cause analysis and overall approach are sound. Four issues worth addressing: 1. Double // current — hits ES twice
return listIndices().contains(stripped) || listIndices().contains(indexName.toLowerCase());
final Set<String> all = listIndices();
return all.contains(stripped) || all.contains(indexName.toLowerCase());2. Phase 2 second condition is dead code (
3. Missing final String logicalName = removeClusterIdFromName(indexName); // no toLowerCase()
final ClusterIndexHealth cih = getClusterHealth().get(logicalName);
final String logicalName = removeClusterIdFromName(indexName.toLowerCase());4. Test covers Phase 2 (ES scan) only, not the Phase 1 (DB) path (
Minor — pre-existing issue, not introduced here ( |
…ionale and two-phase lookup Refs: #35303 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
listIndices()-basedindexExists()with a DB-first check viaIndiciesAPI.loadIndicies()— vendor-neutral, no ES/OS client dependencygetClusterHealth()lookup inclearIndex()to prevent NPE when a physical name is passedcihwith a clearDotStateExceptionmessageclusterIndexNametwice instead of covering both logical and physical name variantsRoot cause
ESIndexAPI.indexExists()usedlistIndices()which builds an ES wildcard query fromIndexType.getPattern(). That pattern embedsClusterFactory.getClusterId(), which reads from thedot_clusterDB table first. When the DB cluster ID diverges fromDOT_DOTCMS_CLUSTER_ID(e.g. stale DB row, or the env var was added after first startup), the pattern matches no indices.getIndices()catches the empty result and swallows it, solistIndices()silently returns an empty set →indexExists()always returnsfalse→clearIndex()throws HTTP 400 before the operation executes.Fix
Query the
indiciesDB table first viaAPILocator.getIndiciesAPI().loadIndicies(). The stored physical names carry the cluster prefix that was real at activation time — immune to any DB/env-var cluster-ID mismatch. Falls back to the existinglistIndices()ES scan for indices not yet tracked in the DB (bootstrap, directcreateIndexcalls, integration tests).Test plan
./mvnw install -pl :dotcms-core -DskipTestsESIndexAPITest#index_exists_should_resolve_even_with_cluster_idPUT /api/v1/esindex/{indexName}?action=clearwithDOT_DOTCMS_CLUSTER_IDset → expect HTTP 200 and index recreatedCloses #35303
🤖 Generated with Claude Code