Skip to content

Commit

Permalink
INTERNAL: Remove reverse arg in bopGet and bopExtendedGet
Browse files Browse the repository at this point in the history
  • Loading branch information
brido4125 authored and jhpark816 committed Jan 3, 2025
1 parent 85417cd commit db1c636
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 23 deletions.
32 changes: 12 additions & 20 deletions src/main/java/net/spy/memcached/ArcusClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> CollectionFuture<Map<Long, Element<T>>> asyncBopGet(
final String k, final CollectionGet collectionGet,
final boolean reverse, final Transcoder<T> tc) {
final String k, final CollectionGet collectionGet, final Transcoder<T> tc) {
final CountDownLatch latch = new CountDownLatch(1);
final CollectionGetFuture<Map<Long, Element<T>>> rv =
new CollectionGetFuture<>(latch, operationTimeout);
Expand All @@ -654,7 +652,7 @@ private <T> CollectionFuture<Map<Long, Element<T>>> asyncBopGet(
new CollectionGetOperation.Callback() {
private final HashMap<Long, CachedData> cachedDataMap = new HashMap<>();
private final GetResult<Map<Long, Element<T>>> result =
new BopGetResultImpl<>(cachedDataMap, reverse, tc);
new BopGetResultImpl<>(cachedDataMap, ((BTreeGet) collectionGet).isReversed(), tc);

public void receivedStatus(OperationStatus status) {
CollectionOperationStatus cstatus;
Expand Down Expand Up @@ -1270,7 +1268,7 @@ public CollectionFuture<Map<Long, Element<Object>>> 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
Expand All @@ -1290,8 +1288,7 @@ public CollectionFuture<Map<Long, Element<Object>>> 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
Expand All @@ -1311,7 +1308,7 @@ public <T> CollectionFuture<Map<Long, Element<T>>> asyncBopGet(String key,
Transcoder<T> tc) {
BTreeUtil.validateBkey(bkey);
BTreeGet get = new BTreeGet(bkey, withDelete, dropIfEmpty, eFlagFilter);
return asyncBopGet(key, get, false, tc);
return asyncBopGet(key, get, tc);
}

// @Override
Expand All @@ -1333,8 +1330,7 @@ public <T> CollectionFuture<Map<Long, Element<T>>> asyncBopGet(String key,
Transcoder<T> 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
Expand Down Expand Up @@ -2392,7 +2388,7 @@ public CollectionFuture<Map<ByteArrayBKey, Element<Object>>> 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
Expand All @@ -2407,7 +2403,7 @@ public <T> CollectionFuture<Map<ByteArrayBKey, Element<T>>> asyncBopGet(
boolean withDelete, boolean dropIfEmpty, Transcoder<T> tc) {
BTreeUtil.validateBkey(bkey);
BTreeGet get = new BTreeGet(bkey, withDelete, dropIfEmpty, eFlagFilter);
return asyncBopExtendedGet(key, get, false, tc);
return asyncBopExtendedGet(key, get, tc);
}

// @Override
Expand All @@ -2423,8 +2419,7 @@ public CollectionFuture<Map<ByteArrayBKey, Element<Object>>> 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
Expand All @@ -2442,8 +2437,7 @@ public <T> CollectionFuture<Map<ByteArrayBKey, Element<T>>> asyncBopGet(
Transcoder<T> 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);
}

/**
Expand All @@ -2452,13 +2446,11 @@ public <T> CollectionFuture<Map<ByteArrayBKey, Element<T>>> 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 <T> CollectionFuture<Map<ByteArrayBKey, Element<T>>> asyncBopExtendedGet(
final String k, final CollectionGet collectionGet,
final boolean reverse, final Transcoder<T> tc) {
final String k, final CollectionGet collectionGet, final Transcoder<T> tc) {

final CountDownLatch latch = new CountDownLatch(1);
final CollectionGetFuture<Map<ByteArrayBKey, Element<T>>> rv
Expand All @@ -2468,7 +2460,7 @@ private <T> CollectionFuture<Map<ByteArrayBKey, Element<T>>> asyncBopExtendedGet
new CollectionGetOperation.Callback() {
private final HashMap<ByteArrayBKey, CachedData> cachedDataMap = new HashMap<>();
private final GetResult<Map<ByteArrayBKey, Element<T>>> result =
new BopGetResultImpl<>(cachedDataMap, reverse, tc);
new BopGetResultImpl<>(cachedDataMap, ((BTreeGet) collectionGet).isReversed(), tc);

public void receivedStatus(OperationStatus status) {
CollectionOperationStatus cstatus;
Expand Down
13 changes: 10 additions & 3 deletions src/main/java/net/spy/memcached/collection/BTreeGet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -50,28 +51,34 @@ 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);
}

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;
}
Expand Down

0 comments on commit db1c636

Please sign in to comment.