Commit 878b43a2 authored by Yuqi Zhang's avatar Yuqi Zhang
Browse files

list can add previously remove element at cmp mode

parent 5da8e0bd
......@@ -79,6 +79,16 @@ void list_generator::gen_and_exec(redis_client &c)
}
list_insert_cmd *list_generator::gen_insert()
{
if (exp_setting::compare && decide() < 0.5)
{
string id_r = list.random_get_removed();
if (!id_r.empty())
{
string pre_t = "null", content_t = "NA";
return new list_insert_cmd(type, list, pre_t, id_r, content_t, 0, 0, 0, false, false,
false);
}
}
string prev = list.random_get(), id = new_id.get(), content = strRand();
int font = intRand(TOTAL_FONT_TYPE), size = intRand(MAX_FONT_SIZE), color = intRand(MAX_COLOR);
bool bold = boolRand(), italic = boolRand(), underline = boolRand();
......
......@@ -89,6 +89,7 @@ void list_log::insert(string &prev, string &name, string &content, int font, int
document.emplace(it_next, new element(content, font, size, color, bold, italic, underline));
it_next--;
ele_map[name] = it_next;
if (ele_removed.find(name) != ele_removed.end()) ele_removed.erase(name);
write_op_executed++;
}
......@@ -122,6 +123,7 @@ void list_log::remove(string &name)
auto &e = ele_map[name];
document.erase(e);
ele_map.erase(name);
ele_removed.insert(name);
}
write_op_executed++;
}
......@@ -136,6 +138,14 @@ string list_log::random_get()
return random_it->first;
}
string list_log::random_get_removed()
{
if (ele_removed.empty()) return {};
int pos = intRand(ele_removed.size()); // NOLINT
auto random_it = next(begin(ele_removed), pos);
return *random_it;
}
void list_log::log_compare(redisReply_ptr &r1, redisReply_ptr &r2)
{
int len1 = r1->elements;
......
......@@ -6,6 +6,7 @@
#define BENCH_LIST_LOG_H
#include <mutex>
#include <set>
#include <unordered_map>
#include "../util.h"
......@@ -41,6 +42,7 @@ private:
static double diff(const element &e, const redisReply *r);
set<string> ele_removed;
unordered_map<string, list<unique_ptr<element>>::iterator> ele_map;
list<unique_ptr<element>> document;
......@@ -56,6 +58,8 @@ public:
string random_get();
string random_get_removed();
void insert(string &prev, string &name, string &content, int font, int size, int color,
bool bold, bool italic, bool underline);
......
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