db_io_failure_test.cc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  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. #include "db/db_test_util.h"
  10. #include "port/stack_trace.h"
  11. namespace ROCKSDB_NAMESPACE {
  12. class DBIOFailureTest : public DBTestBase {
  13. public:
  14. DBIOFailureTest() : DBTestBase("/db_io_failure_test") {}
  15. };
  16. #ifndef ROCKSDB_LITE
  17. // Check that number of files does not grow when writes are dropped
  18. TEST_F(DBIOFailureTest, DropWrites) {
  19. do {
  20. Options options = CurrentOptions();
  21. options.env = env_;
  22. options.paranoid_checks = false;
  23. Reopen(options);
  24. ASSERT_OK(Put("foo", "v1"));
  25. ASSERT_EQ("v1", Get("foo"));
  26. Compact("a", "z");
  27. const size_t num_files = CountFiles();
  28. // Force out-of-space errors
  29. env_->drop_writes_.store(true, std::memory_order_release);
  30. env_->sleep_counter_.Reset();
  31. env_->no_slowdown_ = true;
  32. for (int i = 0; i < 5; i++) {
  33. if (option_config_ != kUniversalCompactionMultiLevel &&
  34. option_config_ != kUniversalSubcompactions) {
  35. for (int level = 0; level < dbfull()->NumberLevels(); level++) {
  36. if (level > 0 && level == dbfull()->NumberLevels() - 1) {
  37. break;
  38. }
  39. dbfull()->TEST_CompactRange(level, nullptr, nullptr, nullptr,
  40. true /* disallow trivial move */);
  41. }
  42. } else {
  43. dbfull()->CompactRange(CompactRangeOptions(), nullptr, nullptr);
  44. }
  45. }
  46. std::string property_value;
  47. ASSERT_TRUE(db_->GetProperty("rocksdb.background-errors", &property_value));
  48. ASSERT_EQ("5", property_value);
  49. env_->drop_writes_.store(false, std::memory_order_release);
  50. ASSERT_LT(CountFiles(), num_files + 3);
  51. // Check that compaction attempts slept after errors
  52. // TODO @krad: Figure out why ASSERT_EQ 5 keeps failing in certain compiler
  53. // versions
  54. ASSERT_GE(env_->sleep_counter_.Read(), 4);
  55. } while (ChangeCompactOptions());
  56. }
  57. // Check background error counter bumped on flush failures.
  58. TEST_F(DBIOFailureTest, DropWritesFlush) {
  59. do {
  60. Options options = CurrentOptions();
  61. options.env = env_;
  62. options.max_background_flushes = 1;
  63. Reopen(options);
  64. ASSERT_OK(Put("foo", "v1"));
  65. // Force out-of-space errors
  66. env_->drop_writes_.store(true, std::memory_order_release);
  67. std::string property_value;
  68. // Background error count is 0 now.
  69. ASSERT_TRUE(db_->GetProperty("rocksdb.background-errors", &property_value));
  70. ASSERT_EQ("0", property_value);
  71. dbfull()->TEST_FlushMemTable(true);
  72. ASSERT_TRUE(db_->GetProperty("rocksdb.background-errors", &property_value));
  73. ASSERT_EQ("1", property_value);
  74. env_->drop_writes_.store(false, std::memory_order_release);
  75. } while (ChangeCompactOptions());
  76. }
  77. // Check that CompactRange() returns failure if there is not enough space left
  78. // on device
  79. TEST_F(DBIOFailureTest, NoSpaceCompactRange) {
  80. do {
  81. Options options = CurrentOptions();
  82. options.env = env_;
  83. options.disable_auto_compactions = true;
  84. Reopen(options);
  85. // generate 5 tables
  86. for (int i = 0; i < 5; ++i) {
  87. ASSERT_OK(Put(Key(i), Key(i) + "v"));
  88. ASSERT_OK(Flush());
  89. }
  90. // Force out-of-space errors
  91. env_->no_space_.store(true, std::memory_order_release);
  92. Status s = dbfull()->TEST_CompactRange(0, nullptr, nullptr, nullptr,
  93. true /* disallow trivial move */);
  94. ASSERT_TRUE(s.IsIOError());
  95. ASSERT_TRUE(s.IsNoSpace());
  96. env_->no_space_.store(false, std::memory_order_release);
  97. } while (ChangeCompactOptions());
  98. }
  99. #endif // ROCKSDB_LITE
  100. TEST_F(DBIOFailureTest, NonWritableFileSystem) {
  101. do {
  102. Options options = CurrentOptions();
  103. options.write_buffer_size = 4096;
  104. options.arena_block_size = 4096;
  105. options.env = env_;
  106. Reopen(options);
  107. ASSERT_OK(Put("foo", "v1"));
  108. env_->non_writeable_rate_.store(100);
  109. std::string big(100000, 'x');
  110. int errors = 0;
  111. for (int i = 0; i < 20; i++) {
  112. if (!Put("foo", big).ok()) {
  113. errors++;
  114. env_->SleepForMicroseconds(100000);
  115. }
  116. }
  117. ASSERT_GT(errors, 0);
  118. env_->non_writeable_rate_.store(0);
  119. } while (ChangeCompactOptions());
  120. }
  121. #ifndef ROCKSDB_LITE
  122. TEST_F(DBIOFailureTest, ManifestWriteError) {
  123. // Test for the following problem:
  124. // (a) Compaction produces file F
  125. // (b) Log record containing F is written to MANIFEST file, but Sync() fails
  126. // (c) GC deletes F
  127. // (d) After reopening DB, reads fail since deleted F is named in log record
  128. // We iterate twice. In the second iteration, everything is the
  129. // same except the log record never makes it to the MANIFEST file.
  130. for (int iter = 0; iter < 2; iter++) {
  131. std::atomic<bool>* error_type = (iter == 0) ? &env_->manifest_sync_error_
  132. : &env_->manifest_write_error_;
  133. // Insert foo=>bar mapping
  134. Options options = CurrentOptions();
  135. options.env = env_;
  136. options.create_if_missing = true;
  137. options.error_if_exists = false;
  138. options.paranoid_checks = true;
  139. DestroyAndReopen(options);
  140. ASSERT_OK(Put("foo", "bar"));
  141. ASSERT_EQ("bar", Get("foo"));
  142. // Memtable compaction (will succeed)
  143. Flush();
  144. ASSERT_EQ("bar", Get("foo"));
  145. const int last = 2;
  146. MoveFilesToLevel(2);
  147. ASSERT_EQ(NumTableFilesAtLevel(last), 1); // foo=>bar is now in last level
  148. // Merging compaction (will fail)
  149. error_type->store(true, std::memory_order_release);
  150. dbfull()->TEST_CompactRange(last, nullptr, nullptr); // Should fail
  151. ASSERT_EQ("bar", Get("foo"));
  152. error_type->store(false, std::memory_order_release);
  153. // Since paranoid_checks=true, writes should fail
  154. ASSERT_NOK(Put("foo2", "bar2"));
  155. // Recovery: should not lose data
  156. ASSERT_EQ("bar", Get("foo"));
  157. // Try again with paranoid_checks=false
  158. Close();
  159. options.paranoid_checks = false;
  160. Reopen(options);
  161. // Merging compaction (will fail)
  162. error_type->store(true, std::memory_order_release);
  163. dbfull()->TEST_CompactRange(last, nullptr, nullptr); // Should fail
  164. ASSERT_EQ("bar", Get("foo"));
  165. // Recovery: should not lose data
  166. error_type->store(false, std::memory_order_release);
  167. Reopen(options);
  168. ASSERT_EQ("bar", Get("foo"));
  169. // Since paranoid_checks=false, writes should succeed
  170. ASSERT_OK(Put("foo2", "bar2"));
  171. ASSERT_EQ("bar", Get("foo"));
  172. ASSERT_EQ("bar2", Get("foo2"));
  173. }
  174. }
  175. TEST_F(DBIOFailureTest, PutFailsParanoid) {
  176. // Test the following:
  177. // (a) A random put fails in paranoid mode (simulate by sync fail)
  178. // (b) All other puts have to fail, even if writes would succeed
  179. // (c) All of that should happen ONLY if paranoid_checks = true
  180. Options options = CurrentOptions();
  181. options.env = env_;
  182. options.create_if_missing = true;
  183. options.error_if_exists = false;
  184. options.paranoid_checks = true;
  185. DestroyAndReopen(options);
  186. CreateAndReopenWithCF({"pikachu"}, options);
  187. Status s;
  188. ASSERT_OK(Put(1, "foo", "bar"));
  189. ASSERT_OK(Put(1, "foo1", "bar1"));
  190. // simulate error
  191. env_->log_write_error_.store(true, std::memory_order_release);
  192. s = Put(1, "foo2", "bar2");
  193. ASSERT_TRUE(!s.ok());
  194. env_->log_write_error_.store(false, std::memory_order_release);
  195. s = Put(1, "foo3", "bar3");
  196. // the next put should fail, too
  197. ASSERT_TRUE(!s.ok());
  198. // but we're still able to read
  199. ASSERT_EQ("bar", Get(1, "foo"));
  200. // do the same thing with paranoid checks off
  201. options.paranoid_checks = false;
  202. DestroyAndReopen(options);
  203. CreateAndReopenWithCF({"pikachu"}, options);
  204. ASSERT_OK(Put(1, "foo", "bar"));
  205. ASSERT_OK(Put(1, "foo1", "bar1"));
  206. // simulate error
  207. env_->log_write_error_.store(true, std::memory_order_release);
  208. s = Put(1, "foo2", "bar2");
  209. ASSERT_TRUE(!s.ok());
  210. env_->log_write_error_.store(false, std::memory_order_release);
  211. s = Put(1, "foo3", "bar3");
  212. // the next put should NOT fail
  213. ASSERT_TRUE(s.ok());
  214. }
  215. #if !(defined NDEBUG) || !defined(OS_WIN)
  216. TEST_F(DBIOFailureTest, FlushSstRangeSyncError) {
  217. Options options = CurrentOptions();
  218. options.env = env_;
  219. options.create_if_missing = true;
  220. options.error_if_exists = false;
  221. options.paranoid_checks = true;
  222. options.write_buffer_size = 256 * 1024 * 1024;
  223. options.writable_file_max_buffer_size = 128 * 1024;
  224. options.bytes_per_sync = 128 * 1024;
  225. options.level0_file_num_compaction_trigger = 4;
  226. options.memtable_factory.reset(new SpecialSkipListFactory(10));
  227. BlockBasedTableOptions table_options;
  228. table_options.filter_policy.reset(NewBloomFilterPolicy(10));
  229. options.table_factory.reset(NewBlockBasedTableFactory(table_options));
  230. DestroyAndReopen(options);
  231. CreateAndReopenWithCF({"pikachu"}, options);
  232. Status s;
  233. std::atomic<int> range_sync_called(0);
  234. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
  235. "SpecialEnv::SStableFile::RangeSync", [&](void* arg) {
  236. if (range_sync_called.fetch_add(1) == 0) {
  237. Status* st = static_cast<Status*>(arg);
  238. *st = Status::IOError("range sync dummy error");
  239. }
  240. });
  241. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
  242. Random rnd(301);
  243. std::string rnd_str =
  244. RandomString(&rnd, static_cast<int>(options.bytes_per_sync / 2));
  245. std::string rnd_str_512kb = RandomString(&rnd, 512 * 1024);
  246. ASSERT_OK(Put(1, "foo", "bar"));
  247. // First 1MB doesn't get range synced
  248. ASSERT_OK(Put(1, "foo0_0", rnd_str_512kb));
  249. ASSERT_OK(Put(1, "foo0_1", rnd_str_512kb));
  250. ASSERT_OK(Put(1, "foo1_1", rnd_str));
  251. ASSERT_OK(Put(1, "foo1_2", rnd_str));
  252. ASSERT_OK(Put(1, "foo1_3", rnd_str));
  253. ASSERT_OK(Put(1, "foo2", "bar"));
  254. ASSERT_OK(Put(1, "foo3_1", rnd_str));
  255. ASSERT_OK(Put(1, "foo3_2", rnd_str));
  256. ASSERT_OK(Put(1, "foo3_3", rnd_str));
  257. ASSERT_OK(Put(1, "foo4", "bar"));
  258. dbfull()->TEST_WaitForFlushMemTable(handles_[1]);
  259. // Following writes should fail as flush failed.
  260. ASSERT_NOK(Put(1, "foo2", "bar3"));
  261. ASSERT_EQ("bar", Get(1, "foo"));
  262. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
  263. ASSERT_GE(1, range_sync_called.load());
  264. ReopenWithColumnFamilies({"default", "pikachu"}, options);
  265. ASSERT_EQ("bar", Get(1, "foo"));
  266. }
  267. TEST_F(DBIOFailureTest, CompactSstRangeSyncError) {
  268. Options options = CurrentOptions();
  269. options.env = env_;
  270. options.create_if_missing = true;
  271. options.error_if_exists = false;
  272. options.paranoid_checks = true;
  273. options.write_buffer_size = 256 * 1024 * 1024;
  274. options.writable_file_max_buffer_size = 128 * 1024;
  275. options.bytes_per_sync = 128 * 1024;
  276. options.level0_file_num_compaction_trigger = 2;
  277. options.target_file_size_base = 256 * 1024 * 1024;
  278. options.disable_auto_compactions = true;
  279. BlockBasedTableOptions table_options;
  280. table_options.filter_policy.reset(NewBloomFilterPolicy(10));
  281. options.table_factory.reset(NewBlockBasedTableFactory(table_options));
  282. DestroyAndReopen(options);
  283. CreateAndReopenWithCF({"pikachu"}, options);
  284. Status s;
  285. Random rnd(301);
  286. std::string rnd_str =
  287. RandomString(&rnd, static_cast<int>(options.bytes_per_sync / 2));
  288. std::string rnd_str_512kb = RandomString(&rnd, 512 * 1024);
  289. ASSERT_OK(Put(1, "foo", "bar"));
  290. // First 1MB doesn't get range synced
  291. ASSERT_OK(Put(1, "foo0_0", rnd_str_512kb));
  292. ASSERT_OK(Put(1, "foo0_1", rnd_str_512kb));
  293. ASSERT_OK(Put(1, "foo1_1", rnd_str));
  294. ASSERT_OK(Put(1, "foo1_2", rnd_str));
  295. ASSERT_OK(Put(1, "foo1_3", rnd_str));
  296. Flush(1);
  297. ASSERT_OK(Put(1, "foo", "bar"));
  298. ASSERT_OK(Put(1, "foo3_1", rnd_str));
  299. ASSERT_OK(Put(1, "foo3_2", rnd_str));
  300. ASSERT_OK(Put(1, "foo3_3", rnd_str));
  301. ASSERT_OK(Put(1, "foo4", "bar"));
  302. Flush(1);
  303. dbfull()->TEST_WaitForFlushMemTable(handles_[1]);
  304. std::atomic<int> range_sync_called(0);
  305. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
  306. "SpecialEnv::SStableFile::RangeSync", [&](void* arg) {
  307. if (range_sync_called.fetch_add(1) == 0) {
  308. Status* st = static_cast<Status*>(arg);
  309. *st = Status::IOError("range sync dummy error");
  310. }
  311. });
  312. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
  313. ASSERT_OK(dbfull()->SetOptions(handles_[1],
  314. {
  315. {"disable_auto_compactions", "false"},
  316. }));
  317. dbfull()->TEST_WaitForCompact();
  318. // Following writes should fail as flush failed.
  319. ASSERT_NOK(Put(1, "foo2", "bar3"));
  320. ASSERT_EQ("bar", Get(1, "foo"));
  321. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
  322. ASSERT_GE(1, range_sync_called.load());
  323. ReopenWithColumnFamilies({"default", "pikachu"}, options);
  324. ASSERT_EQ("bar", Get(1, "foo"));
  325. }
  326. TEST_F(DBIOFailureTest, FlushSstCloseError) {
  327. Options options = CurrentOptions();
  328. options.env = env_;
  329. options.create_if_missing = true;
  330. options.error_if_exists = false;
  331. options.paranoid_checks = true;
  332. options.level0_file_num_compaction_trigger = 4;
  333. options.memtable_factory.reset(new SpecialSkipListFactory(2));
  334. DestroyAndReopen(options);
  335. CreateAndReopenWithCF({"pikachu"}, options);
  336. Status s;
  337. std::atomic<int> close_called(0);
  338. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
  339. "SpecialEnv::SStableFile::Close", [&](void* arg) {
  340. if (close_called.fetch_add(1) == 0) {
  341. Status* st = static_cast<Status*>(arg);
  342. *st = Status::IOError("close dummy error");
  343. }
  344. });
  345. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
  346. ASSERT_OK(Put(1, "foo", "bar"));
  347. ASSERT_OK(Put(1, "foo1", "bar1"));
  348. ASSERT_OK(Put(1, "foo", "bar2"));
  349. dbfull()->TEST_WaitForFlushMemTable(handles_[1]);
  350. // Following writes should fail as flush failed.
  351. ASSERT_NOK(Put(1, "foo2", "bar3"));
  352. ASSERT_EQ("bar2", Get(1, "foo"));
  353. ASSERT_EQ("bar1", Get(1, "foo1"));
  354. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
  355. ReopenWithColumnFamilies({"default", "pikachu"}, options);
  356. ASSERT_EQ("bar2", Get(1, "foo"));
  357. ASSERT_EQ("bar1", Get(1, "foo1"));
  358. }
  359. TEST_F(DBIOFailureTest, CompactionSstCloseError) {
  360. Options options = CurrentOptions();
  361. options.env = env_;
  362. options.create_if_missing = true;
  363. options.error_if_exists = false;
  364. options.paranoid_checks = true;
  365. options.level0_file_num_compaction_trigger = 2;
  366. options.disable_auto_compactions = true;
  367. DestroyAndReopen(options);
  368. CreateAndReopenWithCF({"pikachu"}, options);
  369. Status s;
  370. ASSERT_OK(Put(1, "foo", "bar"));
  371. ASSERT_OK(Put(1, "foo2", "bar"));
  372. Flush(1);
  373. ASSERT_OK(Put(1, "foo", "bar2"));
  374. ASSERT_OK(Put(1, "foo2", "bar"));
  375. Flush(1);
  376. ASSERT_OK(Put(1, "foo", "bar3"));
  377. ASSERT_OK(Put(1, "foo2", "bar"));
  378. Flush(1);
  379. dbfull()->TEST_WaitForCompact();
  380. std::atomic<int> close_called(0);
  381. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
  382. "SpecialEnv::SStableFile::Close", [&](void* arg) {
  383. if (close_called.fetch_add(1) == 0) {
  384. Status* st = static_cast<Status*>(arg);
  385. *st = Status::IOError("close dummy error");
  386. }
  387. });
  388. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
  389. ASSERT_OK(dbfull()->SetOptions(handles_[1],
  390. {
  391. {"disable_auto_compactions", "false"},
  392. }));
  393. dbfull()->TEST_WaitForCompact();
  394. // Following writes should fail as compaction failed.
  395. ASSERT_NOK(Put(1, "foo2", "bar3"));
  396. ASSERT_EQ("bar3", Get(1, "foo"));
  397. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
  398. ReopenWithColumnFamilies({"default", "pikachu"}, options);
  399. ASSERT_EQ("bar3", Get(1, "foo"));
  400. }
  401. TEST_F(DBIOFailureTest, FlushSstSyncError) {
  402. Options options = CurrentOptions();
  403. options.env = env_;
  404. options.create_if_missing = true;
  405. options.error_if_exists = false;
  406. options.paranoid_checks = true;
  407. options.use_fsync = false;
  408. options.level0_file_num_compaction_trigger = 4;
  409. options.memtable_factory.reset(new SpecialSkipListFactory(2));
  410. DestroyAndReopen(options);
  411. CreateAndReopenWithCF({"pikachu"}, options);
  412. Status s;
  413. std::atomic<int> sync_called(0);
  414. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
  415. "SpecialEnv::SStableFile::Sync", [&](void* arg) {
  416. if (sync_called.fetch_add(1) == 0) {
  417. Status* st = static_cast<Status*>(arg);
  418. *st = Status::IOError("sync dummy error");
  419. }
  420. });
  421. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
  422. ASSERT_OK(Put(1, "foo", "bar"));
  423. ASSERT_OK(Put(1, "foo1", "bar1"));
  424. ASSERT_OK(Put(1, "foo", "bar2"));
  425. dbfull()->TEST_WaitForFlushMemTable(handles_[1]);
  426. // Following writes should fail as flush failed.
  427. ASSERT_NOK(Put(1, "foo2", "bar3"));
  428. ASSERT_EQ("bar2", Get(1, "foo"));
  429. ASSERT_EQ("bar1", Get(1, "foo1"));
  430. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
  431. ReopenWithColumnFamilies({"default", "pikachu"}, options);
  432. ASSERT_EQ("bar2", Get(1, "foo"));
  433. ASSERT_EQ("bar1", Get(1, "foo1"));
  434. }
  435. TEST_F(DBIOFailureTest, CompactionSstSyncError) {
  436. Options options = CurrentOptions();
  437. options.env = env_;
  438. options.create_if_missing = true;
  439. options.error_if_exists = false;
  440. options.paranoid_checks = true;
  441. options.level0_file_num_compaction_trigger = 2;
  442. options.disable_auto_compactions = true;
  443. options.use_fsync = false;
  444. DestroyAndReopen(options);
  445. CreateAndReopenWithCF({"pikachu"}, options);
  446. Status s;
  447. ASSERT_OK(Put(1, "foo", "bar"));
  448. ASSERT_OK(Put(1, "foo2", "bar"));
  449. Flush(1);
  450. ASSERT_OK(Put(1, "foo", "bar2"));
  451. ASSERT_OK(Put(1, "foo2", "bar"));
  452. Flush(1);
  453. ASSERT_OK(Put(1, "foo", "bar3"));
  454. ASSERT_OK(Put(1, "foo2", "bar"));
  455. Flush(1);
  456. dbfull()->TEST_WaitForCompact();
  457. std::atomic<int> sync_called(0);
  458. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->SetCallBack(
  459. "SpecialEnv::SStableFile::Sync", [&](void* arg) {
  460. if (sync_called.fetch_add(1) == 0) {
  461. Status* st = static_cast<Status*>(arg);
  462. *st = Status::IOError("close dummy error");
  463. }
  464. });
  465. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->EnableProcessing();
  466. ASSERT_OK(dbfull()->SetOptions(handles_[1],
  467. {
  468. {"disable_auto_compactions", "false"},
  469. }));
  470. dbfull()->TEST_WaitForCompact();
  471. // Following writes should fail as compaction failed.
  472. ASSERT_NOK(Put(1, "foo2", "bar3"));
  473. ASSERT_EQ("bar3", Get(1, "foo"));
  474. ROCKSDB_NAMESPACE::SyncPoint::GetInstance()->DisableProcessing();
  475. ReopenWithColumnFamilies({"default", "pikachu"}, options);
  476. ASSERT_EQ("bar3", Get(1, "foo"));
  477. }
  478. #endif // !(defined NDEBUG) || !defined(OS_WIN)
  479. #endif // ROCKSDB_LITE
  480. } // namespace ROCKSDB_NAMESPACE
  481. int main(int argc, char** argv) {
  482. ROCKSDB_NAMESPACE::port::InstallStackTraceHandler();
  483. ::testing::InitGoogleTest(&argc, argv);
  484. return RUN_ALL_TESTS();
  485. }