From 09347eb990d9a5adc1e97e9e7240edc2784bf367 Mon Sep 17 00:00:00 2001 From: brido4125 Date: Fri, 3 Jan 2025 11:19:17 +0900 Subject: [PATCH] INTERNAL: Remove reverse arg in bopGet and bopExtendedGet --- .../java/net/spy/memcached/ArcusClient.java | 32 +++++++------------ .../spy/memcached/collection/BTreeGet.java | 13 ++++++-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/main/java/net/spy/memcached/ArcusClient.java b/src/main/java/net/spy/memcached/ArcusClient.java index 0d729c4c9..d3c718857 100644 --- a/src/main/java/net/spy/memcached/ArcusClient.java +++ b/src/main/java/net/spy/memcached/ArcusClient.java @@ -639,13 +639,11 @@ public void gotData(String subkey, int flags, byte[] data, byte[] eflag) { * * @param k b+tree item's key * @param collectionGet operation parameters (element keys and so on) - * @param reverse false=forward or true=backward * @param tc transcoder to serialize and unserialize value * @return future holding the map of fetched elements and their keys */ private CollectionFuture>> asyncBopGet( - final String k, final CollectionGet collectionGet, - final boolean reverse, final Transcoder tc) { + final String k, final CollectionGet collectionGet, final Transcoder tc) { final CountDownLatch latch = new CountDownLatch(1); final CollectionGetFuture>> rv = new CollectionGetFuture<>(latch, operationTimeout); @@ -654,7 +652,7 @@ private CollectionFuture>> asyncBopGet( new CollectionGetOperation.Callback() { private final HashMap cachedDataMap = new HashMap<>(); private final GetResult>> result = - new BopGetResultImpl<>(cachedDataMap, reverse, tc); + new BopGetResultImpl<>(cachedDataMap, ((BTreeGet) collectionGet).isReversed(), tc); public void receivedStatus(OperationStatus status) { CollectionOperationStatus cstatus; @@ -1270,7 +1268,7 @@ public CollectionFuture>> asyncBopGet(String key, boolean dropIfEmpty) { BTreeUtil.validateBkey(bkey); BTreeGet get = new BTreeGet(bkey, withDelete, dropIfEmpty, eFlagFilter); - return asyncBopGet(key, get, false, collectionTranscoder); + return asyncBopGet(key, get, collectionTranscoder); } // @Override @@ -1290,8 +1288,7 @@ public CollectionFuture>> asyncBopGet(String key, boolean dropIfEmpty) { BTreeUtil.validateBkey(from, to); BTreeGet get = new BTreeGet(from, to, offset, count, withDelete, dropIfEmpty, eFlagFilter); - boolean reverse = from > to; - return asyncBopGet(key, get, reverse, collectionTranscoder); + return asyncBopGet(key, get, collectionTranscoder); } // @Override @@ -1311,7 +1308,7 @@ public CollectionFuture>> asyncBopGet(String key, Transcoder tc) { BTreeUtil.validateBkey(bkey); BTreeGet get = new BTreeGet(bkey, withDelete, dropIfEmpty, eFlagFilter); - return asyncBopGet(key, get, false, tc); + return asyncBopGet(key, get, tc); } // @Override @@ -1333,8 +1330,7 @@ public CollectionFuture>> asyncBopGet(String key, Transcoder tc) { BTreeUtil.validateBkey(from, to); BTreeGet get = new BTreeGet(from, to, offset, count, withDelete, dropIfEmpty, eFlagFilter); - boolean reverse = from > to; - return asyncBopGet(key, get, reverse, tc); + return asyncBopGet(key, get, tc); } // @Override @@ -2392,7 +2388,7 @@ public CollectionFuture>> asyncBopGet( boolean withDelete, boolean dropIfEmpty) { BTreeUtil.validateBkey(bkey); BTreeGet get = new BTreeGet(bkey, withDelete, dropIfEmpty, eFlagFilter); - return asyncBopExtendedGet(key, get, false, collectionTranscoder); + return asyncBopExtendedGet(key, get, collectionTranscoder); } // @Override @@ -2407,7 +2403,7 @@ public CollectionFuture>> asyncBopGet( boolean withDelete, boolean dropIfEmpty, Transcoder tc) { BTreeUtil.validateBkey(bkey); BTreeGet get = new BTreeGet(bkey, withDelete, dropIfEmpty, eFlagFilter); - return asyncBopExtendedGet(key, get, false, tc); + return asyncBopExtendedGet(key, get, tc); } // @Override @@ -2423,8 +2419,7 @@ public CollectionFuture>> asyncBopGet( int offset, int count, boolean withDelete, boolean dropIfEmpty) { BTreeUtil.validateBkey(from, to); BTreeGet get = new BTreeGet(from, to, offset, count, withDelete, dropIfEmpty, eFlagFilter); - boolean reverse = BTreeUtil.compareByteArraysInLexOrder(from, to) > 0; - return asyncBopExtendedGet(key, get, reverse, collectionTranscoder); + return asyncBopExtendedGet(key, get, collectionTranscoder); } // @Override @@ -2442,8 +2437,7 @@ public CollectionFuture>> asyncBopGet( Transcoder tc) { BTreeUtil.validateBkey(from, to); BTreeGet get = new BTreeGet(from, to, offset, count, withDelete, dropIfEmpty, eFlagFilter); - boolean reverse = BTreeUtil.compareByteArraysInLexOrder(from, to) > 0; - return asyncBopExtendedGet(key, get, reverse, tc); + return asyncBopExtendedGet(key, get, tc); } /** @@ -2452,13 +2446,11 @@ public CollectionFuture>> asyncBopGet( * * @param k b+tree item's key * @param collectionGet operation parameters (element key and so on) - * @param reverse forward or backward * @param tc transcoder to serialize and unserialize value * @return future holding the map of the fetched element and its byte-array bkey */ private CollectionFuture>> asyncBopExtendedGet( - final String k, final CollectionGet collectionGet, - final boolean reverse, final Transcoder tc) { + final String k, final CollectionGet collectionGet, final Transcoder tc) { final CountDownLatch latch = new CountDownLatch(1); final CollectionGetFuture>> rv @@ -2468,7 +2460,7 @@ private CollectionFuture>> asyncBopExtendedGet new CollectionGetOperation.Callback() { private final HashMap cachedDataMap = new HashMap<>(); private final GetResult>> result = - new BopGetResultImpl<>(cachedDataMap, reverse, tc); + new BopGetResultImpl<>(cachedDataMap, ((BTreeGet) collectionGet).isReversed(), tc); public void receivedStatus(OperationStatus status) { CollectionOperationStatus cstatus; diff --git a/src/main/java/net/spy/memcached/collection/BTreeGet.java b/src/main/java/net/spy/memcached/collection/BTreeGet.java index 5e0f79a30..2bddb043a 100644 --- a/src/main/java/net/spy/memcached/collection/BTreeGet.java +++ b/src/main/java/net/spy/memcached/collection/BTreeGet.java @@ -26,6 +26,7 @@ public class BTreeGet extends CollectionGet { protected int offset = -1; protected int count = -1; protected ElementFlagFilter elementFlagFilter; + private boolean reverse = false; private BTreeGet(String range, boolean delete, boolean dropIfEmpty, @@ -50,18 +51,19 @@ public BTreeGet(byte[] bkey, this(BTreeUtil.toHex(bkey), delete, dropIfEmpty, elementFlagFilter); } - private BTreeGet(String range, int offset, int count, - boolean delete, boolean dropIfEmpty, + private BTreeGet(String range, boolean reverse, int offset, + int count, boolean delete, boolean dropIfEmpty, ElementFlagFilter elementFlagFilter) { this(range, delete, dropIfEmpty, elementFlagFilter); this.offset = offset; this.count = count; + this.reverse = reverse; } public BTreeGet(long from, long to, int offset, int count, boolean delete, boolean dropIfEmpty, ElementFlagFilter elementFlagFilter) { - this(from + ".." + to, + this(from + ".." + to, from > to, offset, count, delete, dropIfEmpty, elementFlagFilter); } @@ -69,9 +71,14 @@ public BTreeGet(byte[] from, byte[] to, int offset, int count, boolean delete, boolean dropIfEmpty, ElementFlagFilter elementFlagFilter) { this(BTreeUtil.toHex(from) + ".." + BTreeUtil.toHex(to), + BTreeUtil.compareByteArraysInLexOrder(from, to) > 0, offset, count, delete, dropIfEmpty, elementFlagFilter); } + public boolean isReversed() { + return reverse; + } + public String getRange() { return range; }