Skip to content

Commit

Permalink
delete query index only if put mappings throws an exception (#1685) (#…
Browse files Browse the repository at this point in the history
…1690)

(cherry picked from commit 6239d7b)

Signed-off-by: Subhobrata Dey <sbcd90@gmail.com>
  • Loading branch information
opensearch-trigger-bot[bot] authored Oct 3, 2024
1 parent a47d3c0 commit 94cace8
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ class DocumentLevelMonitorRunner : MonitorRunner() {
throw IndexNotFoundException(docLevelMonitorInput.indices.joinToString(","))
}

if (monitor.deleteQueryIndexInEveryRun == true &&
monitorCtx.docLevelMonitorQueries!!.docLevelQueryIndexExists(monitor.dataSources)
) {
val ack = monitorCtx.docLevelMonitorQueries!!.deleteDocLevelQueryIndex(monitor.dataSources)
if (!ack) {
logger.error(
"Deletion of concrete queryIndex:${monitor.dataSources.queryIndex} is not ack'd! " +
"for monitor ${monitor.id}"
)
}
}
monitorCtx.docLevelMonitorQueries!!.initDocLevelQueryIndex(monitor.dataSources)
monitorCtx.docLevelMonitorQueries!!.indexDocLevelQueries(
monitor = monitor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,8 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
monitorMetadata,
updatedIndexName,
sourceIndexFieldLimit,
updatedProperties
updatedProperties,
indexTimeout
)

if (updateMappingResponse.isAcknowledged) {
Expand Down Expand Up @@ -488,7 +489,8 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
monitorMetadata: MonitorMetadata,
sourceIndex: String,
sourceIndexFieldLimit: Long,
updatedProperties: MutableMap<String, Any>
updatedProperties: MutableMap<String, Any>,
indexTimeout: TimeValue
): Pair<AcknowledgedResponse, String> {
var targetQueryIndex = monitorMetadata.sourceToQueryIndexMapping[sourceIndex + monitor.id]
if (
Expand Down Expand Up @@ -552,9 +554,48 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
}
}
} else {
log.debug("unknown exception during PUT mapping on queryIndex: $targetQueryIndex")
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
throw AlertingException.wrap(unwrappedException)
// retry with deleting query index
if (monitor.deleteQueryIndexInEveryRun == true) {
try {
log.error(
"unknown exception during PUT mapping on queryIndex: $targetQueryIndex, " +
"retrying with deletion of query index",
e
)
if (docLevelQueryIndexExists(monitor.dataSources)) {
val ack = monitorCtx.docLevelMonitorQueries!!.deleteDocLevelQueryIndex(monitor.dataSources)
if (!ack) {
log.error(
"Deletion of concrete queryIndex:${monitor.dataSources.queryIndex} is not ack'd! " +
"for monitor ${monitor.id}"
)
}
}
initDocLevelQueryIndex(monitor.dataSources)
indexDocLevelQueries(
monitor = monitor,
monitorId = monitor.id,
monitorMetadata,
indexTimeout = indexTimeout
)
} catch (e: Exception) {
log.error(
"Doc level monitor ${monitor.id}: unknown exception during " +
"PUT mapping on queryIndex: $targetQueryIndex",
e
)
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
throw AlertingException.wrap(unwrappedException)
}
} else {
log.error(
"Doc level monitor ${monitor.id}: unknown exception during " +
"PUT mapping on queryIndex: $targetQueryIndex",
e
)
val unwrappedException = ExceptionsHelper.unwrapCause(e) as Exception
throw AlertingException.wrap(unwrappedException)
}
}
}
// We did rollover, so try to apply mappings again on new targetQueryIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient
"id", null)), trigger1Serialized)),
Map.of(),
new DataSources(),
true,
false,
"sample-remote-monitor-plugin"
);
IndexMonitorRequest indexMonitorRequest1 = new IndexMonitorRequest(
Expand Down Expand Up @@ -155,7 +155,7 @@ public void onFailure(Exception e) {
List.of(),
Map.of(),
new DataSources(),
true,
false,
"sample-remote-monitor-plugin"
);
IndexMonitorRequest indexMonitorRequest2 = new IndexMonitorRequest(
Expand Down Expand Up @@ -239,7 +239,7 @@ public void onFailure(Exception e) {
"id", null)), trigger1Serialized)),
Map.of(),
new DataSources(),
true,
false,
"sample-remote-monitor-plugin"
);
IndexMonitorRequest indexDocLevelMonitorRequest = new IndexMonitorRequest(
Expand Down

0 comments on commit 94cace8

Please sign in to comment.