From def751b9c9c1541388098101fe7aa3b9784f80ca Mon Sep 17 00:00:00 2001 From: Pratick Chokhani Date: Mon, 9 Dec 2024 20:23:18 +0530 Subject: [PATCH] lint(spanner): Removed unused variables. --- .../com/google/cloud/spanner/BatchClientImpl.java | 13 +++---------- .../google/cloud/spanner/BatchTransactionId.java | 6 +----- .../cloud/spanner/BatchTransactionIdTest.java | 12 ++++++------ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java index f7866ea092f..a250fd5ba39 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchClientImpl.java @@ -59,8 +59,6 @@ public class BatchClientImpl implements BatchClient { @GuardedBy("multiplexedSessionLock") private final AtomicReference multiplexedSessionReference; - private final Clock clock; - BatchClientImpl(SessionClient sessionClient, boolean isMultiplexedSessionEnabled) { this.sessionClient = checkNotNull(sessionClient); this.isMultiplexedSessionEnabled = isMultiplexedSessionEnabled; @@ -76,7 +74,6 @@ public class BatchClientImpl implements BatchClient { // This also ensured that a new session is created on first request. this.expirationDate = new AtomicReference<>(Instant.MIN); this.multiplexedSessionReference = new AtomicReference<>(); - clock = Clock.systemUTC(); } @Override @@ -137,10 +134,10 @@ public BatchReadOnlyTransaction batchReadOnlyTransaction(BatchTransactionId batc private SessionImpl getMultiplexedSession() { this.multiplexedSessionLock.lock(); try { - if (this.clock.instant().isAfter(this.expirationDate.get()) + if (Clock.systemUTC().instant().isAfter(this.expirationDate.get()) || this.multiplexedSessionReference.get() == null) { this.multiplexedSessionReference.set(this.sessionClient.createMultiplexedSession()); - this.expirationDate.set(this.clock.instant().plus(this.sessionExpirationDuration)); + this.expirationDate.set(Clock.systemUTC().instant().plus(this.sessionExpirationDuration)); } return this.multiplexedSessionReference.get(); } finally { @@ -151,14 +148,12 @@ private SessionImpl getMultiplexedSession() { private static class BatchReadOnlyTransactionImpl extends MultiUseReadOnlyTransaction implements BatchReadOnlyTransaction { private final String sessionName; - private final boolean isMultiplexedSession; private final Map options; BatchReadOnlyTransactionImpl( MultiUseReadOnlyTransaction.Builder builder, TimestampBound bound) { super(builder.setTimestampBound(bound)); this.sessionName = session.getName(); - this.isMultiplexedSession = session.getIsMultiplexed(); this.options = session.getOptions(); initTransaction(); } @@ -168,13 +163,11 @@ private static class BatchReadOnlyTransactionImpl extends MultiUseReadOnlyTransa super(builder.setTransactionId(batchTransactionId.getTransactionId())); this.sessionName = session.getName(); this.options = session.getOptions(); - this.isMultiplexedSession = session.getIsMultiplexed(); } @Override public BatchTransactionId getBatchTransactionId() { - return new BatchTransactionId( - sessionName, getTransactionId(), getReadTimestamp(), session.getIsMultiplexed()); + return new BatchTransactionId(sessionName, getTransactionId(), getReadTimestamp()); } @Override diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchTransactionId.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchTransactionId.java index 2e2b4f89001..a5a02ac1360 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchTransactionId.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/BatchTransactionId.java @@ -34,11 +34,7 @@ public class BatchTransactionId implements Serializable { private final Timestamp timestamp; private static final long serialVersionUID = 8067099123096783939L; - BatchTransactionId( - String sessionId, - ByteString transactionId, - Timestamp timestamp, - boolean isMultiplexedSession) { + BatchTransactionId(String sessionId, ByteString transactionId, Timestamp timestamp) { this.transactionId = Preconditions.checkNotNull(transactionId); this.sessionId = Preconditions.checkNotNull(sessionId); this.timestamp = Preconditions.checkNotNull(timestamp); diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchTransactionIdTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchTransactionIdTest.java index 10d1a28ed8a..81d4de41695 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchTransactionIdTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/BatchTransactionIdTest.java @@ -34,14 +34,14 @@ public void equalAndHashCode() { new EqualsTester() .addEqualityGroup( new BatchTransactionId( - "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE, false), + "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE), new BatchTransactionId( - "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE, false)) + "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE)) .addEqualityGroup( new BatchTransactionId( - "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MAX_VALUE, true), + "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MAX_VALUE), new BatchTransactionId( - "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MAX_VALUE, true)) + "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MAX_VALUE)) .testEquals(); } @@ -49,9 +49,9 @@ public void equalAndHashCode() { public void serialization() { reserializeAndAssert( new BatchTransactionId( - "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE, false)); + "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE)); reserializeAndAssert( new BatchTransactionId( - "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE, true)); + "testSession", ByteString.copyFromUtf8("testTxn"), Timestamp.MIN_VALUE)); } }