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

change return type of cuckoo_insert #160

Merged
merged 1 commit into from
Apr 24, 2018
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
6 changes: 3 additions & 3 deletions src/server/slimcache/data/process.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ _process_set(struct response *rsp, struct request *req)
if (it != NULL) {
status = cuckoo_update(it, &val, expire);
} else {
status = cuckoo_insert(key, &val, expire);
it = cuckoo_insert(key, &val, expire);
}

if (status == CC_OK) {
if (it != NULL) {
rsp->type = RSP_STORED;
INCR(process_metrics, set_stored);
} else {
Expand All @@ -224,7 +224,7 @@ _process_add(struct response *rsp, struct request *req)
INCR(process_metrics, add_notstored);
} else {
_get_value(&val, &req->vstr);
if (cuckoo_insert(key, &val, time_reltime(req->expiry)) == CC_OK) {
if (cuckoo_insert(key, &val, time_reltime(req->expiry)) != NULL) {
rsp->type = RSP_STORED;
INCR(process_metrics, add_stored);
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/storage/cuckoo/cuckoo.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ cuckoo_get(struct bstring *key)
}

/* insert applies to a key that doesn't exist validly in our array */
rstatus_i
struct item *
cuckoo_insert(struct bstring *key, struct val *val, rel_time_t expire)
{
struct item *it;
Expand All @@ -354,7 +354,7 @@ cuckoo_insert(struct bstring *key, struct val *val, rel_time_t expire)
ITEM_OVERHEAD);
INCR(cuckoo_metrics, cuckoo_insert_ex);

return CC_ERROR;
return NULL;
}

cuckoo_hash(offset, key);
Expand Down Expand Up @@ -384,7 +384,7 @@ cuckoo_insert(struct bstring *key, struct val *val, rel_time_t expire)
INCR(cuckoo_metrics, item_insert);
ITEM_METRICS_INCR(it);

return CC_OK;
return it;
}

rstatus_i
Expand Down
2 changes: 1 addition & 1 deletion src/storage/cuckoo/cuckoo.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ void cuckoo_teardown(void);
void cuckoo_reset(void);

struct item * cuckoo_get(struct bstring *key);
rstatus_i cuckoo_insert(struct bstring *key, struct val *val, rel_time_t expire);
struct item * cuckoo_insert(struct bstring *key, struct val *val, rel_time_t expire);
rstatus_i cuckoo_update(struct item *it, struct val *val, rel_time_t expire);
bool cuckoo_delete(struct bstring *key);
51 changes: 18 additions & 33 deletions test/storage/cuckoo/check_cuckoo.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ test_insert_basic(uint32_t policy, bool cas)
#define VAL "value"
struct bstring key, testval;
struct val val;
rstatus_i status;
struct item *it;

test_reset(policy, cas);
Expand All @@ -71,9 +70,8 @@ test_insert_basic(uint32_t policy, bool cas)
val.vstr.len = sizeof(VAL) - 1;

time_update();
status = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
it = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(it != NULL, "cuckoo_insert not OK");

it = cuckoo_get(&key);
ck_assert_msg(it != NULL, "cuckoo_get returned NULL");
Expand All @@ -91,7 +89,6 @@ test_insert_collision(uint32_t policy, bool cas)
{
struct bstring key;
struct val val;
rstatus_i status;
struct item *it;
int hits = 0;
char keystring[CC_UINTMAX_MAXLEN];
Expand All @@ -107,9 +104,8 @@ test_insert_collision(uint32_t policy, bool cas)
val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
it = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(it != NULL, "cuckoo_insert not OK");
}

for (i = 0; i < CUCKOO_NITEM + 1; i++) {
Expand Down Expand Up @@ -152,9 +148,8 @@ test_cas(uint32_t policy)
val.vstr.len = sizeof(VAL) - 1;

time_update();
status = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
it = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(it != NULL, "cuckoo_insert not OK");

it = cuckoo_get(&key);
cas1 = item_cas(it);
Expand Down Expand Up @@ -183,7 +178,6 @@ test_delete_basic(uint32_t policy, bool cas)
#define VAL "value"
struct bstring key;
struct val val;
rstatus_i status;
struct item *it;
bool deleted;

Expand All @@ -197,9 +191,8 @@ test_delete_basic(uint32_t policy, bool cas)
val.vstr.len = sizeof(VAL) - 1;

time_update();
status = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
it = cuckoo_insert(&key, &val, UINT32_MAX - 1);
ck_assert_msg(it != NULL, "cuckoo_insert not OK");

it = cuckoo_get(&key);
ck_assert_msg(it != NULL, "cuckoo_get returned NULL");
Expand All @@ -224,7 +217,6 @@ test_expire_basic(uint32_t policy, bool cas)
#define NOW 12345678
struct bstring key;
struct val val;
rstatus_i status;
struct item *it;

test_reset(policy, cas);
Expand All @@ -237,9 +229,8 @@ test_expire_basic(uint32_t policy, bool cas)
val.vstr.len = sizeof(VAL) - 1;

now = NOW;
status = cuckoo_insert(&key, &val, NOW + 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
it = cuckoo_insert(&key, &val, NOW + 1);
ck_assert_msg(it != NULL, "cuckoo_insert not OK");

it = cuckoo_get(&key);
ck_assert_msg(it != NULL, "cuckoo_get returned NULL");
Expand Down Expand Up @@ -331,7 +322,6 @@ START_TEST(test_insert_replace_expired)

struct bstring key;
struct val val;
rstatus_i status;
char keystring[30];
uint64_t i;

Expand All @@ -346,9 +336,8 @@ START_TEST(test_insert_replace_expired)
val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
ck_assert_msg(cuckoo_insert(&key, &val, now + 1) != NULL,
"cuckoo_insert not OK");
}

// dict is full, all items will expire in now + 1
Expand All @@ -359,9 +348,8 @@ START_TEST(test_insert_replace_expired)
val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + 1);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
ck_assert_msg(cuckoo_insert(&key, &val, now + 1) != NULL,
"cuckoo_insert failed");
ck_assert_int_eq(metrics.item_expire.counter, 1);
#undef NOW
}
Expand All @@ -372,7 +360,6 @@ START_TEST(test_insert_insert_expire_swap)
#define NOW 12345678
struct bstring key;
struct val val;
rstatus_i status;
char keystring[30];
uint64_t i;
int hits = 0;
Expand All @@ -388,9 +375,8 @@ START_TEST(test_insert_insert_expire_swap)
val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + i);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
ck_assert_msg(cuckoo_insert(&key, &val, now + i) != NULL,
"cuckoo_insert not OK");
}

key.len = sprintf(keystring, "%"PRIu64, i);
Expand All @@ -399,9 +385,8 @@ START_TEST(test_insert_insert_expire_swap)
val.type = VAL_TYPE_INT;
val.vint = i;

status = cuckoo_insert(&key, &val, now + i);
ck_assert_msg(status == CC_OK, "cuckoo_insert not OK - return status %d",
status);
ck_assert_msg(cuckoo_insert(&key, &val, now + i) != NULL,
"cuckoo_insert not OK");

for (;i > 0 && hits < CUCKOO_NITEM;i--) {
if (cuckoo_get(&key) != NULL) {
Expand Down