mirror of
https://github.com/google/nomulus
synced 2026-09-12 11:06:29 +00:00
Use one SQL transaction per Datastore transaction in replay to SQL (#1268)
There was a subtle issue that we encountered in sandbox when using one transaction per file that was difficult to replicate. Basically, 1. Save a domain with dsData 2. Save the domain without dsData 3. Save the domain with the same dsData as step 1 4. Delete literally any object If one performs steps 2-4 in the same transaction, Hibernate will throw an exception (cascade re-saving a cascade-deleted object). Note that step 4 is in fact necessary to reproduce the issue, yay Hibernate. We will test this and if one transaction per transaction is too slow, we'll figure out ways to reduce the number of SQL transactions.
This commit is contained in:
@@ -189,7 +189,7 @@ public class ReplayCommitLogsToSqlAction implements Runnable {
|
||||
searchStartTime.toString("yyyy-MM-dd HH"));
|
||||
}
|
||||
for (BlobInfo file : fileBatch) {
|
||||
jpaTm().transact(() -> processFile(file));
|
||||
processFile(file);
|
||||
filesProcessed++;
|
||||
if (clock.nowUtc().isAfter(replayTimeoutTime)) {
|
||||
return String.format(
|
||||
@@ -205,10 +205,11 @@ public class ReplayCommitLogsToSqlAction implements Runnable {
|
||||
// Load and process the Datastore transactions one at a time
|
||||
ImmutableList<ImmutableList<VersionedEntity>> allTransactions =
|
||||
CommitLogImports.loadEntitiesByTransaction(input);
|
||||
allTransactions.forEach(this::replayTransaction);
|
||||
allTransactions.forEach(
|
||||
transaction -> jpaTm().transact(() -> replayTransaction(transaction)));
|
||||
// if we succeeded, set the last-seen time
|
||||
DateTime checkpoint = DateTime.parse(metadata.getName().substring(DIFF_FILE_PREFIX.length()));
|
||||
SqlReplayCheckpoint.set(checkpoint);
|
||||
jpaTm().transact(() -> SqlReplayCheckpoint.set(checkpoint));
|
||||
logger.atInfo().log(
|
||||
"Replayed %d transactions from commit log file %s with size %d B.",
|
||||
allTransactions.size(), metadata.getName(), metadata.getSize());
|
||||
|
||||
Reference in New Issue
Block a user