Skip to content

Commit

Permalink
Add index name to logging
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Dai <[email protected]>
  • Loading branch information
dai-chen committed Jun 25, 2024
1 parent 972ed7d commit 6e72473
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,21 @@ trait FlintSparkTransactionSupport { self: Logging =>
*/
def withTransaction[T](indexName: String, opName: String, forceInit: Boolean = false)(
opBlock: OptimisticTransaction[T] => T): T = {
logInfo(s"Starting index operation [$opName for $indexName] with forceInit=$forceInit")
logInfo(s"Starting index operation [$opName $indexName] with forceInit=$forceInit")
try {
// Create transaction (only have side effect if forceInit is true)
val tx: OptimisticTransaction[T] =
flintMetadataLogService.startTransaction(indexName, forceInit)

val result = opBlock(tx)
logInfo(s"Index operation [$opName] complete")
logInfo(s"Index operation [$opName $indexName] complete")
result
} catch {
case e: Exception =>
// Extract and add root cause message to final error message
val rootCauseMessage = extractRootCause(e)
val detailedMessage =
s"Failed to execute index operation [$opName] caused by: $rootCauseMessage"
s"Failed to execute index operation [$opName $indexName] caused by: $rootCauseMessage"
logError(detailedMessage, e)

// Re-throw with new detailed error message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FlintSparkTransactionSupportSuite extends FlintSuite with Matchers {
throw new IllegalArgumentException("Fake exception")
}
} should have message
"Failed to execute index operation [test operation] caused by: Fake exception"
s"Failed to execute index operation [test operation $testIndex] caused by: Fake exception"
}

test("should throw exception with root cause exception message") {
Expand All @@ -54,6 +54,6 @@ class FlintSparkTransactionSupportSuite extends FlintSuite with Matchers {
throw new IllegalStateException("message ignored", cause)
}
} should have message
"Failed to execute index operation [test operation] caused by: Fake root cause"
s"Failed to execute index operation [test operation $testIndex] caused by: Fake root cause"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class FlintSparkTransactionITSuite extends OpenSearchTransactionSuite with Match
the[IllegalStateException] thrownBy {
flint.vacuumIndex(testFlintIndex)
} should have message
s"Failed to execute index operation [Vacuum Flint index] caused by: Index state [active] doesn't satisfy precondition"
s"Failed to execute index operation [Vacuum Flint index $testFlintIndex] caused by: Index state [active] doesn't satisfy precondition"
}

test("should not recreate index if index data still exists") {
Expand All @@ -209,7 +209,7 @@ class FlintSparkTransactionITSuite extends OpenSearchTransactionSuite with Match
.addValueSet("name")
.create()
} should have message
s"Failed to execute index operation [Create Flint index] caused by: Flint index $testFlintIndex already exists"
s"Failed to execute index operation [Create Flint index $testFlintIndex] caused by: Flint index $testFlintIndex already exists"
}

test("should clean up metadata log entry if index data has been deleted") {
Expand Down

0 comments on commit 6e72473

Please sign in to comment.