From 9bc449025dde8f580f2fd2c0c19c5c9cbc87e9d8 Mon Sep 17 00:00:00 2001 From: "andre.martins" Date: Thu, 30 Mar 2023 15:06:25 +0100 Subject: [PATCH] Improve message when lock is held by some other client --- .../java/uk/sky/cqlmigrate/CassandraLockingMechanism.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java b/src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java index 397f1b6..082d888 100644 --- a/src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java +++ b/src/main/java/uk/sky/cqlmigrate/CassandraLockingMechanism.java @@ -72,12 +72,13 @@ public boolean acquire(String clientId) throws CannotAcquireLockException { verifyClusterIsHealthy(); ResultSet resultSet = session.execute(insertLockQuery.bind(lockName, clientId)); Row currentLock = resultSet.one(); + String currentClientWithLock = currentLock.getString("client"); // we could already hold the lock and not be aware if a previous acquire had a writetimeout as a timeout is not a failure in cassandra // also since we use a conditional insertion (IF NOT EXISTS) the resultSet is never null, same with resultSet.one() - if (currentLock.getBoolean("[applied]") || clientId.equals(currentLock.getString("client"))) { + if (currentLock.getBoolean("[applied]") || clientId.equals(currentClientWithLock)) { return true; } else { - log.info("Lock currently held by {}", currentLock); + log.info("Lock currently held by client {}", currentClientWithLock); return false; } } catch (WriteTimeoutException wte) {