2016-03-03 20:20:25 +01:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-16 01:03:42 +02:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2016-03-03 20:20:25 +01:00
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
|
|
|
|
#ifndef __STDC_FORMAT_MACROS
|
|
|
|
#define __STDC_FORMAT_MACROS
|
|
|
|
#endif
|
|
|
|
|
2019-05-30 20:21:38 +02:00
|
|
|
#include "test_util/transaction_test_util.h"
|
2016-03-03 20:20:25 +01:00
|
|
|
|
|
|
|
#include <inttypes.h>
|
2017-12-06 18:32:09 +01:00
|
|
|
#include <algorithm>
|
|
|
|
#include <numeric>
|
2018-10-11 19:48:12 +02:00
|
|
|
#include <random>
|
2016-03-03 20:20:25 +01:00
|
|
|
#include <string>
|
2017-06-24 23:06:43 +02:00
|
|
|
#include <thread>
|
2016-03-03 20:20:25 +01:00
|
|
|
|
|
|
|
#include "rocksdb/db.h"
|
|
|
|
#include "rocksdb/utilities/optimistic_transaction_db.h"
|
|
|
|
#include "rocksdb/utilities/transaction.h"
|
|
|
|
#include "rocksdb/utilities/transaction_db.h"
|
2019-02-12 00:59:30 +01:00
|
|
|
|
|
|
|
#include "db/dbformat.h"
|
|
|
|
#include "db/snapshot_impl.h"
|
2019-06-01 02:19:43 +02:00
|
|
|
#include "logging/logging.h"
|
2016-03-03 20:20:25 +01:00
|
|
|
#include "util/random.h"
|
|
|
|
#include "util/string_util.h"
|
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
RandomTransactionInserter::RandomTransactionInserter(
|
|
|
|
Random64* rand, const WriteOptions& write_options,
|
2019-02-12 00:59:30 +01:00
|
|
|
const ReadOptions& read_options, uint64_t num_keys, uint16_t num_sets,
|
|
|
|
const uint64_t cmt_delay_ms, const uint64_t first_id)
|
2016-03-03 20:20:25 +01:00
|
|
|
: rand_(rand),
|
|
|
|
write_options_(write_options),
|
|
|
|
read_options_(read_options),
|
|
|
|
num_keys_(num_keys),
|
2017-07-08 03:18:45 +02:00
|
|
|
num_sets_(num_sets),
|
2019-02-12 00:59:30 +01:00
|
|
|
txn_id_(first_id),
|
|
|
|
cmt_delay_ms_(cmt_delay_ms) {}
|
2016-03-03 20:20:25 +01:00
|
|
|
|
|
|
|
RandomTransactionInserter::~RandomTransactionInserter() {
|
|
|
|
if (txn_ != nullptr) {
|
|
|
|
delete txn_;
|
|
|
|
}
|
|
|
|
if (optimistic_txn_ != nullptr) {
|
|
|
|
delete optimistic_txn_;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool RandomTransactionInserter::TransactionDBInsert(
|
|
|
|
TransactionDB* db, const TransactionOptions& txn_options) {
|
|
|
|
txn_ = db->BeginTransaction(write_options_, txn_options, txn_);
|
2018-07-24 09:09:18 +02:00
|
|
|
|
|
|
|
std::hash<std::thread::id> hasher;
|
|
|
|
char name[64];
|
2019-02-12 00:59:30 +01:00
|
|
|
snprintf(name, 64, "txn%" ROCKSDB_PRIszt "-%" PRIu64,
|
2018-07-24 09:09:18 +02:00
|
|
|
hasher(std::this_thread::get_id()), txn_id_++);
|
|
|
|
assert(strlen(name) < 64 - 1);
|
2019-02-12 00:59:30 +01:00
|
|
|
assert(txn_->SetName(name).ok());
|
2018-07-24 09:09:18 +02:00
|
|
|
|
2019-02-12 00:59:30 +01:00
|
|
|
// Take a snapshot if set_snapshot was not set or with 50% change otherwise
|
|
|
|
bool take_snapshot = txn_->GetSnapshot() == nullptr || rand_->OneIn(2);
|
2017-12-06 18:32:09 +01:00
|
|
|
if (take_snapshot) {
|
|
|
|
txn_->SetSnapshot();
|
|
|
|
read_options_.snapshot = txn_->GetSnapshot();
|
|
|
|
}
|
2019-02-12 00:59:30 +01:00
|
|
|
auto res = DoInsert(db, txn_, false);
|
2017-12-06 18:32:09 +01:00
|
|
|
if (take_snapshot) {
|
|
|
|
read_options_.snapshot = nullptr;
|
|
|
|
}
|
|
|
|
return res;
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RandomTransactionInserter::OptimisticTransactionDBInsert(
|
|
|
|
OptimisticTransactionDB* db,
|
|
|
|
const OptimisticTransactionOptions& txn_options) {
|
|
|
|
optimistic_txn_ =
|
|
|
|
db->BeginTransaction(write_options_, txn_options, optimistic_txn_);
|
|
|
|
|
2019-02-12 00:59:30 +01:00
|
|
|
return DoInsert(db, optimistic_txn_, true);
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
bool RandomTransactionInserter::DBInsert(DB* db) {
|
|
|
|
return DoInsert(db, nullptr, false);
|
|
|
|
}
|
|
|
|
|
2017-12-06 18:32:09 +01:00
|
|
|
Status RandomTransactionInserter::DBGet(
|
|
|
|
DB* db, Transaction* txn, ReadOptions& read_options, uint16_t set_i,
|
|
|
|
uint64_t ikey, bool get_for_update, uint64_t* int_value,
|
|
|
|
std::string* full_key, bool* unexpected_error) {
|
|
|
|
Status s;
|
FIXED: string buffers potentially too small to fit formatted write
Summary:
This fixes the following warnings when compiled with GCC7:
util/transaction_test_util.cc: In static member function ‘static rocksdb::Status rocksdb::RandomTransactionInserter::DBGet(rocksdb::DB*, rocksdb::Transaction*, rocksdb::ReadOptions&, uint16_t, uint64_t, bool, uint64_t*, std::__cxx11::string*, bool*)’:
util/transaction_test_util.cc:75:8: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
Status RandomTransactionInserter::DBGet(
^~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc:84:11: note: ‘snprintf’ output between 5 and 6 bytes into a destination of size 5
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc: In static member function ‘static rocksdb::Status rocksdb::RandomTransactionInserter::Verify(rocksdb::DB*, uint16_t, uint64_t, bool, rocksdb::Random64*)’:
util/transaction_test_util.cc:245:8: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets,
^~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc:268:13: note: ‘snprintf’ output between 5 and 6 bytes into a destination of size 5
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Closes https://github.com/facebook/rocksdb/pull/3295
Differential Revision: D6609411
Pulled By: maysamyabandeh
fbshipit-source-id: 33f0add471056eb59db2f8bd4366e6dfbb1a187d
2017-12-20 17:02:53 +01:00
|
|
|
// Five digits (since the largest uint16_t is 65535) plus the NUL
|
|
|
|
// end char.
|
|
|
|
char prefix_buf[6];
|
2017-12-06 18:32:09 +01:00
|
|
|
// Pad prefix appropriately so we can iterate over each set
|
2017-12-12 21:07:35 +01:00
|
|
|
assert(set_i + 1 <= 9999);
|
2017-12-06 18:32:09 +01:00
|
|
|
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
|
|
|
|
// key format: [SET#][random#]
|
|
|
|
std::string skey = ToString(ikey);
|
|
|
|
Slice base_key(skey);
|
|
|
|
*full_key = std::string(prefix_buf) + base_key.ToString();
|
|
|
|
Slice key(*full_key);
|
|
|
|
|
|
|
|
std::string value;
|
|
|
|
if (txn != nullptr) {
|
|
|
|
if (get_for_update) {
|
|
|
|
s = txn->GetForUpdate(read_options, key, &value);
|
|
|
|
} else {
|
|
|
|
s = txn->Get(read_options, key, &value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s = db->Get(read_options, key, &value);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
// Found key, parse its value
|
|
|
|
*int_value = std::stoull(value);
|
|
|
|
if (*int_value == 0 || *int_value == ULONG_MAX) {
|
|
|
|
*unexpected_error = true;
|
|
|
|
fprintf(stderr, "Get returned unexpected value: %s\n", value.c_str());
|
|
|
|
s = Status::Corruption();
|
|
|
|
}
|
|
|
|
} else if (s.IsNotFound()) {
|
|
|
|
// Have not yet written to this key, so assume its value is 0
|
|
|
|
*int_value = 0;
|
|
|
|
s = Status::OK();
|
|
|
|
}
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
2016-03-03 20:20:25 +01:00
|
|
|
bool RandomTransactionInserter::DoInsert(DB* db, Transaction* txn,
|
|
|
|
bool is_optimistic) {
|
|
|
|
Status s;
|
|
|
|
WriteBatch batch;
|
|
|
|
|
|
|
|
// pick a random number to use to increment a key in each set
|
|
|
|
uint64_t incr = (rand_->Next() % 100) + 1;
|
|
|
|
bool unexpected_error = false;
|
|
|
|
|
2017-12-06 18:32:09 +01:00
|
|
|
std::vector<uint16_t> set_vec(num_sets_);
|
2017-12-14 20:57:11 +01:00
|
|
|
std::iota(set_vec.begin(), set_vec.end(), static_cast<uint16_t>(0));
|
2018-10-11 19:48:12 +02:00
|
|
|
std::shuffle(set_vec.begin(), set_vec.end(), std::random_device{});
|
2018-09-06 03:07:53 +02:00
|
|
|
|
2016-03-03 20:20:25 +01:00
|
|
|
// For each set, pick a key at random and increment it
|
2017-12-06 18:32:09 +01:00
|
|
|
for (uint16_t set_i : set_vec) {
|
2016-03-03 20:20:25 +01:00
|
|
|
uint64_t int_value = 0;
|
2017-12-06 18:32:09 +01:00
|
|
|
std::string full_key;
|
|
|
|
uint64_t rand_key = rand_->Next() % num_keys_;
|
|
|
|
const bool get_for_update = txn ? rand_->OneIn(2) : false;
|
|
|
|
s = DBGet(db, txn, read_options_, set_i, rand_key, get_for_update,
|
|
|
|
&int_value, &full_key, &unexpected_error);
|
2016-03-03 20:20:25 +01:00
|
|
|
Slice key(full_key);
|
2017-12-06 18:32:09 +01:00
|
|
|
if (!s.ok()) {
|
2016-03-03 20:20:25 +01:00
|
|
|
// Optimistic transactions should never return non-ok status here.
|
|
|
|
// Non-optimistic transactions may return write-coflict/timeout errors.
|
|
|
|
if (is_optimistic || !(s.IsBusy() || s.IsTimedOut() || s.IsTryAgain())) {
|
|
|
|
fprintf(stderr, "Get returned an unexpected error: %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
unexpected_error = true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
// Increment key
|
|
|
|
std::string sum = ToString(int_value + incr);
|
|
|
|
if (txn != nullptr) {
|
|
|
|
s = txn->Put(key, sum);
|
2017-12-06 18:32:09 +01:00
|
|
|
if (!get_for_update && (s.IsBusy() || s.IsTimedOut())) {
|
|
|
|
// If the initial get was not for update, then the key is not locked
|
|
|
|
// before put and put could fail due to concurrent writes.
|
|
|
|
break;
|
|
|
|
} else if (!s.ok()) {
|
2016-03-03 20:20:25 +01:00
|
|
|
// Since we did a GetForUpdate, Put should not fail.
|
|
|
|
fprintf(stderr, "Put returned an unexpected error: %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
unexpected_error = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
batch.Put(key, sum);
|
|
|
|
}
|
2017-10-17 03:29:50 +02:00
|
|
|
bytes_inserted_ += key.size() + sum.size();
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
2019-02-12 22:55:40 +01:00
|
|
|
if (txn != nullptr) {
|
|
|
|
ROCKS_LOG_DEBUG(db->GetDBOptions().info_log,
|
|
|
|
"Insert (%s) %s snap: %" PRIu64 " key:%s value: %" PRIu64
|
|
|
|
"+%" PRIu64 "=%" PRIu64,
|
|
|
|
txn->GetName().c_str(), s.ToString().c_str(),
|
|
|
|
txn->GetSnapshot()->GetSequenceNumber(), full_key.c_str(),
|
|
|
|
int_value, incr, int_value + incr);
|
|
|
|
}
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
if (txn != nullptr) {
|
2019-02-12 00:59:30 +01:00
|
|
|
bool with_prepare = !is_optimistic && !rand_->OneIn(10);
|
|
|
|
if (with_prepare) {
|
|
|
|
// Also try commit without prepare
|
2017-12-06 18:32:09 +01:00
|
|
|
s = txn->Prepare();
|
|
|
|
assert(s.ok());
|
2019-02-12 00:59:30 +01:00
|
|
|
ROCKS_LOG_DEBUG(db->GetDBOptions().info_log,
|
|
|
|
"Prepare of %" PRIu64 " %s (%s)", txn->GetId(),
|
|
|
|
s.ToString().c_str(), txn->GetName().c_str());
|
2019-05-15 22:48:59 +02:00
|
|
|
if (rand_->OneIn(20)) {
|
|
|
|
// This currently only tests the mechanics of writing commit time
|
|
|
|
// write batch so the exact values would not matter.
|
|
|
|
s = txn_->GetCommitTimeWriteBatch()->Put("cat", "dog");
|
|
|
|
assert(s.ok());
|
|
|
|
}
|
2019-02-12 00:59:30 +01:00
|
|
|
db->GetDBOptions().env->SleepForMicroseconds(
|
|
|
|
static_cast<int>(cmt_delay_ms_ * 1000));
|
2017-12-06 18:32:09 +01:00
|
|
|
}
|
2018-05-03 03:09:55 +02:00
|
|
|
if (!rand_->OneIn(20)) {
|
2017-12-06 18:32:09 +01:00
|
|
|
s = txn->Commit();
|
2019-02-12 00:59:30 +01:00
|
|
|
assert(!with_prepare || s.ok());
|
|
|
|
ROCKS_LOG_DEBUG(db->GetDBOptions().info_log,
|
|
|
|
"Commit of %" PRIu64 " %s (%s)", txn->GetId(),
|
|
|
|
s.ToString().c_str(), txn->GetName().c_str());
|
2017-12-06 18:32:09 +01:00
|
|
|
} else {
|
|
|
|
// Also try 5% rollback
|
|
|
|
s = txn->Rollback();
|
2019-02-12 00:59:30 +01:00
|
|
|
ROCKS_LOG_DEBUG(db->GetDBOptions().info_log,
|
|
|
|
"Rollback %" PRIu64 " %s %s", txn->GetId(),
|
|
|
|
txn->GetName().c_str(), s.ToString().c_str());
|
2017-12-06 18:32:09 +01:00
|
|
|
assert(s.ok());
|
|
|
|
}
|
|
|
|
assert(is_optimistic || s.ok());
|
2016-03-03 20:20:25 +01:00
|
|
|
|
|
|
|
if (!s.ok()) {
|
|
|
|
if (is_optimistic) {
|
|
|
|
// Optimistic transactions can have write-conflict errors on commit.
|
|
|
|
// Any other error is unexpected.
|
|
|
|
if (!(s.IsBusy() || s.IsTimedOut() || s.IsTryAgain())) {
|
|
|
|
unexpected_error = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// Non-optimistic transactions should only fail due to expiration
|
|
|
|
// or write failures. For testing purproses, we do not expect any
|
|
|
|
// write failures.
|
|
|
|
if (!s.IsExpired()) {
|
|
|
|
unexpected_error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unexpected_error) {
|
|
|
|
fprintf(stderr, "Commit returned an unexpected error: %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s = db->Write(write_options_, &batch);
|
|
|
|
if (!s.ok()) {
|
|
|
|
unexpected_error = true;
|
|
|
|
fprintf(stderr, "Write returned an unexpected error: %s\n",
|
|
|
|
s.ToString().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (txn != nullptr) {
|
2017-12-06 18:32:09 +01:00
|
|
|
assert(txn->Rollback().ok());
|
2019-02-12 22:55:40 +01:00
|
|
|
ROCKS_LOG_DEBUG(db->GetDBOptions().info_log, "Error %s for txn %s",
|
|
|
|
s.ToString().c_str(), txn->GetName().c_str());
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (s.ok()) {
|
|
|
|
success_count_++;
|
|
|
|
} else {
|
|
|
|
failure_count_++;
|
|
|
|
}
|
|
|
|
|
|
|
|
last_status_ = s;
|
|
|
|
|
|
|
|
// return success if we didn't get any unexpected errors
|
|
|
|
return !unexpected_error;
|
|
|
|
}
|
|
|
|
|
2017-12-06 18:32:09 +01:00
|
|
|
// Verify that the sum of the keys in each set are equal
|
|
|
|
Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets,
|
|
|
|
uint64_t num_keys_per_set,
|
2019-02-12 00:59:30 +01:00
|
|
|
bool take_snapshot, Random64* rand,
|
|
|
|
uint64_t delay_ms) {
|
|
|
|
// delay_ms is the delay between taking a snapshot and doing the reads. It
|
|
|
|
// emulates reads from a long-running backup job.
|
|
|
|
assert(delay_ms == 0 || take_snapshot);
|
2016-03-03 20:20:25 +01:00
|
|
|
uint64_t prev_total = 0;
|
2017-12-06 18:32:09 +01:00
|
|
|
uint32_t prev_i = 0;
|
|
|
|
bool prev_assigned = false;
|
|
|
|
|
|
|
|
ReadOptions roptions;
|
|
|
|
if (take_snapshot) {
|
|
|
|
roptions.snapshot = db->GetSnapshot();
|
2019-02-12 00:59:30 +01:00
|
|
|
db->GetDBOptions().env->SleepForMicroseconds(
|
|
|
|
static_cast<int>(delay_ms * 1000));
|
2017-12-06 18:32:09 +01:00
|
|
|
}
|
2016-03-03 20:20:25 +01:00
|
|
|
|
2017-12-06 18:32:09 +01:00
|
|
|
std::vector<uint16_t> set_vec(num_sets);
|
2017-12-14 20:57:11 +01:00
|
|
|
std::iota(set_vec.begin(), set_vec.end(), static_cast<uint16_t>(0));
|
2018-10-11 19:48:12 +02:00
|
|
|
std::shuffle(set_vec.begin(), set_vec.end(), std::random_device{});
|
|
|
|
|
2016-03-03 20:20:25 +01:00
|
|
|
// For each set of keys with the same prefix, sum all the values
|
2017-12-06 18:32:09 +01:00
|
|
|
for (uint16_t set_i : set_vec) {
|
FIXED: string buffers potentially too small to fit formatted write
Summary:
This fixes the following warnings when compiled with GCC7:
util/transaction_test_util.cc: In static member function ‘static rocksdb::Status rocksdb::RandomTransactionInserter::DBGet(rocksdb::DB*, rocksdb::Transaction*, rocksdb::ReadOptions&, uint16_t, uint64_t, bool, uint64_t*, std::__cxx11::string*, bool*)’:
util/transaction_test_util.cc:75:8: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
Status RandomTransactionInserter::DBGet(
^~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc:84:11: note: ‘snprintf’ output between 5 and 6 bytes into a destination of size 5
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc: In static member function ‘static rocksdb::Status rocksdb::RandomTransactionInserter::Verify(rocksdb::DB*, uint16_t, uint64_t, bool, rocksdb::Random64*)’:
util/transaction_test_util.cc:245:8: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
Status RandomTransactionInserter::Verify(DB* db, uint16_t num_sets,
^~~~~~~~~~~~~~~~~~~~~~~~~
util/transaction_test_util.cc:268:13: note: ‘snprintf’ output between 5 and 6 bytes into a destination of size 5
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Closes https://github.com/facebook/rocksdb/pull/3295
Differential Revision: D6609411
Pulled By: maysamyabandeh
fbshipit-source-id: 33f0add471056eb59db2f8bd4366e6dfbb1a187d
2017-12-20 17:02:53 +01:00
|
|
|
// Five digits (since the largest uint16_t is 65535) plus the NUL
|
|
|
|
// end char.
|
|
|
|
char prefix_buf[6];
|
2017-12-12 21:07:35 +01:00
|
|
|
assert(set_i + 1 <= 9999);
|
2017-12-06 18:32:09 +01:00
|
|
|
snprintf(prefix_buf, sizeof(prefix_buf), "%.4u", set_i + 1);
|
2016-03-03 20:20:25 +01:00
|
|
|
uint64_t total = 0;
|
|
|
|
|
2017-12-06 18:32:09 +01:00
|
|
|
// Use either point lookup or iterator. Point lookups are slower so we use
|
|
|
|
// it less often.
|
2019-02-12 00:59:30 +01:00
|
|
|
const bool use_point_lookup =
|
|
|
|
num_keys_per_set != 0 && rand && rand->OneIn(10);
|
|
|
|
if (use_point_lookup) {
|
2017-12-06 18:32:09 +01:00
|
|
|
ReadOptions read_options;
|
|
|
|
for (uint64_t k = 0; k < num_keys_per_set; k++) {
|
|
|
|
std::string dont_care;
|
|
|
|
uint64_t int_value = 0;
|
|
|
|
bool unexpected_error = false;
|
|
|
|
const bool FOR_UPDATE = false;
|
|
|
|
Status s = DBGet(db, nullptr, roptions, set_i, k, FOR_UPDATE,
|
|
|
|
&int_value, &dont_care, &unexpected_error);
|
|
|
|
assert(s.ok());
|
|
|
|
assert(!unexpected_error);
|
|
|
|
total += int_value;
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
2017-12-06 18:32:09 +01:00
|
|
|
} else { // user iterators
|
|
|
|
Iterator* iter = db->NewIterator(roptions);
|
|
|
|
for (iter->Seek(Slice(prefix_buf, 4)); iter->Valid(); iter->Next()) {
|
|
|
|
Slice key = iter->key();
|
|
|
|
// stop when we reach a different prefix
|
|
|
|
if (key.ToString().compare(0, 4, prefix_buf) != 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Slice value = iter->value();
|
|
|
|
uint64_t int_value = std::stoull(value.ToString());
|
|
|
|
if (int_value == 0 || int_value == ULONG_MAX) {
|
|
|
|
fprintf(stderr, "Iter returned unexpected value: %s\n",
|
|
|
|
value.ToString().c_str());
|
|
|
|
return Status::Corruption();
|
|
|
|
}
|
2019-02-12 00:59:30 +01:00
|
|
|
ROCKS_LOG_DEBUG(
|
|
|
|
db->GetDBOptions().info_log,
|
|
|
|
"VerifyRead at %" PRIu64 " (%" PRIu64 "): %.*s value: %" PRIu64,
|
|
|
|
roptions.snapshot ? roptions.snapshot->GetSequenceNumber() : 0ul,
|
|
|
|
roptions.snapshot
|
|
|
|
? ((SnapshotImpl*)roptions.snapshot)->min_uncommitted_
|
|
|
|
: 0ul,
|
2019-04-04 21:05:42 +02:00
|
|
|
static_cast<int>(key.size()), key.data(), int_value);
|
2017-12-06 18:32:09 +01:00
|
|
|
total += int_value;
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
2017-12-06 18:32:09 +01:00
|
|
|
delete iter;
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
2017-12-06 18:32:09 +01:00
|
|
|
|
|
|
|
if (prev_assigned && total != prev_total) {
|
2019-02-12 00:59:30 +01:00
|
|
|
db->GetDBOptions().info_log->Flush();
|
2017-12-06 18:32:09 +01:00
|
|
|
fprintf(stdout,
|
2019-02-12 00:59:30 +01:00
|
|
|
"RandomTransactionVerify found inconsistent totals using "
|
|
|
|
"pointlookup? %d "
|
|
|
|
"Set[%" PRIu32 "]: %" PRIu64 ", Set[%" PRIu32 "]: %" PRIu64
|
|
|
|
" at snapshot %" PRIu64 "\n",
|
|
|
|
use_point_lookup, prev_i, prev_total, set_i, total,
|
|
|
|
roptions.snapshot ? roptions.snapshot->GetSequenceNumber() : 0ul);
|
|
|
|
fflush(stdout);
|
2017-12-06 18:32:09 +01:00
|
|
|
return Status::Corruption();
|
2019-02-12 00:59:30 +01:00
|
|
|
} else {
|
|
|
|
ROCKS_LOG_DEBUG(
|
|
|
|
db->GetDBOptions().info_log,
|
|
|
|
"RandomTransactionVerify pass pointlookup? %d total: %" PRIu64
|
|
|
|
" snap: %" PRIu64,
|
|
|
|
use_point_lookup, total,
|
|
|
|
roptions.snapshot ? roptions.snapshot->GetSequenceNumber() : 0ul);
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
|
|
|
prev_total = total;
|
2017-12-06 18:32:09 +01:00
|
|
|
prev_i = set_i;
|
|
|
|
prev_assigned = true;
|
|
|
|
}
|
|
|
|
if (take_snapshot) {
|
|
|
|
db->ReleaseSnapshot(roptions.snapshot);
|
2016-03-03 20:20:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return Status::OK();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace rocksdb
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|