From ae2407e066c89a12e3f1726b384e16842488d9fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20R=C3=B6gner?= Date: Tue, 13 Dec 2022 18:43:28 +0100 Subject: [PATCH] Preparations for versioning in PSQL Connector MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Preparations for intermediate deployment phase1: - Fix disabling phaseLock for OTA phase1 Signed-off-by: Benjamin Rögner --- .../java/com/here/xyz/psql/DatabaseHandler.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java index a6e537539e..60baaba659 100644 --- a/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java +++ b/xyz-psql-connector/src/main/java/com/here/xyz/psql/DatabaseHandler.java @@ -915,18 +915,19 @@ public static int readVersionsToKeep(Event event) { } private boolean executeOneTimeAction(String phase, Map inputData) throws SQLException { + boolean phaseLock = "phase1".equals(phase) ? false : true; try (final Connection connection = dataSource.getConnection()) { logger.info("oneTimeAction " + phase + ": Starting execution ..."); - if (_advisory(phase, connection, true, false)) { + if (!phaseLock || _advisory(phase, connection, true, false)) { try { switch (phase) { case "phase0": { - oneTimeActionForVersioning(phase, inputData, connection, true); + oneTimeActionForVersioning(phase, inputData, connection); break; } case "phase1": { setupOneTimeActionFillNewColumns(phase, connection); - oneTimeActionForVersioning(phase, inputData, connection, false); + oneTimeActionForVersioning(phase, inputData, connection); break; } case "phaseX": { @@ -947,7 +948,8 @@ private boolean executeOneTimeAction(String phase, Map inputData } } finally { - _advisory(phase, connection, false, false); + if (phaseLock) + _advisory(phase, connection, false, false); } return true; } @@ -972,7 +974,7 @@ private Map getDefaultInputDataForOneTimeAction(String phase) th return Collections.emptyMap(); } - private void oneTimeActionForVersioning(String phase, Map inputData, Connection connection, boolean phaseLock) throws SQLException { + private void oneTimeActionForVersioning(String phase, Map inputData, Connection connection) throws SQLException { if (inputData == null || !inputData.containsKey("tableNames") || !(inputData.get("tableNames") instanceof List)) throw new IllegalArgumentException("Table names have to be defined for OTA phase: " + phase); List tableNames = (List) inputData.get("tableNames"); @@ -989,7 +991,7 @@ private void oneTimeActionForVersioning(String phase, Map inputD boolean tableCompleted = false; logger.info(phase + ": process table: " + tableName); - if (!phaseLock || _advisory(tableName, connection, true, false)) { + if (_advisory(tableName, connection, true, false)) { long tableStartTime = System.currentTimeMillis(); boolean cStateFlag = connection.getAutoCommit(); try {