-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
List based on ziplist (create/delete implemented in this diff) (#170)
* adding list interface * List.create works * adding List.delete impl * revert some merge errors
- Loading branch information
Yao Yue
authored
Jun 25, 2018
1 parent
ac2b9bf
commit 17b7635
Showing
13 changed files
with
201 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#pragma once | ||
|
||
/** | ||
* create: create an empty list | ||
* List.create KEY | ||
* | ||
* delete: delete a list or a particular value from list | ||
* List.delete KEY [VALUE [COUNT]] | ||
* | ||
* trim: trimming a list | ||
* List.trim KEY INDEX [COUNT] | ||
* | ||
* len: return number of entries in list | ||
* List.len KEY | ||
* | ||
* find: find entry in list | ||
* List.find KEY VALUE | ||
* | ||
* get: get entry/entries at an index | ||
* List.get KEY [INDEX [COUNT]] | ||
* | ||
* insert: insert entry at an index | ||
* List.insert KEY VALUE INDEX | ||
* | ||
* push: pushing entry/entries at the end | ||
* List.push KEY VALUE [VALUE ...] | ||
*/ | ||
|
||
|
||
/* type string #arg #opt */ | ||
#define REQ_LIST(ACTION) \ | ||
ACTION( REQ_LIST_CREATE, "List.create", 2, 0 )\ | ||
ACTION( REQ_LIST_DELETE, "List.delete", 2, 2 )\ | ||
ACTION( REQ_LIST_TRIM, "List.trim", 4, 0 )\ | ||
ACTION( REQ_LIST_LEN, "List.len", 2, 0 )\ | ||
ACTION( REQ_LIST_FIND, "List.find", 3, 0 )\ | ||
ACTION( REQ_LIST_GET, "List.get", 2, 2 )\ | ||
ACTION( REQ_LIST_INSERT, "List.insert", 4, 0 )\ | ||
ACTION( REQ_LIST_PUSH, "List.push", 3, -1 ) | ||
|
||
typedef enum list_elem { | ||
LIST_VERB = 0, | ||
LIST_KEY = 1, | ||
LIST_VAL = 2, | ||
LIST_IDX = 2, | ||
LIST_VIDX = 3, /* when a value is also present */ | ||
LIST_CNT = 3, | ||
} list_elem_e; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ set(SOURCE | |
|
||
set(MODULES | ||
core | ||
ds_bitmap | ||
ds_ziplist | ||
protocol_admin | ||
protocol_redis | ||
slab | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#include "process.h" | ||
|
||
#include "data_structure/ziplist/ziplist.h" | ||
#include "protocol/data/redis_include.h" | ||
#include "storage/slab/item.h" | ||
#include "storage/slab/slab.h" | ||
|
||
#include <cc_array.h> | ||
#include <cc_bstring.h> | ||
#include <cc_debug.h> | ||
|
||
|
||
static inline struct bstring * | ||
_get_key(struct request *req) | ||
{ | ||
struct element *key = (struct element *)array_get(req->token, LIST_KEY); | ||
|
||
return &key->bstr; | ||
} | ||
|
||
static inline struct item * | ||
_add_key(struct response *rsp, struct bstring *key) | ||
{ | ||
struct element *reply = (struct element *)array_get(rsp->token, 0); | ||
struct item *it; | ||
item_rstatus_t istatus; | ||
|
||
it = item_get(key); | ||
if (it != NULL) { | ||
rsp->type = reply->type = ELEM_ERR; | ||
reply->bstr = str2bstr(RSP_EXIST); | ||
INCR(process_metrics, list_create_exist); | ||
|
||
return NULL; | ||
} else { | ||
/* TODO: figure out a TTL story here */ | ||
istatus = item_reserve(&it, key, NULL, ZIPLIST_HEADER_SIZE, 0, UINT32_MAX); | ||
if (istatus != ITEM_OK) { | ||
rsp->type = reply->type = ELEM_ERR; | ||
reply->bstr = str2bstr(RSP_ERR_STORAGE); | ||
INCR(process_metrics, list_create_ex); | ||
INCR(process_metrics, process_ex); | ||
} else { | ||
INCR(process_metrics, list_create_stored); | ||
} | ||
|
||
return it; | ||
} | ||
} | ||
|
||
|
||
void | ||
cmd_list_create(struct response *rsp, struct request *req, struct command *cmd) | ||
{ | ||
struct item *it; | ||
struct bstring *key = _get_key(req); | ||
struct element *reply = (struct element *)array_push(rsp->token); | ||
|
||
INCR(process_metrics, list_create); | ||
|
||
it = _add_key(rsp, key); | ||
if (it == NULL) { | ||
log_debug("command '%.*s' '%.*s' failed: cannot store", cmd->bstr.len, | ||
cmd->bstr.data, key->len, key->data); | ||
return; | ||
} | ||
|
||
/* initialize data structure */ | ||
ziplist_reset((ziplist_p)item_data(it)); | ||
it->vlen = ZIPLIST_HEADER_SIZE; | ||
|
||
/* link into index */ | ||
item_insert(it, key); | ||
|
||
rsp->type = reply->type = ELEM_STR; | ||
reply->bstr = str2bstr(RSP_OK); | ||
|
||
log_verb("command '%.*s' '%.*s' succeeded", cmd->bstr.len, cmd->bstr.data, | ||
key->len, key->data); | ||
} | ||
|
||
void | ||
cmd_list_delete(struct response *rsp, struct request *req, struct command *cmd) | ||
{ | ||
struct bstring *key = _get_key(req); | ||
struct element *reply = (struct element *)array_push(rsp->token); | ||
|
||
INCR(process_metrics, list_delete); | ||
|
||
if (item_delete(key)) { | ||
reply->bstr = str2bstr(RSP_OK); | ||
INCR(process_metrics, list_delete_deleted); | ||
log_verb("command '%.*s' '%.*s' succeeded", cmd->bstr.len, | ||
cmd->bstr.data, key->len, key->data); | ||
} else { | ||
reply->bstr = str2bstr(RSP_NOTFOUND); | ||
INCR(process_metrics, list_delete_notfound); | ||
log_verb("command '%.*s' '%.*s' completed as no-op, key not found", | ||
cmd->bstr.len, cmd->bstr.data, key->len, key->data); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
/* name type description */ | ||
#define PROCESS_LIST_METRIC(ACTION) \ | ||
ACTION( list_create, METRIC_COUNTER, "# list create requests" )\ | ||
ACTION( list_create_exist, METRIC_COUNTER, "# list already exist" )\ | ||
ACTION( list_create_stored, METRIC_COUNTER, "# list stored" )\ | ||
ACTION( list_create_ex, METRIC_COUNTER, "# list create exceptions" )\ | ||
ACTION( list_delete, METRIC_COUNTER, "# list delete requests" )\ | ||
ACTION( list_delete_deleted, METRIC_COUNTER, "# list delete success" )\ | ||
ACTION( list_delete_notfound, METRIC_COUNTER, "# list delete success" )\ | ||
ACTION( list_trim, METRIC_COUNTER, "# list trim requests" )\ | ||
ACTION( list_len, METRIC_COUNTER, "# list length requests" )\ | ||
ACTION( list_find, METRIC_COUNTER, "# list find requests" )\ | ||
ACTION( list_get, METRIC_COUNTER, "# list get requests" )\ | ||
ACTION( list_insert, METRIC_COUNTER, "# list insert requests" )\ | ||
ACTION( list_push, METRIC_COUNTER, "# list push requests" ) | ||
|
||
struct request; | ||
struct response; | ||
struct command; | ||
|
||
/* cmd_* functions must be command_fn (process.c) compatible */ | ||
void cmd_list_create(struct response *rsp, struct request *req, struct command *cmd); | ||
void cmd_list_delete(struct response *rsp, struct request *req, struct command *cmd); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters