|
|
@ -444,13 +444,13 @@ DEFINE_bool(use_merge, false, "On true, replaces all writes with a Merge " |
|
|
|
namespace rocksdb { |
|
|
|
namespace rocksdb { |
|
|
|
|
|
|
|
|
|
|
|
// convert long to a big-endian slice key
|
|
|
|
// convert long to a big-endian slice key
|
|
|
|
static std::string Key(long val) { |
|
|
|
static std::string Key(int64_t val) { |
|
|
|
std::string little_endian_key; |
|
|
|
std::string little_endian_key; |
|
|
|
std::string big_endian_key; |
|
|
|
std::string big_endian_key; |
|
|
|
PutFixed64(&little_endian_key, val); |
|
|
|
PutFixed64(&little_endian_key, val); |
|
|
|
assert(little_endian_key.size() == sizeof(val)); |
|
|
|
assert(little_endian_key.size() == sizeof(val)); |
|
|
|
big_endian_key.resize(sizeof(val)); |
|
|
|
big_endian_key.resize(sizeof(val)); |
|
|
|
for (int i=0; i<(int)sizeof(val); i++) { |
|
|
|
for (size_t i = 0 ; i < sizeof(val); ++i) { |
|
|
|
big_endian_key[i] = little_endian_key[sizeof(val) - 1 - i]; |
|
|
|
big_endian_key[i] = little_endian_key[sizeof(val) - 1 - i]; |
|
|
|
} |
|
|
|
} |
|
|
|
return big_endian_key; |
|
|
|
return big_endian_key; |
|
|
@ -472,8 +472,8 @@ namespace { |
|
|
|
|
|
|
|
|
|
|
|
class Stats { |
|
|
|
class Stats { |
|
|
|
private: |
|
|
|
private: |
|
|
|
double start_; |
|
|
|
uint64_t start_; |
|
|
|
double finish_; |
|
|
|
uint64_t finish_; |
|
|
|
double seconds_; |
|
|
|
double seconds_; |
|
|
|
long done_; |
|
|
|
long done_; |
|
|
|
long gets_; |
|
|
|
long gets_; |
|
|
@ -487,7 +487,7 @@ class Stats { |
|
|
|
long errors_; |
|
|
|
long errors_; |
|
|
|
int next_report_; |
|
|
|
int next_report_; |
|
|
|
size_t bytes_; |
|
|
|
size_t bytes_; |
|
|
|
double last_op_finish_; |
|
|
|
uint64_t last_op_finish_; |
|
|
|
HistogramImpl hist_; |
|
|
|
HistogramImpl hist_; |
|
|
|
|
|
|
|
|
|
|
|
public: |
|
|
|
public: |
|
|
@ -538,11 +538,11 @@ class Stats { |
|
|
|
|
|
|
|
|
|
|
|
void FinishedSingleOp() { |
|
|
|
void FinishedSingleOp() { |
|
|
|
if (FLAGS_histogram) { |
|
|
|
if (FLAGS_histogram) { |
|
|
|
double now = FLAGS_env->NowMicros(); |
|
|
|
auto now = FLAGS_env->NowMicros(); |
|
|
|
double micros = now - last_op_finish_; |
|
|
|
auto micros = now - last_op_finish_; |
|
|
|
hist_.Add(micros); |
|
|
|
hist_.Add(micros); |
|
|
|
if (micros > 20000) { |
|
|
|
if (micros > 20000) { |
|
|
|
fprintf(stdout, "long op: %.1f micros%30s\r", micros, ""); |
|
|
|
fprintf(stdout, "long op: %" PRIu64 " micros%30s\r", micros, ""); |
|
|
|
} |
|
|
|
} |
|
|
|
last_op_finish_ = now; |
|
|
|
last_op_finish_ = now; |
|
|
|
} |
|
|
|
} |
|
|
@ -676,7 +676,7 @@ class SharedState { |
|
|
|
values_[i] = std::vector<uint32_t>(max_key_, SENTINEL); |
|
|
|
values_[i] = std::vector<uint32_t>(max_key_, SENTINEL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long num_locks = (max_key_ >> log2_keys_per_lock_); |
|
|
|
long num_locks = static_cast<long>(max_key_ >> log2_keys_per_lock_); |
|
|
|
if (max_key_ & ((1 << log2_keys_per_lock_) - 1)) { |
|
|
|
if (max_key_ & ((1 << log2_keys_per_lock_) - 1)) { |
|
|
|
num_locks++; |
|
|
|
num_locks++; |
|
|
|
} |
|
|
|
} |
|
|
@ -705,7 +705,7 @@ class SharedState { |
|
|
|
return stress_test_; |
|
|
|
return stress_test_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
long GetMaxKey() const { |
|
|
|
int64_t GetMaxKey() const { |
|
|
|
return max_key_; |
|
|
|
return max_key_; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -785,21 +785,21 @@ class SharedState { |
|
|
|
std::fill(values_[cf].begin(), values_[cf].end(), SENTINEL); |
|
|
|
std::fill(values_[cf].begin(), values_[cf].end(), SENTINEL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Put(int cf, long key, uint32_t value_base) { |
|
|
|
void Put(int cf, int64_t key, uint32_t value_base) { |
|
|
|
values_[cf][key] = value_base; |
|
|
|
values_[cf][key] = value_base; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
uint32_t Get(int cf, long key) const { return values_[cf][key]; } |
|
|
|
uint32_t Get(int cf, int64_t key) const { return values_[cf][key]; } |
|
|
|
|
|
|
|
|
|
|
|
void Delete(int cf, long key) { values_[cf][key] = SENTINEL; } |
|
|
|
void Delete(int cf, int64_t key) { values_[cf][key] = SENTINEL; } |
|
|
|
|
|
|
|
|
|
|
|
void SingleDelete(int cf, size_t key) { values_[cf][key] = SENTINEL; } |
|
|
|
void SingleDelete(int cf, int64_t key) { values_[cf][key] = SENTINEL; } |
|
|
|
|
|
|
|
|
|
|
|
bool AllowsOverwrite(int cf, size_t key) { |
|
|
|
bool AllowsOverwrite(int cf, int64_t key) { |
|
|
|
return no_overwrite_ids_[cf].find(key) == no_overwrite_ids_[cf].end(); |
|
|
|
return no_overwrite_ids_[cf].find(key) == no_overwrite_ids_[cf].end(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Exists(int cf, size_t key) { return values_[cf][key] != SENTINEL; } |
|
|
|
bool Exists(int cf, int64_t key) { return values_[cf][key] != SENTINEL; } |
|
|
|
|
|
|
|
|
|
|
|
uint32_t GetSeed() const { return seed_; } |
|
|
|
uint32_t GetSeed() const { return seed_; } |
|
|
|
|
|
|
|
|
|
|
@ -815,7 +815,7 @@ class SharedState { |
|
|
|
port::Mutex mu_; |
|
|
|
port::Mutex mu_; |
|
|
|
port::CondVar cv_; |
|
|
|
port::CondVar cv_; |
|
|
|
const uint32_t seed_; |
|
|
|
const uint32_t seed_; |
|
|
|
const long max_key_; |
|
|
|
const int64_t max_key_; |
|
|
|
const uint32_t log2_keys_per_lock_; |
|
|
|
const uint32_t log2_keys_per_lock_; |
|
|
|
const int num_threads_; |
|
|
|
const int num_threads_; |
|
|
|
long num_initialized_; |
|
|
|
long num_initialized_; |
|
|
@ -1122,9 +1122,9 @@ class StressTest { |
|
|
|
shared.GetCondVar()->Wait(); |
|
|
|
shared.GetCondVar()->Wait(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
double now = FLAGS_env->NowMicros(); |
|
|
|
auto now = FLAGS_env->NowMicros(); |
|
|
|
fprintf(stdout, "%s Starting database operations\n", |
|
|
|
fprintf(stdout, "%s Starting database operations\n", |
|
|
|
FLAGS_env->TimeToString((uint64_t) now/1000000).c_str()); |
|
|
|
FLAGS_env->TimeToString(now/1000000).c_str()); |
|
|
|
|
|
|
|
|
|
|
|
shared.SetStart(); |
|
|
|
shared.SetStart(); |
|
|
|
shared.GetCondVar()->SignalAll(); |
|
|
|
shared.GetCondVar()->SignalAll(); |
|
|
@ -1157,10 +1157,10 @@ class StressTest { |
|
|
|
delete threads[i]; |
|
|
|
delete threads[i]; |
|
|
|
threads[i] = nullptr; |
|
|
|
threads[i] = nullptr; |
|
|
|
} |
|
|
|
} |
|
|
|
double now = FLAGS_env->NowMicros(); |
|
|
|
auto now = FLAGS_env->NowMicros(); |
|
|
|
if (!FLAGS_test_batches_snapshots) { |
|
|
|
if (!FLAGS_test_batches_snapshots) { |
|
|
|
fprintf(stdout, "%s Verification successful\n", |
|
|
|
fprintf(stdout, "%s Verification successful\n", |
|
|
|
FLAGS_env->TimeToString((uint64_t) now/1000000).c_str()); |
|
|
|
FLAGS_env->TimeToString(now/1000000).c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
PrintStatistics(); |
|
|
|
PrintStatistics(); |
|
|
|
|
|
|
|
|
|
|
@ -1510,7 +1510,7 @@ class StressTest { |
|
|
|
WriteOptions write_opts; |
|
|
|
WriteOptions write_opts; |
|
|
|
auto shared = thread->shared; |
|
|
|
auto shared = thread->shared; |
|
|
|
char value[100]; |
|
|
|
char value[100]; |
|
|
|
long max_key = thread->shared->GetMaxKey(); |
|
|
|
auto max_key = thread->shared->GetMaxKey(); |
|
|
|
std::string from_db; |
|
|
|
std::string from_db; |
|
|
|
if (FLAGS_sync) { |
|
|
|
if (FLAGS_sync) { |
|
|
|
write_opts.sync = true; |
|
|
|
write_opts.sync = true; |
|
|
@ -1760,7 +1760,7 @@ class StressTest { |
|
|
|
unique_ptr<Iterator> iter( |
|
|
|
unique_ptr<Iterator> iter( |
|
|
|
db_->NewIterator(options, column_families_[cf])); |
|
|
|
db_->NewIterator(options, column_families_[cf])); |
|
|
|
iter->Seek(Key(start)); |
|
|
|
iter->Seek(Key(start)); |
|
|
|
for (long i = start; i < end; i++) { |
|
|
|
for (auto i = start; i < end; i++) { |
|
|
|
if (thread->shared->HasVerificationFailedYet()) { |
|
|
|
if (thread->shared->HasVerificationFailedYet()) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -1798,7 +1798,7 @@ class StressTest { |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
// Use Get to verify this range
|
|
|
|
// Use Get to verify this range
|
|
|
|
for (long i = start; i < end; i++) { |
|
|
|
for (auto i = start; i < end; i++) { |
|
|
|
if (thread->shared->HasVerificationFailedYet()) { |
|
|
|
if (thread->shared->HasVerificationFailedYet()) { |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -1818,13 +1818,13 @@ class StressTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VerificationAbort(SharedState* shared, std::string msg, int cf, |
|
|
|
void VerificationAbort(SharedState* shared, std::string msg, int cf, |
|
|
|
long key) const { |
|
|
|
int64_t key) const { |
|
|
|
printf("Verification failed for column family %d key %ld: %s\n", cf, key, |
|
|
|
printf("Verification failed for column family %d key %" PRIi64 ": %s\n", cf, key, |
|
|
|
msg.c_str()); |
|
|
|
msg.c_str()); |
|
|
|
shared->SetVerificationFailure(); |
|
|
|
shared->SetVerificationFailure(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool VerifyValue(int cf, long key, const ReadOptions& opts, |
|
|
|
bool VerifyValue(int cf, int64_t key, const ReadOptions& opts, |
|
|
|
SharedState* shared, const std::string& value_from_db, |
|
|
|
SharedState* shared, const std::string& value_from_db, |
|
|
|
Status s, bool strict = false) const { |
|
|
|
Status s, bool strict = false) const { |
|
|
|
if (shared->HasVerificationFailedYet()) { |
|
|
|
if (shared->HasVerificationFailedYet()) { |
|
|
@ -1861,12 +1861,12 @@ class StressTest { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void PrintKeyValue(int cf, uint32_t key, const char* value, |
|
|
|
static void PrintKeyValue(int cf, int64_t key, const char* value, |
|
|
|
size_t sz) { |
|
|
|
size_t sz) { |
|
|
|
if (!FLAGS_verbose) { |
|
|
|
if (!FLAGS_verbose) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
fprintf(stdout, "[CF %d] %u ==> (%u) ", cf, key, (unsigned int)sz); |
|
|
|
fprintf(stdout, "[CF %d] %" PRIi64 " == > (%" ROCKSDB_PRIszt ") ", cf, key, sz); |
|
|
|
for (size_t i = 0; i < sz; i++) { |
|
|
|
for (size_t i = 0; i < sz; i++) { |
|
|
|
fprintf(stdout, "%X", value[i]); |
|
|
|
fprintf(stdout, "%X", value[i]); |
|
|
|
} |
|
|
|
} |
|
|
@ -2127,9 +2127,9 @@ class StressTest { |
|
|
|
db_ = nullptr; |
|
|
|
db_ = nullptr; |
|
|
|
|
|
|
|
|
|
|
|
num_times_reopened_++; |
|
|
|
num_times_reopened_++; |
|
|
|
double now = FLAGS_env->NowMicros(); |
|
|
|
auto now = FLAGS_env->NowMicros(); |
|
|
|
fprintf(stdout, "%s Reopening database for the %dth time\n", |
|
|
|
fprintf(stdout, "%s Reopening database for the %dth time\n", |
|
|
|
FLAGS_env->TimeToString((uint64_t) now/1000000).c_str(), |
|
|
|
FLAGS_env->TimeToString(now/1000000).c_str(), |
|
|
|
num_times_reopened_); |
|
|
|
num_times_reopened_); |
|
|
|
Open(); |
|
|
|
Open(); |
|
|
|
} |
|
|
|
} |
|
|
|