Commit 99e2fe64 authored by Yuqi Zhang's avatar Yuqi Zhang
Browse files

try to fix the not converge bug for list

at experiment compare setting, readd operation may add element not yet added, causing multiple leid for same element issue
parent e0daa748
......@@ -38,7 +38,7 @@ void list_generator::gen_and_exec(redis_client &c)
else if (rand <= PU)
{
string id = list.random_get();
if (id == "null") return c.add_pipeline_cmd(gen_insert());
if (id.empty()) return c.add_pipeline_cmd(gen_insert());
string upd_type;
int value;
switch (intRand(6))
......@@ -73,7 +73,7 @@ void list_generator::gen_and_exec(redis_client &c)
else
{
string id = list.random_get();
if (id == "null") return c.add_pipeline_cmd(gen_insert());
if (id.empty()) return c.add_pipeline_cmd(gen_insert());
c.add_pipeline_cmd(new list_remove_cmd(type, list, id));
}
}
......@@ -84,7 +84,7 @@ list_insert_cmd *list_generator::gen_insert()
string id_r = list.random_get_removed();
if (!id_r.empty())
{
string pre_t = "null", content_t = "NA";
string pre_t = "readd", content_t = "NA";
return new list_insert_cmd(type, list, pre_t, id_r, content_t, 0, 0, 0, false, false,
false);
}
......
......@@ -82,9 +82,9 @@ void list_log::insert(string &prev, string &name, string &content, int font, int
bool bold, bool italic, bool underline)
{
lock_guard<mutex> lk(mtx);
if (prev != "null" && ele_map.find(prev) == ele_map.end()) return;
if (prev != "null" && prev != "readd" && ele_map.find(prev) == ele_map.end()) return;
if (ele_map.find(name) != ele_map.end()) return;
auto it_next = prev == "null" ? document.begin() : ele_map[prev];
auto it_next = (prev == "null" || prev == "readd") ? document.begin() : ele_map[prev];
if (it_next != document.begin()) it_next++;
document.emplace(it_next, new element(content, font, size, color, bold, italic, underline));
it_next--;
......@@ -131,9 +131,9 @@ void list_log::remove(string &name)
string list_log::random_get()
{
lock_guard<mutex> lk(mtx);
if (ele_map.empty()) return string("null");
if (ele_map.empty()) return {};
int pos = intRand(ele_map.size() + 1); // NOLINT
if (pos == ele_map.size()) return string("null");
if (pos == ele_map.size()) return {};
auto random_it = next(begin(ele_map), pos);
return random_it->first;
}
......
......@@ -395,7 +395,7 @@ void rlinsertCommand(client *c)
if (pre == NULL)
{
sdstolower(c->argv[2]->ptr);
if (strcmp(c->argv[2]->ptr, "null") != 0)
if (strcmp(c->argv[2]->ptr, "null") != 0 && strcmp(c->argv[2]->ptr, "readd") != 0)
{
sds errs =
sdscatfmt(sdsempty(), "-No pre element %S in the list.\r\n", c->argv[2]->ptr);
......@@ -411,6 +411,14 @@ void rlinsertCommand(client *c)
}
if (e->oid == NULL)
{
if (strcmp(c->argv[2]->ptr, "readd") == 0)
{
sds errs = sdscatfmt(sdsempty(),
"-Element %S hasn't been added, can't be readded.\r\n",
c->argv[3]->ptr);
addReplySds(c, errs);
return;
}
leid *left = pre == NULL ? NULL : pre->pos_id;
leid *right;
if (pre == NULL)
......
......@@ -155,7 +155,7 @@ void rwflinsertCommand(client *c)
if (pre == NULL)
{
sdstolower(c->argv[2]->ptr);
if (strcmp(c->argv[2]->ptr, "null") != 0)
if (strcmp(c->argv[2]->ptr, "null") != 0 && strcmp(c->argv[2]->ptr, "readd") != 0)
{
sds errs =
sdscatfmt(sdsempty(), "-No pre element %S in the list.\r\n", c->argv[2]->ptr);
......@@ -167,6 +167,14 @@ void rwflinsertCommand(client *c)
PREPARE_PRECOND_ADD(e);
if (e->oid == NULL)
{
if (strcmp(c->argv[2]->ptr, "readd") == 0)
{
sds errs = sdscatfmt(sdsempty(),
"-Element %S hasn't been added, can't be readded.\r\n",
c->argv[3]->ptr);
addReplySds(c, errs);
return;
}
leid *left = pre == NULL ? NULL : pre->pos_id;
leid *right;
if (pre == NULL)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment