Point read/write workload for server_bench
This commit is contained in:
@@ -64,31 +64,47 @@ template <class... Ts> std::string tupleKey(const Ts &...ts) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr int kWindowSize = 300000;
|
constexpr int kTotalKeyRange = 1'000'000'000;
|
||||||
|
constexpr int kWindowSize = 1'000'000;
|
||||||
|
constexpr int kNumKeys = 10;
|
||||||
|
|
||||||
void workload(weaselab::ConflictSet *cs) {
|
void workload(weaselab::ConflictSet *cs) {
|
||||||
int64_t version = kWindowSize;
|
int64_t version = kWindowSize;
|
||||||
constexpr int kNumWrites = 16;
|
|
||||||
for (;; transactions.fetch_add(1, std::memory_order_relaxed)) {
|
for (;; transactions.fetch_add(1, std::memory_order_relaxed)) {
|
||||||
std::vector<int64_t> keyIndices;
|
std::vector<int64_t> keyIndices;
|
||||||
for (int i = 0; i < kNumWrites; ++i) {
|
for (int i = 0; i < kNumKeys; ++i) {
|
||||||
keyIndices.push_back(rand() % 100'000'000);
|
keyIndices.push_back(rand() % kTotalKeyRange);
|
||||||
}
|
}
|
||||||
std::sort(keyIndices.begin(), keyIndices.end());
|
std::sort(keyIndices.begin(), keyIndices.end());
|
||||||
std::vector<std::string> keys;
|
std::vector<std::string> keys;
|
||||||
std::vector<weaselab::ConflictSet::WriteRange> writes;
|
constexpr std::string_view fullString =
|
||||||
constexpr std::string_view suffix = "this is a suffix";
|
"this is a string, where a prefix of it is used as an element of the "
|
||||||
for (int i = 0; i < kNumWrites; ++i) {
|
"tuple forming the key";
|
||||||
keys.push_back(tupleKey(0x100, i, keyIndices[i],
|
for (int i = 0; i < kNumKeys; ++i) {
|
||||||
suffix.substr(0, rand() % suffix.size()),
|
keys.push_back(
|
||||||
rand()));
|
tupleKey(0x100, keyIndices[i] / fullString.size(),
|
||||||
|
fullString.substr(0, keyIndices[i] % fullString.size())));
|
||||||
// printf("%s\n", printable(keys.back()).c_str());
|
// printf("%s\n", printable(keys.back()).c_str());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < kNumWrites; ++i) {
|
|
||||||
|
std::vector<weaselab::ConflictSet::ReadRange> reads;
|
||||||
|
std::vector<weaselab::ConflictSet::WriteRange> writes;
|
||||||
|
std::vector<weaselab::ConflictSet::Result> results;
|
||||||
|
for (int i = 0; i < kNumKeys; ++i) {
|
||||||
writes.push_back({{(const uint8_t *)keys[i].data(), int(keys[i].size())},
|
writes.push_back({{(const uint8_t *)keys[i].data(), int(keys[i].size())},
|
||||||
{nullptr, 0}});
|
{nullptr, 0}});
|
||||||
|
reads.push_back({{(const uint8_t *)keys[i].data(), int(keys[i].size())},
|
||||||
|
{nullptr, 0},
|
||||||
|
version - kWindowSize});
|
||||||
}
|
}
|
||||||
cs->addWrites(writes.data(), writes.size(), version);
|
results.resize(reads.size());
|
||||||
|
|
||||||
|
cs->check(reads.data(), results.data(), reads.size());
|
||||||
|
bool ok = true;
|
||||||
|
for (auto result : results) {
|
||||||
|
ok &= result == weaselab::ConflictSet::Commit;
|
||||||
|
}
|
||||||
|
cs->addWrites(writes.data(), ok ? writes.size() : 0, version);
|
||||||
cs->setOldestVersion(version - kWindowSize);
|
cs->setOldestVersion(version - kWindowSize);
|
||||||
++version;
|
++version;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user