Permalink
Browse files

added --key-prefix feature on kumo-gateway

  • Loading branch information...
1 parent 78879b5 commit a224108c2e330a0581f981a5cd33fbb7ab35dda1 @frsyuki frsyuki committed Dec 13, 2010
View
@@ -273,7 +273,6 @@ void request_getx(void* user,
gate::req_get req;
req.keylen = keylen;
req.key = key;
- req.hash = kumo::gate::stdhash(req.key, req.keylen);
req.user = static_cast<void*>(e);
req.callback = &response_getx;
req.life = life;
@@ -304,7 +303,6 @@ void request_set(void* user,
req.key = key;
req.vallen = vallen;
req.val = val;
- req.hash = kumo::gate::stdhash(req.key, req.keylen);
req.user = static_cast<void*>(e);
req.callback = &response_set;
req.life = life;
@@ -332,7 +330,6 @@ void request_delete(void* user,
gate::req_delete req;
req.key = key;
req.keylen = keylen;
- req.hash = kumo::gate::stdhash(req.key, req.keylen);
req.user = static_cast<void*>(e);
req.callback = &response_delete;
req.life = life;
View
@@ -49,6 +49,7 @@ struct res_get {
int error;
const char* key;
uint32_t keylen;
+
uint64_t hash;
char* val;
@@ -59,11 +60,13 @@ struct res_get {
typedef void (*callback_get)(void* user, res_get& res, auto_zone z);
struct req_get {
- req_get() { }
+ req_get() : has_user_hash(false) { }
const char* key;
uint32_t keylen;
- uint64_t hash;
+
+ bool has_user_hash;
+ uint64_t user_hash;
shared_zone life;
callback_get callback;
@@ -87,6 +90,7 @@ struct res_set {
const char* key;
uint32_t keylen;
+
uint64_t hash;
const char* val;
@@ -99,11 +103,13 @@ struct res_set {
typedef void (*callback_set)(void* user, res_set& res, auto_zone z);
struct req_set {
- req_set() : operation(OP_SET) { }
+ req_set() : has_user_hash(false), operation(OP_SET) { }
const char* key;
uint32_t keylen;
- uint64_t hash;
+
+ bool has_user_hash;
+ uint64_t user_hash;
const char* val;
uint32_t vallen;
@@ -124,6 +130,7 @@ struct res_delete {
const char* key;
uint32_t keylen;
+
uint64_t hash;
bool deleted;
@@ -132,11 +139,13 @@ struct res_delete {
typedef void (*callback_delete)(void* user, res_delete& res, auto_zone z);
struct req_delete {
- req_delete() : async(false) { }
+ req_delete() : has_user_hash(false), async(false) { }
const char* key;
uint32_t keylen;
- uint64_t hash;
+
+ bool has_user_hash;
+ uint64_t user_hash;
bool async;
@@ -559,7 +559,6 @@ void handler::request_getx(memproto_header* h,
gate::req_get req;
req.keylen = keylen;
req.key = key;
- req.hash = gate::stdhash(req.key, req.keylen);
req.user = reinterpret_cast<void*>(e);
req.callback = &handler::response_getx;
req.life = life;
@@ -625,7 +624,6 @@ void handler::request_set(memproto_header* h,
req.key = key;
req.vallen = vallen;
req.val = val;
- req.hash = gate::stdhash(req.key, req.keylen);
req.user = reinterpret_cast<void*>(e);
req.callback = &handler::response_set;
req.life = life;
@@ -658,7 +656,6 @@ void handler::request_delete(memproto_header* h,
gate::req_delete req;
req.key = key;
req.keylen = keylen;
- req.hash = gate::stdhash(req.key, req.keylen);
req.user = reinterpret_cast<void*>(e);
req.callback = &handler::response_delete;
req.life = life;
@@ -429,7 +429,6 @@ int request_get_single(void* user,
gate::req_get req;
req.keylen = key_len;
req.key = key;
- req.hash = gate::stdhash(req.key, req.keylen);
req.user = reinterpret_cast<void*>(e);
req.callback = &response_get;
req.life = life;
@@ -483,7 +482,6 @@ int request_get_multi(void* user,
req.keylen = r->key_len[i];
req.key = r->key[i];
req.user = reinterpret_cast<void*>(me[i]);
- req.hash = gate::stdhash(req.key, req.keylen);
req.callback = &response_get_multi;
req.life = life;
@@ -563,7 +561,6 @@ int request_set_impl(void* user,
req.key = r->key;
req.vallen = r->data_len;
req.val = r->data;
- req.hash = gate::stdhash(req.key, req.keylen);
req.user = reinterpret_cast<void*>(e);
req.life = life;
if(r->noreply) {
@@ -635,7 +632,6 @@ int request_delete(void* user,
gate::req_delete req;
req.key = r->key;
req.keylen = r->key_len;
- req.hash = gate::stdhash(req.key, req.keylen);
req.user = reinterpret_cast<void*>(e);
if(r->noreply) {
req.async = true;
@@ -82,6 +82,8 @@ class resource {
unsigned short m_error_count;
+ std::string m_cfg_key_prefix;
+
public:
// mod_store.cc
void incr_error_renew_count();
@@ -114,6 +116,8 @@ class resource {
RESOURCE_CONST_ACCESSOR(unsigned short, cfg_renew_threshold);
+ RESOURCE_CONST_ACCESSOR(std::string, cfg_key_prefix);
+
private:
resource();
resource(const resource&);
View
@@ -57,6 +57,7 @@ resource::resource(const Config& cfg) :
m_cfg_set_retry_num(cfg.set_retry_num),
m_cfg_delete_retry_num(cfg.delete_retry_num),
m_cfg_renew_threshold(cfg.renew_threshold),
+ m_cfg_key_prefix(cfg.key_prefix),
m_error_count(0)
{ }
@@ -62,6 +62,8 @@ struct arg_t : rpc_args {
bool mc_save_flag;
bool mc_save_exptime;
+ std::string key_prefix;
+
virtual void convert()
{
rpc_args::convert();
@@ -119,6 +121,8 @@ struct arg_t : rpc_args {
type::boolean(&async_replicate_set));
on("-Ad", "--async-replicate-delete",
type::boolean(&async_replicate_delete));
+ on("-k", "--key-prefix",
+ type::string(&key_prefix, ""));
parse(argc, argv);
}
@@ -158,6 +162,8 @@ struct arg_t : rpc_args {
"--delete-retry delete retry limit\n"
" -rn <number="<<renew_threshold<<"> "
"--renew-threshold hash space renew threshold\n"
+ " -k <string> "
+ "--key-prefix add prefix to keys automatically\n"
;
rpc_args::show_usage();
}
Oops, something went wrong.

0 comments on commit a224108

Please sign in to comment.