Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INTERNAL: Integration get and mget api #860

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1103,10 +1103,9 @@ public void complete() {

Operation op;
if (node == null) {
op = opFact.mget(keyList, cb);
op = opFact.get(keyList, cb, false);
} else {
op = node.enabledMGetOp() ? opFact.mget(keyList, cb)
: opFact.get(keyList, cb);
op = opFact.get(keyList, cb, node.enabledMGetOp());
}
conn.addOperation(node, op);
ops.add(op);
Expand Down Expand Up @@ -1240,10 +1239,9 @@ public void complete() {

Operation op;
if (node == null) {
op = opFact.mgets(keyList, cb);
op = opFact.gets(keyList, cb, false);
} else {
op = node.enabledMGetsOp() ? opFact.mgets(keyList, cb)
: opFact.gets(keyList, cb);
op = opFact.gets(keyList, cb, node.enabledMGetOp());
}
conn.addOperation(node, op);
ops.add(op);
Expand Down
25 changes: 4 additions & 21 deletions src/main/java/net/spy/memcached/OperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,42 +133,25 @@ public interface OperationFactory {
*/
GetsOperation gets(String key, GetsOperation.Callback callback);


/**
* Create a get operation.
*
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @param isMGet true if the handling node provides mget command
* @return a new GetOperation
*/
GetOperation get(Collection<String> keys, GetOperation.Callback cb);
GetOperation get(Collection<String> keys, GetOperation.Callback cb, boolean isMGet);

/**
* Create a gets operation.
*
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @param isMGet true if the handling node provides mgets command
* @return a new GetsOperation
*/
GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb);

/**
* Create a mget operation.
*
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @return a new GetOperation
*/
GetOperation mget(Collection<String> keys, GetOperation.Callback cb);

/**
* Create a mgets operation.
*
* @param keys the collection of keys to get
* @param cb the callback that will contain the results
* @return a new GetOperation
*/
GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb);
GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMGet);

/**
* Create a mutator operation.
Expand Down
1 change: 0 additions & 1 deletion src/main/java/net/spy/memcached/ops/APIType.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public enum APIType {
INCR(OperationType.WRITE), DECR(OperationType.WRITE),
DELETE(OperationType.WRITE),
GET(OperationType.READ), GETS(OperationType.READ),
MGET(OperationType.READ), MGETS(OperationType.READ),

// List API Type
LOP_CREATE(OperationType.WRITE),
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/net/spy/memcached/ops/BaseOperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ public Operation cloneMultiOperation(KeyedOperation op, MemcachedNode node,
assert !op.hasErrored() : "Attempted to clone an errored op";

if (op instanceof GetOperation) {
// If MemcachedNode supports this clone feature, it should support mget operation too.
return mget(redirectKeys, (GetOperation.Callback) mcb);
return get(redirectKeys, (GetOperation.Callback) mcb, node.enabledMGetOp());
} else if (op instanceof GetsOperation) {
// If MemcachedNode supports this clone feature, it should support mgets operation too.
return mgets(redirectKeys, (GetsOperation.Callback) mcb);
return gets(redirectKeys, (GetsOperation.Callback) mcb, node.enabledMGetsOp());
} else if (op instanceof CollectionBulkInsertOperation) {
final CollectionBulkInsert<?> insert = ((CollectionBulkInsertOperation) op).getInsert();
return collectionBulkInsert(insert.clone(node, redirectKeys), mcb);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.net.SocketAddress;
import java.util.concurrent.BlockingQueue;

import net.spy.memcached.ops.APIType;
import net.spy.memcached.ops.GetOperation;
import net.spy.memcached.ops.Operation;
import net.spy.memcached.ops.OperationState;
Expand All @@ -45,10 +44,10 @@ protected void optimize() {
// make sure there are at least two get operations in a row before
// attempting to optimize them.
Operation nxtOp = writeQ.peek();
if (nxtOp instanceof GetOperation && nxtOp.getAPIType() != APIType.MGET) {
if (nxtOp instanceof GetOperation) {
optimizedOp = writeQ.remove();
nxtOp = writeQ.peek();
if (nxtOp instanceof GetOperation && nxtOp.getAPIType() != APIType.MGET) {
if (nxtOp instanceof GetOperation) {
OptimizedGetImpl og = new OptimizedGetImpl(
(GetOperation) optimizedOp);
optimizedOp = og;
Expand All @@ -59,8 +58,7 @@ protected void optimize() {
og.addOperation(o);
}
nxtOp = writeQ.peek();
} while (nxtOp instanceof GetOperation &&
nxtOp.getAPIType() != APIType.MGET);
} while (nxtOp instanceof GetOperation);

// Initialize the new mega get
optimizedOp.initialize();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,24 +98,16 @@ public GetOperation get(String key, GetOperation.Callback cb) {
return new GetOperationImpl(key, cb);
}

public GetOperation get(Collection<String> keys, GetOperation.Callback cb) {
return new GetOperationImpl(keys, cb);
public GetOperation get(Collection<String> keys, GetOperation.Callback cb, boolean isMGet) {
return new GetOperationImpl(keys, cb, isMGet);
}

public GetsOperation gets(String key, GetsOperation.Callback cb) {
return new GetsOperationImpl(key, cb);
}

public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb) {
return new GetsOperationImpl(keys, cb);
}

public GetOperation mget(Collection<String> keys, GetOperation.Callback cb) {
return new MGetOperationImpl(keys, cb);
}

public GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb) {
return new MGetsOperationImpl(keys, cb);
public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMGet) {
return new GetsOperationImpl(keys, cb, isMGet);
}

public MutatorOperation mutate(Mutator m, String key, int by,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
class GetOperationImpl extends BaseGetOpImpl implements GetOperation {

private static final String CMD = "get";
private static final String CMD_MGET = "mget";

public GetOperationImpl(String key, GetOperation.Callback c) {
super(CMD, c, Collections.singleton(key));
Expand All @@ -26,4 +27,9 @@ public GetOperationImpl(Collection<String> k, GetOperation.Callback c) {
setAPIType(APIType.GET);
}

public GetOperationImpl(Collection<String> keys, GetOperation.Callback cb, boolean isMGet) {
super(isMGet ? CMD_MGET : CMD, cb, new HashSet<>(keys));
setAPIType(APIType.GET);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
class GetsOperationImpl extends BaseGetOpImpl implements GetsOperation {

private static final String CMD = "gets";
private static final String CMD_MGETS = "mgets";

public GetsOperationImpl(String key, GetsOperation.Callback cb) {
super(CMD, cb, Collections.singleton(key));
setAPIType(APIType.GETS);
}

public GetsOperationImpl(Collection<String> keys, GetsOperation.Callback cb) {
super(CMD, cb, new HashSet<>(keys));
public GetsOperationImpl(Collection<String> keys, GetsOperation.Callback cb, boolean isMGet) {
super(isMGet ? CMD_MGETS : CMD, cb, new HashSet<>(keys));
setAPIType(APIType.GETS);
}

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,17 @@ public GetOperation get(String key, Callback callback) {
return new GetOperationImpl(key, callback);
}

public GetOperation get(Collection<String> value, Callback cb) {
return new MultiGetOperationImpl(value, cb);
public GetOperation get(Collection<String> keys, Callback cb, boolean isMGet) {
return new MultiGetOperationImpl(keys, cb);
}

public GetsOperation gets(String key, GetsOperation.Callback cb) {
return new GetOperationImpl(key, cb);
}

public GetsOperation gets(Collection<String> keys, GetsOperation.Callback callback) {
public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMGet) {
throw new RuntimeException(
"gets is not supported in binary protocol yet.");
}

public GetOperation mget(Collection<String> keys, GetOperation.Callback cb) {
throw new RuntimeException(
"mget is not supported in binary protocol yet.");
}

public GetsOperation mgets(Collection<String> keys, GetsOperation.Callback cb) {
throw new RuntimeException(
"mgets is not supported in binary protocol yet.");
"multiple key gets is not supported in binary protocol yet.");
}

public MutatorOperation mutate(Mutator m, String key, int by,
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/net/spy/memcached/OperationFactoryTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ void testSingleGetsOperationCloning() {
void testMultipleGetOperationCloning() {
Collection<String> keys = Arrays.asList("k1", "k2", "k3");
GetOperation.Callback callback = context.mock(GetOperation.Callback.class);
GetOperation op = ofact.get(keys, callback);
GetOperation op = ofact.get(keys, callback, false);

Collection<Operation> ops = ofact.clone(op);
assertEquals(3, ops.size());
Expand Down Expand Up @@ -244,7 +244,7 @@ void testMultipleGetOperationFanout() {
e.oneOf(callback).gotData(e.with("k3"), e.with(3), e.with(any(byte[].class)));
}));

GetOperation op = ofact.get(keys, callback);
GetOperation op = ofact.get(keys, callback, false);

// Transition each operation callback into the complete state.
Iterator<String> ki = keys.iterator();
Expand All @@ -262,7 +262,7 @@ void testMultipleGetOperationFanout() {
public void testMultipleGetsOperationCloning() {
Collection<String> keys = Arrays.asList("k1", "k2", "k3");
GetsOperation.Callback callback = context.mock(GetsOperation.Callback.class);
GetsOperation op = ofact.gets(keys, callback);
GetsOperation op = ofact.gets(keys, callback, false);

Collection<Operation> ops = ofact.clone(op);
assertEquals(3, ops.size());
Expand Down Expand Up @@ -296,7 +296,7 @@ public void testMultipleGetsOperationFanout() {
e.with(casId[2]), e.with(any(byte[].class)));
}));

GetsOperation op = ofact.gets(keys, callback);
GetsOperation op = ofact.gets(keys, callback, false);

// Transition each operation callback into the complete state.
Iterator<String> ki = keys.iterator();
Expand Down