Skip to content

Commit

Permalink
INTERNAL: Integration get and mget api
Browse files Browse the repository at this point in the history
  • Loading branch information
cheesecrust committed Dec 30, 2024
1 parent c9473d9 commit f3577fd
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 124 deletions.
14 changes: 6 additions & 8 deletions src/main/java/net/spy/memcached/MemcachedClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ public void gotData(String k, int flags, byte[] data) {
public void complete() {
latch.countDown();
}
});
}, false);
future.setOperation(op);
addOp(key, op);
return future;
Expand Down Expand Up @@ -960,7 +960,7 @@ public void gotData(String k, int flags, long cas, byte[] data) {
public void complete() {
latch.countDown();
}
});
}, false);
rv.setOperation(op);
addOp(key, op);
return rv;
Expand Down Expand Up @@ -1103,10 +1103,9 @@ public void complete() {

Operation op;
if (node == null) {
op = opFact.mget(keyList, cb);
op = opFact.get(keyList, cb, true);
} 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, true);
} 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
30 changes: 8 additions & 22 deletions src/main/java/net/spy/memcached/OperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,55 +120,41 @@ public interface OperationFactory {
*
* @param key the key to get
* @param callback the callback that will contain the results
* @param isMget true if this is a multi-key get
* @return a new GetOperation
*/
GetOperation get(String key, GetOperation.Callback callback);
GetOperation get(String key, GetOperation.Callback callback, boolean isMget);

/**
* Create a gets operation.
*
* @param key the key to get
* @param callback the callback that will contain the results
* @param isMget true if this is a multi-key get
* @return a new GetsOperation
*/
GetsOperation gets(String key, GetsOperation.Callback callback);
GetsOperation gets(String key, GetsOperation.Callback callback, boolean isMget);


/**
* 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 this is a multi-key get
* @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 this is a multi-key get
* @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
8 changes: 4 additions & 4 deletions src/main/java/net/spy/memcached/ops/BaseOperationFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ public Collection<Operation> clone(KeyedOperation op) {
GetOperation.Callback getCb = new MultiGetOperationCallback(
op.getCallback(), op.getKeys().size());
for (String k : op.getKeys()) {
rv.add(get(k, getCb));
rv.add(get(k, getCb, false));
}
} else if (op instanceof GetsOperation) {
GetsOperation.Callback getsCb = new MultiGetsOperationCallback(
op.getCallback(), op.getKeys().size());
for (String k : op.getKeys()) {
rv.add(gets(k, getsCb));
rv.add(gets(k, getsCb, false));
}
} else if (op instanceof CASOperation) {
CASOperation cop = (CASOperation) op;
Expand Down Expand Up @@ -137,10 +137,10 @@ public Operation cloneMultiOperation(KeyedOperation op, MemcachedNode node,

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, true);
} 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, true);
} 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 @@ -81,6 +81,9 @@
import net.spy.memcached.ops.StoreType;
import net.spy.memcached.ops.VersionOperation;

import static net.spy.memcached.protocol.ascii.GetOperationImpl.generateGetOp;
import static net.spy.memcached.protocol.ascii.GetsOperationImpl.generateGetsOp;

/**
* Operation factory for the ascii protocol.
*/
Expand All @@ -94,28 +97,20 @@ public FlushOperation flush(int delay, OperationCallback cb) {
return new FlushOperationImpl(delay, cb);
}

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 GetsOperation gets(String key, GetsOperation.Callback cb) {
return new GetsOperationImpl(key, cb);
public GetOperation get(String key, GetOperation.Callback cb, boolean isMget) {
return generateGetOp(key, cb, isMget);
}

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

public GetOperation mget(Collection<String> keys, GetOperation.Callback cb) {
return new MGetOperationImpl(keys, cb);
public GetsOperation gets(String key, GetsOperation.Callback cb, boolean isMget) {
return generateGetsOp(key, cb, isMget);
}

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 generateGetsOp(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,15 +15,32 @@
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));
public GetOperationImpl(String key, GetOperation.Callback c, String command) {
super(command, c, Collections.singleton(key));
setAPIType(APIType.GET);
}

public GetOperationImpl(Collection<String> k, GetOperation.Callback c) {
super(CMD, c, new HashSet<>(k));
public GetOperationImpl(Collection<String> k, GetOperation.Callback c, String command) {
super(command, c, new HashSet<>(k));
setAPIType(APIType.GET);
}

public static GetOperationImpl generateGetOp(String key, GetOperation.Callback c,
boolean isMget) {
if (isMget) {
return new GetOperationImpl(key, c, CMD_MGET);
}
return new GetOperationImpl(key, c, CMD);
}

public static GetOperationImpl generateGetOp(Collection<String> keys, GetOperation.Callback c,
boolean isMget) {
if (isMget) {
return new GetOperationImpl(keys, c, CMD_MGET);
}
return new GetOperationImpl(keys, c, CMD);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,32 @@
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));
public GetsOperationImpl(String key, GetsOperation.Callback cb, String command) {
super(command, 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, String command) {
super(command, cb, new HashSet<>(keys));
setAPIType(APIType.GETS);
}

public static GetsOperationImpl generateGetsOp(String key, GetsOperation.Callback c,
boolean isMget) {
if (isMget) {
return new GetsOperationImpl(key, c, CMD_MGETS);
}
return new GetsOperationImpl(key, c, CMD);
}

public static GetsOperationImpl generateGetsOp(Collection<String> keys, GetsOperation.Callback c,
boolean isMget) {
if (isMget) {
return new GetsOperationImpl(keys, c, CMD_MGETS);
}
return new GetsOperationImpl(keys, c, CMD);
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
*/
final class OptimizedGetImpl extends GetOperationImpl {

private static final String CMD = "get";
private final ProxyCallback pcb;

/**
* Construct an optimized get starting with the given get operation.
*/
public OptimizedGetImpl(GetOperation firstGet) {
super(new HashSet<>(), new ProxyCallback());
super(new HashSet<>(), new ProxyCallback(), CMD);
pcb = (ProxyCallback) getCallback();
addOperation(firstGet);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,33 +96,39 @@ public FlushOperation flush(int delay, OperationCallback cb) {
return new FlushOperationImpl(cb);
}

public GetOperation get(String key, Callback callback) {
public GetOperation get(String key, Callback callback, boolean isMget) {
if (isMget) {
throw new RuntimeException(
"mget is not supported in binary protocol yet.");
}
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) {
if (isMget) {
throw new RuntimeException(
"mget is not supported in binary protocol yet.");
}
return new MultiGetOperationImpl(keys, cb);
}

public GetsOperation gets(String key, GetsOperation.Callback cb) {
return new GetOperationImpl(key, cb);
public GetsOperation gets(String key, GetsOperation.Callback callback, boolean isMget) {
if (isMget) {
throw new RuntimeException(
"mgets is not supported in binary protocol yet.");
}
return new GetOperationImpl(key, callback);
}

public GetsOperation gets(Collection<String> keys, GetsOperation.Callback callback) {
public GetsOperation gets(Collection<String> keys, GetsOperation.Callback cb, boolean isMget) {
if (isMget) {
throw new RuntimeException(
"mgets is not supported in binary protocol yet.");
}
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.");
}

public MutatorOperation mutate(Mutator m, String key, int by,
long def, int exp, OperationCallback cb) {
return new MutatorOperationImpl(m, key, by, def, exp, cb);
Expand Down
Loading

0 comments on commit f3577fd

Please sign in to comment.