From af9cca545a76a34c3cb9ba0066078acd6c576893 Mon Sep 17 00:00:00 2001 From: Abhilash Mandaliya Date: Mon, 13 May 2024 11:05:30 +0530 Subject: [PATCH] Checking the emptiness of binNames field before setting into command Minor code cleanup suggestion changes --- client/src/com/aerospike/client/BatchRead.java | 12 ++++++++++-- .../com/aerospike/client/async/AsyncBatch.java | 15 +++++++++++---- .../aerospike/client/async/AsyncBatchSingle.java | 14 +++++++++++--- .../com/aerospike/client/async/AsyncRead.java | 8 ++++++-- .../client/async/AsyncScanPartition.java | 6 +++++- .../client/async/AsyncScanPartitionExecutor.java | 6 +++++- .../src/com/aerospike/client/command/Batch.java | 10 +++++++--- .../aerospike/client/command/BatchSingle.java | 6 +++++- .../aerospike/client/command/ReadCommand.java | 6 +++++- .../client/command/ScanPartitionCommand.java | 6 +++++- .../com/aerospike/client/query/Statement.java | 6 +++++- .../com/aerospike/client/proxy/BatchProxy.java | 16 ++++++++++++---- .../aerospike/client/proxy/ReadCommandProxy.java | 6 +++++- .../aerospike/client/proxy/ScanCommandProxy.java | 6 +++++- 14 files changed, 97 insertions(+), 26 deletions(-) diff --git a/client/src/com/aerospike/client/BatchRead.java b/client/src/com/aerospike/client/BatchRead.java index 1f8112a67..c25bb305d 100644 --- a/client/src/com/aerospike/client/BatchRead.java +++ b/client/src/com/aerospike/client/BatchRead.java @@ -57,7 +57,11 @@ public final class BatchRead extends BatchRecord { public BatchRead(Key key, String[] binNames) { super(key, false); this.policy = null; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.ops = null; this.readAllBins = false; } @@ -90,7 +94,11 @@ public BatchRead(Key key, Operation[] ops) { public BatchRead(BatchReadPolicy policy, Key key, String[] binNames) { super(key, false); this.policy = policy; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.ops = null; this.readAllBins = false; } diff --git a/client/src/com/aerospike/client/async/AsyncBatch.java b/client/src/com/aerospike/client/async/AsyncBatch.java index 5893e06ae..8b789f56e 100644 --- a/client/src/com/aerospike/client/async/AsyncBatch.java +++ b/client/src/com/aerospike/client/async/AsyncBatch.java @@ -16,7 +16,6 @@ */ package com.aerospike.client.async; -import java.util.ArrayList; import java.util.List; import com.aerospike.client.AerospikeClient; @@ -175,7 +174,11 @@ public GetArrayCommand( ) { super(parent, batch, batchPolicy, isOperation); this.keys = keys; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.ops = ops; this.records = records; this.readAttr = readAttr; @@ -236,7 +239,11 @@ public GetSequenceCommand( ) { super(parent, batch, batchPolicy, isOperation); this.keys = keys; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.ops = ops; this.listener = listener; this.readAttr = readAttr; @@ -963,7 +970,7 @@ protected boolean retryBatch(Runnable other, long deadline) { // This can cause an exponential number of commands. List batchNodes = generateBatchNodes(); - if (batchNodes.size() == 0 || (batchNodes.size() == 1 && batchNodes.get(0).node == batch.node)) { + if (batchNodes.isEmpty() || (batchNodes.size() == 1 && batchNodes.getFirst().node == batch.node)) { // Go through normal retry. return false; } diff --git a/client/src/com/aerospike/client/async/AsyncBatchSingle.java b/client/src/com/aerospike/client/async/AsyncBatchSingle.java index 59e9c379e..a3c371b87 100644 --- a/client/src/com/aerospike/client/async/AsyncBatchSingle.java +++ b/client/src/com/aerospike/client/async/AsyncBatchSingle.java @@ -63,7 +63,7 @@ public ReadGetSequence( } @Override - protected final boolean parseResult() { + protected boolean parseResult() { super.parseResult(); try { @@ -181,7 +181,11 @@ public Get( boolean isOperation ) { super(executor, cluster, policy, key, node, false); - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.records = records; this.index = index; this.isOperation = isOperation; @@ -242,7 +246,11 @@ public GetSequence( ) { super(executor, cluster, policy, key, node, false); this.listener = listener; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.isOperation = isOperation; } diff --git a/client/src/com/aerospike/client/async/AsyncRead.java b/client/src/com/aerospike/client/async/AsyncRead.java index 2b2959ffe..c14c948cb 100644 --- a/client/src/com/aerospike/client/async/AsyncRead.java +++ b/client/src/com/aerospike/client/async/AsyncRead.java @@ -41,7 +41,11 @@ public AsyncRead(Cluster cluster, RecordListener listener, Policy policy, Key ke super(policy, true); this.listener = listener; this.key = key; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.isOperation = false; this.partition = Partition.read(cluster, policy, key); cluster.addTran(); @@ -126,7 +130,7 @@ protected void handleNotFound(int resultCode) { // Do nothing in default case. Record will be null. } - private final void handleUdfError(int resultCode) { + private void handleUdfError(int resultCode) { String ret = (String)record.bins.get("FAILURE"); if (ret == null) { diff --git a/client/src/com/aerospike/client/async/AsyncScanPartition.java b/client/src/com/aerospike/client/async/AsyncScanPartition.java index bd1363d44..a84917d1f 100644 --- a/client/src/com/aerospike/client/async/AsyncScanPartition.java +++ b/client/src/com/aerospike/client/async/AsyncScanPartition.java @@ -54,7 +54,11 @@ public AsyncScanPartition( this.listener = listener; this.namespace = namespace; this.setName = setName; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.taskId = taskId; this.tracker = tracker; this.nodePartitions = nodePartitions; diff --git a/client/src/com/aerospike/client/async/AsyncScanPartitionExecutor.java b/client/src/com/aerospike/client/async/AsyncScanPartitionExecutor.java index adf5dff7d..51773d772 100644 --- a/client/src/com/aerospike/client/async/AsyncScanPartitionExecutor.java +++ b/client/src/com/aerospike/client/async/AsyncScanPartitionExecutor.java @@ -51,7 +51,11 @@ public AsyncScanPartitionExecutor( this.listener = listener; this.namespace = namespace; this.setName = setName; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.tracker = tracker; this.random = new RandomShift(); diff --git a/client/src/com/aerospike/client/command/Batch.java b/client/src/com/aerospike/client/command/Batch.java index a5168c061..9c1e2fca1 100644 --- a/client/src/com/aerospike/client/command/Batch.java +++ b/client/src/com/aerospike/client/command/Batch.java @@ -115,7 +115,11 @@ public GetArrayCommand( ) { super(cluster, batch, policy, status, isOperation); this.keys = keys; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.ops = ops; this.records = records; this.readAttr = readAttr; @@ -554,7 +558,7 @@ protected boolean retryBatch( // This is both recursive and exponential. List batchNodes = generateBatchNodes(); - if (batchNodes.size() == 1 && batchNodes.get(0).node == batch.node) { + if (batchNodes.size() == 1 && batchNodes.getFirst().node == batch.node) { // Batch node is the same. Go through normal retry. return false; } @@ -562,7 +566,7 @@ protected boolean retryBatch( splitRetry = true; // Run batch retries in parallel using virtual threads. - try (ExecutorService es = Executors.newThreadPerTaskExecutor(cluster.threadFactory);) { + try (ExecutorService es = Executors.newThreadPerTaskExecutor(cluster.threadFactory)) { for (BatchNode batchNode : batchNodes) { BatchCommand command = createCommand(batchNode); command.sequenceAP = sequenceAP; diff --git a/client/src/com/aerospike/client/command/BatchSingle.java b/client/src/com/aerospike/client/command/BatchSingle.java index f14180ea5..030410bc0 100644 --- a/client/src/com/aerospike/client/command/BatchSingle.java +++ b/client/src/com/aerospike/client/command/BatchSingle.java @@ -78,7 +78,11 @@ public Read( ) { super(cluster, policy, status, key, node, false); this.key = key; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.records = records; this.index = index; this.isOperation = isOperation; diff --git a/client/src/com/aerospike/client/command/ReadCommand.java b/client/src/com/aerospike/client/command/ReadCommand.java index 0bbccc12f..b4d9aa47b 100644 --- a/client/src/com/aerospike/client/command/ReadCommand.java +++ b/client/src/com/aerospike/client/command/ReadCommand.java @@ -48,7 +48,11 @@ public ReadCommand(Cluster cluster, Policy policy, Key key) { public ReadCommand(Cluster cluster, Policy policy, Key key, String[] binNames) { super(cluster, policy); this.key = key; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.partition = Partition.read(cluster, policy, key); this.isOperation = false; cluster.addTran(); diff --git a/client/src/com/aerospike/client/command/ScanPartitionCommand.java b/client/src/com/aerospike/client/command/ScanPartitionCommand.java index a8daa4328..fa2effb9c 100644 --- a/client/src/com/aerospike/client/command/ScanPartitionCommand.java +++ b/client/src/com/aerospike/client/command/ScanPartitionCommand.java @@ -49,7 +49,11 @@ public ScanPartitionCommand( super(cluster, scanPolicy, nodePartitions.node, namespace, tracker.socketTimeout, tracker.totalTimeout); this.scanPolicy = scanPolicy; this.setName = setName; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.callback = callback; this.taskId = taskId; this.tracker = tracker; diff --git a/client/src/com/aerospike/client/query/Statement.java b/client/src/com/aerospike/client/query/Statement.java index f53951ddd..f35729674 100644 --- a/client/src/com/aerospike/client/query/Statement.java +++ b/client/src/com/aerospike/client/query/Statement.java @@ -89,7 +89,11 @@ public String getIndexName() { * Set query bin names. */ public void setBinNames(String... binNames) { - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } } /** diff --git a/proxy/src/com/aerospike/client/proxy/BatchProxy.java b/proxy/src/com/aerospike/client/proxy/BatchProxy.java index c4ce06f8d..a4f759f5e 100644 --- a/proxy/src/com/aerospike/client/proxy/BatchProxy.java +++ b/proxy/src/com/aerospike/client/proxy/BatchProxy.java @@ -51,8 +51,8 @@ public class BatchProxy { //------------------------------------------------------- public interface BatchListListenerSync { - public void onSuccess(List records, boolean status); - public void onFailure(AerospikeException ae); + void onSuccess(List records, boolean status); + void onFailure(AerospikeException ae); } public static final class ReadListCommandSync extends BaseCommand { @@ -217,7 +217,11 @@ public GetArrayCommand( super(executor, batchPolicy, isOperation, keys.length); this.listener = listener; this.keys = keys; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.ops = ops; this.readAttr = readAttr; this.records = new Record[keys.length]; @@ -276,7 +280,11 @@ public GetSequenceCommand( super(executor, batchPolicy, isOperation, keys.length); this.listener = listener; this.keys = keys; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.ops = ops; this.readAttr = readAttr; } diff --git a/proxy/src/com/aerospike/client/proxy/ReadCommandProxy.java b/proxy/src/com/aerospike/client/proxy/ReadCommandProxy.java index 4db4255c4..30e699628 100644 --- a/proxy/src/com/aerospike/client/proxy/ReadCommandProxy.java +++ b/proxy/src/com/aerospike/client/proxy/ReadCommandProxy.java @@ -45,7 +45,11 @@ public ReadCommandProxy( super(KVSGrpc.getReadStreamingMethod(), executor, policy); this.listener = listener; this.key = key; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.isOperation = false; } diff --git a/proxy/src/com/aerospike/client/proxy/ScanCommandProxy.java b/proxy/src/com/aerospike/client/proxy/ScanCommandProxy.java index 250315275..0f6d9a306 100644 --- a/proxy/src/com/aerospike/client/proxy/ScanCommandProxy.java +++ b/proxy/src/com/aerospike/client/proxy/ScanCommandProxy.java @@ -47,7 +47,11 @@ public ScanCommandProxy( listener, partitionTracker); this.namespace = namespace; this.setName = setName; - this.binNames = binNames; + if (binNames == null || binNames.length == 0) { + this.binNames = null; + } else { + this.binNames = binNames; + } this.partitionFilter = partitionFilter; }