Permalink
Browse files

evict key command

This allows for explicit eviction of the body of an item from its key.
Useful for testing fetching from disk.

Change-Id: I600ba04448da20636985ca55f168a0b5a6a9b36d
Reviewed-on: http://review.northscale.com/1056
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information...
1 parent bf3aeaa commit 98f92f9fdf26958cf695b007dd86933649805e9f @dustin dustin committed with trondn Jul 7, 2010
Showing with 76 additions and 1 deletion.
  1. +1 −0 command_ids.h
  2. +29 −0 ep.cc
  3. +4 −0 ep.hh
  4. +31 −0 ep_engine.cc
  5. +6 −0 ep_engine.h
  6. +1 −0 management/flushctl.py
  7. +3 −0 management/mc_bin_client.py
  8. +1 −1 management/memcacheConstants.py
View
@@ -11,5 +11,6 @@
#define CMD_START_REPLICATION 0x90
#define CMD_STOP_REPLICATION 0x91
#define CMD_SET_TAP_PARAM 0x92
+#define CMD_EVICT_KEY 0x93
#endif /* COMMAND_IDS_H */
View
29 ep.cc
@@ -182,6 +182,35 @@ RCPtr<VBucket> EventuallyPersistentStore::getVBucket(uint16_t vbid,
}
}
+protocol_binary_response_status EventuallyPersistentStore::evictKey(const std::string &key,
+ uint16_t vbucket,
+ const char **msg) {
+ RCPtr<VBucket> vb = getVBucket(vbucket);
+ if (!(vb && vb->getState() == active)) {
+ return PROTOCOL_BINARY_RESPONSE_NOT_MY_VBUCKET;
+ }
+
+ int bucket_num = vb->ht.bucket(key);
+ LockHolder lh(vb->ht.getMutex(bucket_num));
+ StoredValue *v = vb->ht.unlocked_find(key, bucket_num);
+
+ protocol_binary_response_status rv(PROTOCOL_BINARY_RESPONSE_SUCCESS);
+
+ if (v) {
+ if (v->isResident()) {
+ v->ejectValue();
+ *msg = "Ejected.";
+ } else {
+ *msg = "Already ejected.";
+ }
+ } else {
+ *msg = "Not found.";
+ rv = PROTOCOL_BINARY_RESPONSE_KEY_ENOENT;
+ }
+
+ return rv;
+}
+
ENGINE_ERROR_CODE EventuallyPersistentStore::set(const Item &item,
const void *cookie,
bool force) {
View
4 ep.hh
@@ -169,6 +169,10 @@ public:
assert(false);
}
+ protocol_binary_response_status evictKey(const std::string &key,
+ uint16_t vbucket,
+ const char **msg);
+
ENGINE_ERROR_CODE del(const std::string &key, uint16_t vbucket,
const void *cookie);
View
@@ -216,6 +216,34 @@ extern "C" {
return rv;
}
+ static protocol_binary_response_status evictKey(EventuallyPersistentEngine *e,
+ protocol_binary_request_header *request,
+ const char **msg) {
+ protocol_binary_request_no_extras *req =
+ (protocol_binary_request_no_extras*)request;
+
+ char keyz[256];
+
+ // Read the key.
+ int keylen = ntohs(req->message.header.request.keylen);
+ if (keylen >= (int)sizeof(keyz)) {
+ *msg = "Key is too large.";
+ return PROTOCOL_BINARY_RESPONSE_EINVAL;
+ }
+ memcpy(keyz, ((char*)request) + sizeof(req->message.header), keylen);
+ keyz[keylen] = 0x00;
+
+ uint16_t vbucket = ntohs(request->request.vbucket);
+
+ std::string key(keyz, keylen);
+
+ getLogger()->log(EXTENSION_LOG_DEBUG, NULL,
+ "Manually evicting object with key %s\n",
+ keyz);
+
+ return e->evictKey(key, vbucket, msg);
+ }
+
static protocol_binary_response_status setParam(EventuallyPersistentEngine *e,
protocol_binary_request_header *request,
const char **msg) {
@@ -455,6 +483,9 @@ extern "C" {
case CMD_SET_VBUCKET:
res = setVbucket(h, request, &msg);
break;
+ case CMD_EVICT_KEY:
+ res = evictKey(h, request, &msg);
+ break;
default:
/* unknown command */
handled = false;
View
@@ -1309,6 +1309,12 @@ class EventuallyPersistentEngine : public ENGINE_HANDLE_V1 {
return false;
}
+ protocol_binary_response_status evictKey(const std::string &key,
+ uint16_t vbucket,
+ const char **msg) {
+ return epstore->evictKey(key, vbucket, msg);
+ }
+
void setTapPeer(std::string peer) {
tapConnect(peer);
}
View
@@ -27,5 +27,6 @@ def stop(mc):
c.addCommand('stop', stop)
c.addCommand('start', 'start_persistence')
c.addCommand('set', 'set_flush_param', 'set param value')
+ c.addCommand('evict', 'evict_key', "evict key")
c.execute()
@@ -196,6 +196,9 @@ def set_vbucket_state(self, vbucket, state):
def delete_vbucket(self, vbucket):
return self._doCmd(memcacheConstants.CMD_DELETE_VBUCKET, str(vbucket), '')
+ def evict_key(self, key):
+ return self._doCmd(memcacheConstants.CMD_EVICT_KEY, key, '')
+
def getMulti(self, keys):
"""Get values for any available keys in the given iterable.
@@ -41,7 +41,7 @@
CMD_START_REPLICATION = 0x90
CMD_STOP_REPLICATION = 0x91
CMD_SET_TAP_PARAM = 0x92
-
+CMD_EVICT_KEY = 0x93
# Replication
CMD_TAP_CONNECT = 0x40

0 comments on commit 98f92f9

Please sign in to comment.