diff --git a/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/importer/DeltaMirrorImporter.java b/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/importer/DeltaMirrorImporter.java index 78b5199709..c0038cc932 100644 --- a/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/importer/DeltaMirrorImporter.java +++ b/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/importer/DeltaMirrorImporter.java @@ -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; @@ -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()); diff --git a/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/processor/UpdateNotificationFileProcessor.java b/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/processor/UpdateNotificationFileProcessor.java index 7de07e7bcd..f079394ec5 100644 --- a/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/processor/UpdateNotificationFileProcessor.java +++ b/whois-nrtm4-client/src/main/java/net/ripe/db/nrtm4/client/processor/UpdateNotificationFileProcessor.java @@ -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 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);