Set payload response in happy path of ReplayCommitLogsToSqlAction (#1229)

* Set payload response in happy path of ReplayCommitLogsToSqlAction

I suspect this may be the reason the logs are missing on the happy path (when it
runs successfully), but are visible on the exception paths (which do set the
payload response). I don't think App Engine likes it when a Web request
terminates without a response.

This also adds more logging and error handling.
This commit is contained in:
Ben McIlwain 2021-07-01 18:21:17 -04:00 committed by GitHub
parent 047444831b
commit 4e30d020ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 3 deletions

View file

@ -109,7 +109,14 @@ public class ReplayCommitLogsToSqlAction implements Runnable {
try { try {
replayFiles(); replayFiles();
response.setStatus(HttpServletResponse.SC_OK); response.setStatus(HttpServletResponse.SC_OK);
logger.atInfo().log("ReplayCommitLogsToSqlAction completed successfully."); String message = "ReplayCommitLogsToSqlAction completed successfully.";
response.setPayload(message);
logger.atInfo().log(message);
} catch (Throwable t) {
String message = "Errored out replaying files.";
logger.atSevere().withCause(t).log(message);
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
response.setPayload(message);
} finally { } finally {
lock.ifPresent(Lock::release); lock.ifPresent(Lock::release);
} }
@ -139,21 +146,30 @@ public class ReplayCommitLogsToSqlAction implements Runnable {
} }
private void processFile(GcsFileMetadata metadata) { private void processFile(GcsFileMetadata metadata) {
logger.atInfo().log(
"Processing commit log file %s of size %d B.",
metadata.getFilename(), metadata.getLength());
try (InputStream input = try (InputStream input =
Channels.newInputStream( Channels.newInputStream(
gcsService.openPrefetchingReadChannel(metadata.getFilename(), 0, BLOCK_SIZE))) { gcsService.openPrefetchingReadChannel(metadata.getFilename(), 0, BLOCK_SIZE))) {
// Load and process the Datastore transactions one at a time // Load and process the Datastore transactions one at a time
ImmutableList<ImmutableList<VersionedEntity>> allTransactions = ImmutableList<ImmutableList<VersionedEntity>> allTransactions =
CommitLogImports.loadEntitiesByTransaction(input); CommitLogImports.loadEntitiesByTransaction(input);
logger.atInfo().log(
"Replaying %d transactions from commit log file %s.",
allTransactions.size(), metadata.getFilename());
allTransactions.forEach(this::replayTransaction); allTransactions.forEach(this::replayTransaction);
// if we succeeded, set the last-seen time // if we succeeded, set the last-seen time
DateTime checkpoint = DateTime checkpoint =
DateTime.parse( DateTime.parse(
metadata.getFilename().getObjectName().substring(DIFF_FILE_PREFIX.length())); metadata.getFilename().getObjectName().substring(DIFF_FILE_PREFIX.length()));
SqlReplayCheckpoint.set(checkpoint); SqlReplayCheckpoint.set(checkpoint);
logger.atInfo().log("Replayed %d transactions from commit log file.", allTransactions.size()); logger.atInfo().log(
"Replayed %d transactions from commit log file %s.",
allTransactions.size(), metadata.getFilename());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(
"Errored out while replaying commit log file " + metadata.getFilename(), e);
} }
} }

View file

@ -494,6 +494,8 @@ public class ReplayCommitLogsToSqlActionTest {
private void runAndAssertSuccess(DateTime expectedCheckpointTime) { private void runAndAssertSuccess(DateTime expectedCheckpointTime) {
action.run(); action.run();
assertThat(response.getStatus()).isEqualTo(SC_OK); assertThat(response.getStatus()).isEqualTo(SC_OK);
assertThat(response.getPayload())
.isEqualTo("ReplayCommitLogsToSqlAction completed successfully.");
assertThat(jpaTm().transact(SqlReplayCheckpoint::get)).isEqualTo(expectedCheckpointTime); assertThat(jpaTm().transact(SqlReplayCheckpoint::get)).isEqualTo(expectedCheckpointTime);
} }