no_batched_ops_stress.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. // Copyright (c) 2011 The LevelDB Authors. All rights reserved.
  7. // Use of this source code is governed by a BSD-style license that can be
  8. // found in the LICENSE file. See the AUTHORS file for names of contributors.
  9. #ifdef GFLAGS
  10. #include "db_stress_tool/db_stress_common.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. class NonBatchedOpsStressTest : public StressTest {
  13. public:
  14. NonBatchedOpsStressTest() {}
  15. virtual ~NonBatchedOpsStressTest() {}
  16. void VerifyDb(ThreadState* thread) const override {
  17. ReadOptions options(FLAGS_verify_checksum, true);
  18. auto shared = thread->shared;
  19. const int64_t max_key = shared->GetMaxKey();
  20. const int64_t keys_per_thread = max_key / shared->GetNumThreads();
  21. int64_t start = keys_per_thread * thread->tid;
  22. int64_t end = start + keys_per_thread;
  23. uint64_t prefix_to_use =
  24. (FLAGS_prefix_size < 0) ? 1 : static_cast<size_t>(FLAGS_prefix_size);
  25. if (thread->tid == shared->GetNumThreads() - 1) {
  26. end = max_key;
  27. }
  28. for (size_t cf = 0; cf < column_families_.size(); ++cf) {
  29. if (thread->shared->HasVerificationFailedYet()) {
  30. break;
  31. }
  32. if (!thread->rand.OneIn(2)) {
  33. // Use iterator to verify this range
  34. Slice prefix;
  35. std::string seek_key = Key(start);
  36. std::unique_ptr<Iterator> iter(
  37. db_->NewIterator(options, column_families_[cf]));
  38. iter->Seek(seek_key);
  39. prefix = Slice(seek_key.data(), prefix_to_use);
  40. for (auto i = start; i < end; i++) {
  41. if (thread->shared->HasVerificationFailedYet()) {
  42. break;
  43. }
  44. std::string from_db;
  45. std::string keystr = Key(i);
  46. Slice k = keystr;
  47. Slice pfx = Slice(keystr.data(), prefix_to_use);
  48. // Reseek when the prefix changes
  49. if (prefix_to_use > 0 && prefix.compare(pfx) != 0) {
  50. iter->Seek(k);
  51. seek_key = keystr;
  52. prefix = Slice(seek_key.data(), prefix_to_use);
  53. }
  54. Status s = iter->status();
  55. if (iter->Valid()) {
  56. Slice iter_key = iter->key();
  57. if (iter->key().compare(k) > 0) {
  58. s = Status::NotFound(Slice());
  59. } else if (iter->key().compare(k) == 0) {
  60. from_db = iter->value().ToString();
  61. iter->Next();
  62. } else if (iter_key.compare(k) < 0) {
  63. VerificationAbort(shared, "An out of range key was found",
  64. static_cast<int>(cf), i);
  65. }
  66. } else {
  67. // The iterator found no value for the key in question, so do not
  68. // move to the next item in the iterator
  69. s = Status::NotFound();
  70. }
  71. VerifyValue(static_cast<int>(cf), i, options, shared, from_db, s,
  72. true);
  73. if (from_db.length()) {
  74. PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
  75. from_db.data(), from_db.length());
  76. }
  77. }
  78. } else {
  79. // Use Get to verify this range
  80. for (auto i = start; i < end; i++) {
  81. if (thread->shared->HasVerificationFailedYet()) {
  82. break;
  83. }
  84. std::string from_db;
  85. std::string keystr = Key(i);
  86. Slice k = keystr;
  87. Status s = db_->Get(options, column_families_[cf], k, &from_db);
  88. VerifyValue(static_cast<int>(cf), i, options, shared, from_db, s,
  89. true);
  90. if (from_db.length()) {
  91. PrintKeyValue(static_cast<int>(cf), static_cast<uint32_t>(i),
  92. from_db.data(), from_db.length());
  93. }
  94. }
  95. }
  96. }
  97. }
  98. void MaybeClearOneColumnFamily(ThreadState* thread) override {
  99. if (FLAGS_column_families > 1) {
  100. if (thread->rand.OneInOpt(FLAGS_clear_column_family_one_in)) {
  101. // drop column family and then create it again (can't drop default)
  102. int cf = thread->rand.Next() % (FLAGS_column_families - 1) + 1;
  103. std::string new_name = ToString(new_column_family_name_.fetch_add(1));
  104. {
  105. MutexLock l(thread->shared->GetMutex());
  106. fprintf(
  107. stdout,
  108. "[CF %d] Dropping and recreating column family. new name: %s\n",
  109. cf, new_name.c_str());
  110. }
  111. thread->shared->LockColumnFamily(cf);
  112. Status s = db_->DropColumnFamily(column_families_[cf]);
  113. delete column_families_[cf];
  114. if (!s.ok()) {
  115. fprintf(stderr, "dropping column family error: %s\n",
  116. s.ToString().c_str());
  117. std::terminate();
  118. }
  119. s = db_->CreateColumnFamily(ColumnFamilyOptions(options_), new_name,
  120. &column_families_[cf]);
  121. column_family_names_[cf] = new_name;
  122. thread->shared->ClearColumnFamily(cf);
  123. if (!s.ok()) {
  124. fprintf(stderr, "creating column family error: %s\n",
  125. s.ToString().c_str());
  126. std::terminate();
  127. }
  128. thread->shared->UnlockColumnFamily(cf);
  129. }
  130. }
  131. }
  132. bool ShouldAcquireMutexOnKey() const override { return true; }
  133. Status TestGet(ThreadState* thread, const ReadOptions& read_opts,
  134. const std::vector<int>& rand_column_families,
  135. const std::vector<int64_t>& rand_keys) override {
  136. auto cfh = column_families_[rand_column_families[0]];
  137. std::string key_str = Key(rand_keys[0]);
  138. Slice key = key_str;
  139. std::string from_db;
  140. Status s = db_->Get(read_opts, cfh, key, &from_db);
  141. if (s.ok()) {
  142. // found case
  143. thread->stats.AddGets(1, 1);
  144. } else if (s.IsNotFound()) {
  145. // not found case
  146. thread->stats.AddGets(1, 0);
  147. } else {
  148. // errors case
  149. fprintf(stderr, "TestGet error: %s\n", s.ToString().c_str());
  150. thread->stats.AddErrors(1);
  151. }
  152. return s;
  153. }
  154. std::vector<Status> TestMultiGet(
  155. ThreadState* thread, const ReadOptions& read_opts,
  156. const std::vector<int>& rand_column_families,
  157. const std::vector<int64_t>& rand_keys) override {
  158. size_t num_keys = rand_keys.size();
  159. std::vector<std::string> key_str;
  160. std::vector<Slice> keys;
  161. key_str.reserve(num_keys);
  162. keys.reserve(num_keys);
  163. std::vector<PinnableSlice> values(num_keys);
  164. std::vector<Status> statuses(num_keys);
  165. ColumnFamilyHandle* cfh = column_families_[rand_column_families[0]];
  166. // To appease clang analyzer
  167. const bool use_txn = FLAGS_use_txn;
  168. // Create a transaction in order to write some data. The purpose is to
  169. // exercise WriteBatchWithIndex::MultiGetFromBatchAndDB. The transaction
  170. // will be rolled back once MultiGet returns.
  171. #ifndef ROCKSDB_LITE
  172. Transaction* txn = nullptr;
  173. if (use_txn) {
  174. WriteOptions wo;
  175. Status s = NewTxn(wo, &txn);
  176. if (!s.ok()) {
  177. fprintf(stderr, "NewTxn: %s\n", s.ToString().c_str());
  178. std::terminate();
  179. }
  180. }
  181. #endif
  182. for (size_t i = 0; i < num_keys; ++i) {
  183. key_str.emplace_back(Key(rand_keys[i]));
  184. keys.emplace_back(key_str.back());
  185. #ifndef ROCKSDB_LITE
  186. if (use_txn) {
  187. // With a 1 in 10 probability, insert the just added key in the batch
  188. // into the transaction. This will create an overlap with the MultiGet
  189. // keys and exercise some corner cases in the code
  190. if (thread->rand.OneIn(10)) {
  191. int op = thread->rand.Uniform(2);
  192. Status s;
  193. switch (op) {
  194. case 0:
  195. case 1: {
  196. uint32_t value_base =
  197. thread->rand.Next() % thread->shared->UNKNOWN_SENTINEL;
  198. char value[100];
  199. size_t sz = GenerateValue(value_base, value, sizeof(value));
  200. Slice v(value, sz);
  201. if (op == 0) {
  202. s = txn->Put(cfh, keys.back(), v);
  203. } else {
  204. s = txn->Merge(cfh, keys.back(), v);
  205. }
  206. break;
  207. }
  208. case 2:
  209. s = txn->Delete(cfh, keys.back());
  210. break;
  211. default:
  212. assert(false);
  213. }
  214. if (!s.ok()) {
  215. fprintf(stderr, "Transaction put: %s\n", s.ToString().c_str());
  216. std::terminate();
  217. }
  218. }
  219. }
  220. #endif
  221. }
  222. if (!use_txn) {
  223. db_->MultiGet(read_opts, cfh, num_keys, keys.data(), values.data(),
  224. statuses.data());
  225. } else {
  226. #ifndef ROCKSDB_LITE
  227. txn->MultiGet(read_opts, cfh, num_keys, keys.data(), values.data(),
  228. statuses.data());
  229. RollbackTxn(txn);
  230. #endif
  231. }
  232. for (const auto& s : statuses) {
  233. if (s.ok()) {
  234. // found case
  235. thread->stats.AddGets(1, 1);
  236. } else if (s.IsNotFound()) {
  237. // not found case
  238. thread->stats.AddGets(1, 0);
  239. } else if (s.IsMergeInProgress() && use_txn) {
  240. // With txn this is sometimes expected.
  241. thread->stats.AddGets(1, 1);
  242. } else {
  243. // errors case
  244. fprintf(stderr, "MultiGet error: %s\n", s.ToString().c_str());
  245. thread->stats.AddErrors(1);
  246. }
  247. }
  248. return statuses;
  249. }
  250. Status TestPrefixScan(ThreadState* thread, const ReadOptions& read_opts,
  251. const std::vector<int>& rand_column_families,
  252. const std::vector<int64_t>& rand_keys) override {
  253. auto cfh = column_families_[rand_column_families[0]];
  254. std::string key_str = Key(rand_keys[0]);
  255. Slice key = key_str;
  256. Slice prefix = Slice(key.data(), FLAGS_prefix_size);
  257. std::string upper_bound;
  258. Slice ub_slice;
  259. ReadOptions ro_copy = read_opts;
  260. // Get the next prefix first and then see if we want to set upper bound.
  261. // We'll use the next prefix in an assertion later on
  262. if (GetNextPrefix(prefix, &upper_bound) && thread->rand.OneIn(2)) {
  263. // For half of the time, set the upper bound to the next prefix
  264. ub_slice = Slice(upper_bound);
  265. ro_copy.iterate_upper_bound = &ub_slice;
  266. }
  267. Iterator* iter = db_->NewIterator(ro_copy, cfh);
  268. unsigned long count = 0;
  269. for (iter->Seek(prefix); iter->Valid() && iter->key().starts_with(prefix);
  270. iter->Next()) {
  271. ++count;
  272. }
  273. assert(count <= GetPrefixKeyCount(prefix.ToString(), upper_bound));
  274. Status s = iter->status();
  275. if (iter->status().ok()) {
  276. thread->stats.AddPrefixes(1, count);
  277. } else {
  278. fprintf(stderr, "TestPrefixScan error: %s\n", s.ToString().c_str());
  279. thread->stats.AddErrors(1);
  280. }
  281. delete iter;
  282. return s;
  283. }
  284. Status TestPut(ThreadState* thread, WriteOptions& write_opts,
  285. const ReadOptions& read_opts,
  286. const std::vector<int>& rand_column_families,
  287. const std::vector<int64_t>& rand_keys, char (&value)[100],
  288. std::unique_ptr<MutexLock>& lock) override {
  289. auto shared = thread->shared;
  290. int64_t max_key = shared->GetMaxKey();
  291. int64_t rand_key = rand_keys[0];
  292. int rand_column_family = rand_column_families[0];
  293. while (!shared->AllowsOverwrite(rand_key) &&
  294. (FLAGS_use_merge || shared->Exists(rand_column_family, rand_key))) {
  295. lock.reset();
  296. rand_key = thread->rand.Next() % max_key;
  297. rand_column_family = thread->rand.Next() % FLAGS_column_families;
  298. lock.reset(
  299. new MutexLock(shared->GetMutexForKey(rand_column_family, rand_key)));
  300. }
  301. std::string key_str = Key(rand_key);
  302. Slice key = key_str;
  303. ColumnFamilyHandle* cfh = column_families_[rand_column_family];
  304. if (FLAGS_verify_before_write) {
  305. std::string key_str2 = Key(rand_key);
  306. Slice k = key_str2;
  307. std::string from_db;
  308. Status s = db_->Get(read_opts, cfh, k, &from_db);
  309. if (!VerifyValue(rand_column_family, rand_key, read_opts, shared, from_db,
  310. s, true)) {
  311. return s;
  312. }
  313. }
  314. uint32_t value_base = thread->rand.Next() % shared->UNKNOWN_SENTINEL;
  315. size_t sz = GenerateValue(value_base, value, sizeof(value));
  316. Slice v(value, sz);
  317. shared->Put(rand_column_family, rand_key, value_base, true /* pending */);
  318. Status s;
  319. if (FLAGS_use_merge) {
  320. if (!FLAGS_use_txn) {
  321. s = db_->Merge(write_opts, cfh, key, v);
  322. } else {
  323. #ifndef ROCKSDB_LITE
  324. Transaction* txn;
  325. s = NewTxn(write_opts, &txn);
  326. if (s.ok()) {
  327. s = txn->Merge(cfh, key, v);
  328. if (s.ok()) {
  329. s = CommitTxn(txn);
  330. }
  331. }
  332. #endif
  333. }
  334. } else {
  335. if (!FLAGS_use_txn) {
  336. s = db_->Put(write_opts, cfh, key, v);
  337. } else {
  338. #ifndef ROCKSDB_LITE
  339. Transaction* txn;
  340. s = NewTxn(write_opts, &txn);
  341. if (s.ok()) {
  342. s = txn->Put(cfh, key, v);
  343. if (s.ok()) {
  344. s = CommitTxn(txn);
  345. }
  346. }
  347. #endif
  348. }
  349. }
  350. shared->Put(rand_column_family, rand_key, value_base, false /* pending */);
  351. if (!s.ok()) {
  352. fprintf(stderr, "put or merge error: %s\n", s.ToString().c_str());
  353. std::terminate();
  354. }
  355. thread->stats.AddBytesForWrites(1, sz);
  356. PrintKeyValue(rand_column_family, static_cast<uint32_t>(rand_key), value,
  357. sz);
  358. return s;
  359. }
  360. Status TestDelete(ThreadState* thread, WriteOptions& write_opts,
  361. const std::vector<int>& rand_column_families,
  362. const std::vector<int64_t>& rand_keys,
  363. std::unique_ptr<MutexLock>& lock) override {
  364. int64_t rand_key = rand_keys[0];
  365. int rand_column_family = rand_column_families[0];
  366. auto shared = thread->shared;
  367. int64_t max_key = shared->GetMaxKey();
  368. // OPERATION delete
  369. // If the chosen key does not allow overwrite and it does not exist,
  370. // choose another key.
  371. while (!shared->AllowsOverwrite(rand_key) &&
  372. !shared->Exists(rand_column_family, rand_key)) {
  373. lock.reset();
  374. rand_key = thread->rand.Next() % max_key;
  375. rand_column_family = thread->rand.Next() % FLAGS_column_families;
  376. lock.reset(
  377. new MutexLock(shared->GetMutexForKey(rand_column_family, rand_key)));
  378. }
  379. std::string key_str = Key(rand_key);
  380. Slice key = key_str;
  381. auto cfh = column_families_[rand_column_family];
  382. // Use delete if the key may be overwritten and a single deletion
  383. // otherwise.
  384. Status s;
  385. if (shared->AllowsOverwrite(rand_key)) {
  386. shared->Delete(rand_column_family, rand_key, true /* pending */);
  387. if (!FLAGS_use_txn) {
  388. s = db_->Delete(write_opts, cfh, key);
  389. } else {
  390. #ifndef ROCKSDB_LITE
  391. Transaction* txn;
  392. s = NewTxn(write_opts, &txn);
  393. if (s.ok()) {
  394. s = txn->Delete(cfh, key);
  395. if (s.ok()) {
  396. s = CommitTxn(txn);
  397. }
  398. }
  399. #endif
  400. }
  401. shared->Delete(rand_column_family, rand_key, false /* pending */);
  402. thread->stats.AddDeletes(1);
  403. if (!s.ok()) {
  404. fprintf(stderr, "delete error: %s\n", s.ToString().c_str());
  405. std::terminate();
  406. }
  407. } else {
  408. shared->SingleDelete(rand_column_family, rand_key, true /* pending */);
  409. if (!FLAGS_use_txn) {
  410. s = db_->SingleDelete(write_opts, cfh, key);
  411. } else {
  412. #ifndef ROCKSDB_LITE
  413. Transaction* txn;
  414. s = NewTxn(write_opts, &txn);
  415. if (s.ok()) {
  416. s = txn->SingleDelete(cfh, key);
  417. if (s.ok()) {
  418. s = CommitTxn(txn);
  419. }
  420. }
  421. #endif
  422. }
  423. shared->SingleDelete(rand_column_family, rand_key, false /* pending */);
  424. thread->stats.AddSingleDeletes(1);
  425. if (!s.ok()) {
  426. fprintf(stderr, "single delete error: %s\n", s.ToString().c_str());
  427. std::terminate();
  428. }
  429. }
  430. return s;
  431. }
  432. Status TestDeleteRange(ThreadState* thread, WriteOptions& write_opts,
  433. const std::vector<int>& rand_column_families,
  434. const std::vector<int64_t>& rand_keys,
  435. std::unique_ptr<MutexLock>& lock) override {
  436. // OPERATION delete range
  437. std::vector<std::unique_ptr<MutexLock>> range_locks;
  438. // delete range does not respect disallowed overwrites. the keys for
  439. // which overwrites are disallowed are randomly distributed so it
  440. // could be expensive to find a range where each key allows
  441. // overwrites.
  442. int64_t rand_key = rand_keys[0];
  443. int rand_column_family = rand_column_families[0];
  444. auto shared = thread->shared;
  445. int64_t max_key = shared->GetMaxKey();
  446. if (rand_key > max_key - FLAGS_range_deletion_width) {
  447. lock.reset();
  448. rand_key =
  449. thread->rand.Next() % (max_key - FLAGS_range_deletion_width + 1);
  450. range_locks.emplace_back(
  451. new MutexLock(shared->GetMutexForKey(rand_column_family, rand_key)));
  452. } else {
  453. range_locks.emplace_back(std::move(lock));
  454. }
  455. for (int j = 1; j < FLAGS_range_deletion_width; ++j) {
  456. if (((rand_key + j) & ((1 << FLAGS_log2_keys_per_lock) - 1)) == 0) {
  457. range_locks.emplace_back(new MutexLock(
  458. shared->GetMutexForKey(rand_column_family, rand_key + j)));
  459. }
  460. }
  461. shared->DeleteRange(rand_column_family, rand_key,
  462. rand_key + FLAGS_range_deletion_width,
  463. true /* pending */);
  464. std::string keystr = Key(rand_key);
  465. Slice key = keystr;
  466. auto cfh = column_families_[rand_column_family];
  467. std::string end_keystr = Key(rand_key + FLAGS_range_deletion_width);
  468. Slice end_key = end_keystr;
  469. Status s = db_->DeleteRange(write_opts, cfh, key, end_key);
  470. if (!s.ok()) {
  471. fprintf(stderr, "delete range error: %s\n", s.ToString().c_str());
  472. std::terminate();
  473. }
  474. int covered = shared->DeleteRange(rand_column_family, rand_key,
  475. rand_key + FLAGS_range_deletion_width,
  476. false /* pending */);
  477. thread->stats.AddRangeDeletions(1);
  478. thread->stats.AddCoveredByRangeDeletions(covered);
  479. return s;
  480. }
  481. #ifdef ROCKSDB_LITE
  482. void TestIngestExternalFile(
  483. ThreadState* /* thread */,
  484. const std::vector<int>& /* rand_column_families */,
  485. const std::vector<int64_t>& /* rand_keys */,
  486. std::unique_ptr<MutexLock>& /* lock */) override {
  487. assert(false);
  488. fprintf(stderr,
  489. "RocksDB lite does not support "
  490. "TestIngestExternalFile\n");
  491. std::terminate();
  492. }
  493. #else
  494. void TestIngestExternalFile(ThreadState* thread,
  495. const std::vector<int>& rand_column_families,
  496. const std::vector<int64_t>& rand_keys,
  497. std::unique_ptr<MutexLock>& lock) override {
  498. const std::string sst_filename =
  499. FLAGS_db + "/." + ToString(thread->tid) + ".sst";
  500. Status s;
  501. if (db_stress_env->FileExists(sst_filename).ok()) {
  502. // Maybe we terminated abnormally before, so cleanup to give this file
  503. // ingestion a clean slate
  504. s = db_stress_env->DeleteFile(sst_filename);
  505. }
  506. SstFileWriter sst_file_writer(EnvOptions(options_), options_);
  507. if (s.ok()) {
  508. s = sst_file_writer.Open(sst_filename);
  509. }
  510. int64_t key_base = rand_keys[0];
  511. int column_family = rand_column_families[0];
  512. std::vector<std::unique_ptr<MutexLock>> range_locks;
  513. std::vector<uint32_t> values;
  514. SharedState* shared = thread->shared;
  515. // Grab locks, set pending state on expected values, and add keys
  516. for (int64_t key = key_base;
  517. s.ok() && key < std::min(key_base + FLAGS_ingest_external_file_width,
  518. shared->GetMaxKey());
  519. ++key) {
  520. if (key == key_base) {
  521. range_locks.emplace_back(std::move(lock));
  522. } else if ((key & ((1 << FLAGS_log2_keys_per_lock) - 1)) == 0) {
  523. range_locks.emplace_back(
  524. new MutexLock(shared->GetMutexForKey(column_family, key)));
  525. }
  526. uint32_t value_base = thread->rand.Next() % shared->UNKNOWN_SENTINEL;
  527. values.push_back(value_base);
  528. shared->Put(column_family, key, value_base, true /* pending */);
  529. char value[100];
  530. size_t value_len = GenerateValue(value_base, value, sizeof(value));
  531. auto key_str = Key(key);
  532. s = sst_file_writer.Put(Slice(key_str), Slice(value, value_len));
  533. }
  534. if (s.ok()) {
  535. s = sst_file_writer.Finish();
  536. }
  537. if (s.ok()) {
  538. s = db_->IngestExternalFile(column_families_[column_family],
  539. {sst_filename}, IngestExternalFileOptions());
  540. }
  541. if (!s.ok()) {
  542. fprintf(stderr, "file ingestion error: %s\n", s.ToString().c_str());
  543. std::terminate();
  544. }
  545. int64_t key = key_base;
  546. for (int32_t value : values) {
  547. shared->Put(column_family, key, value, false /* pending */);
  548. ++key;
  549. }
  550. }
  551. #endif // ROCKSDB_LITE
  552. bool VerifyValue(int cf, int64_t key, const ReadOptions& /*opts*/,
  553. SharedState* shared, const std::string& value_from_db,
  554. const Status& s, bool strict = false) const {
  555. if (shared->HasVerificationFailedYet()) {
  556. return false;
  557. }
  558. // compare value_from_db with the value in the shared state
  559. char value[kValueMaxLen];
  560. uint32_t value_base = shared->Get(cf, key);
  561. if (value_base == SharedState::UNKNOWN_SENTINEL) {
  562. return true;
  563. }
  564. if (value_base == SharedState::DELETION_SENTINEL && !strict) {
  565. return true;
  566. }
  567. if (s.ok()) {
  568. if (value_base == SharedState::DELETION_SENTINEL) {
  569. VerificationAbort(shared, "Unexpected value found", cf, key);
  570. return false;
  571. }
  572. size_t sz = GenerateValue(value_base, value, sizeof(value));
  573. if (value_from_db.length() != sz) {
  574. VerificationAbort(shared, "Length of value read is not equal", cf, key);
  575. return false;
  576. }
  577. if (memcmp(value_from_db.data(), value, sz) != 0) {
  578. VerificationAbort(shared, "Contents of value read don't match", cf,
  579. key);
  580. return false;
  581. }
  582. } else {
  583. if (value_base != SharedState::DELETION_SENTINEL) {
  584. VerificationAbort(shared, "Value not found: " + s.ToString(), cf, key);
  585. return false;
  586. }
  587. }
  588. return true;
  589. }
  590. };
  591. StressTest* CreateNonBatchedOpsStressTest() {
  592. return new NonBatchedOpsStressTest();
  593. }
  594. } // namespace ROCKSDB_NAMESPACE
  595. #endif // GFLAGS