Skip to content

Commit

Permalink
feat: just delete tables when snap fails, relay on transaction when d…
Browse files Browse the repository at this point in the history
…eltas
  • Loading branch information
MiguelAHM committed Dec 10, 2024
1 parent 220013c commit 5f35735
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Conditional;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.io.BufferedReader;
Expand Down Expand Up @@ -72,6 +73,7 @@ private void processPayload(final byte[] deltaFilePayload, final String sessionI
persistVersion(source, metadata.version, metadata.sessionId);
}

@Transactional(transactionManager = NrtmClientTransactionConfiguration.NRTM_CLIENT_UPDATE_TRANSACTION)
private Metadata persistDeltas(final byte[] deltaFilePayload, String sessionId) {
ByteBuffer buffer = ByteBuffer.wrap(deltaFilePayload);
InputStream inputStream = new ByteArrayInputStream(buffer.array(), buffer.position(), buffer.remaining());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,22 @@ public void processFile(){
return;
}

importRecordsAndPersistVersion(source, nrtmClientLastVersionInfo, updateNotificationFile, hostname);
});
}

private void importRecordsAndPersistVersion(final String source, final NrtmClientVersionInfo nrtmClientLastVersionInfo,
final UpdateNotificationFileResponse updateNotificationFile, final String hostname) {
try {
if (nrtmClientLastVersionInfo == null) {
LOGGER.info("There is no existing Snapshot for the source {}", source);
snapshotImporter.doImport(source, updateNotificationFile.getSessionID(), updateNotificationFile.getSnapshot());
}
processSnapshot(source, nrtmClientLastVersionInfo, updateNotificationFile);

final List<UpdateNotificationFileResponse.NrtmFileLink> newDeltas = getNewDeltasFromNotificationFile(source, updateNotificationFile);
deltaImporter.doImport(source, updateNotificationFile.getSessionID(), newDeltas);
persistVersion(source, updateNotificationFile, hostname);
});
}

private void processSnapshot(final String source, final NrtmClientVersionInfo nrtmClientLastVersionInfo, final UpdateNotificationFileResponse updateNotificationFile) {

if (nrtmClientLastVersionInfo != null){
return;
}
try {
LOGGER.info("There is no existing Snapshot for the source {}", source);
snapshotImporter.doImport(source, updateNotificationFile.getSessionID(), updateNotificationFile.getSnapshot());
} catch (Exception ex) {
snapshotImporter.truncateTables();
LOGGER.error("There was an issue importing the records", ex);
Expand Down

0 comments on commit 5f35735

Please sign in to comment.