From: Igor Fedotov Date: Wed, 18 Mar 2020 11:51:47 +0000 (+0300) Subject: os/bluestore: avoid bluefs log compaction when doing cold_close X-Git-Tag: v16.1.0~2616^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=db6f3f66fcc28c3db2eba01611664676a820cb90;p=ceph.git os/bluestore: avoid bluefs log compaction when doing cold_close Signed-off-by: Igor Fedotov --- diff --git a/src/os/bluestore/BlueFS.cc b/src/os/bluestore/BlueFS.cc index 0b1b998d9732..b20720da350f 100644 --- a/src/os/bluestore/BlueFS.cc +++ b/src/os/bluestore/BlueFS.cc @@ -710,11 +710,11 @@ int BlueFS::maybe_verify_layout(const bluefs_layout_t& layout) const return 0; } -void BlueFS::umount() +void BlueFS::umount(bool avoid_compact) { dout(1) << __func__ << dendl; - sync_metadata(); + sync_metadata(avoid_compact); _close_writer(log_writer); log_writer = NULL; @@ -3193,7 +3193,7 @@ int BlueFS::_preallocate(FileRef f, uint64_t off, uint64_t len) return 0; } -void BlueFS::sync_metadata() +void BlueFS::sync_metadata(bool avoid_compact) { std::unique_lock l(lock); if (log_t.empty() && dirty_files.empty()) { @@ -3206,7 +3206,7 @@ void BlueFS::sync_metadata() dout(10) << __func__ << " done in " << (ceph_clock_now() - start) << dendl; } - if (_should_compact_log()) { + if (!avoid_compact && _should_compact_log()) { if (cct->_conf->bluefs_compact_log_sync) { _compact_log_sync(); } else { diff --git a/src/os/bluestore/BlueFS.h b/src/os/bluestore/BlueFS.h index f6605d5a464e..62f59ab31466 100644 --- a/src/os/bluestore/BlueFS.h +++ b/src/os/bluestore/BlueFS.h @@ -443,7 +443,7 @@ public: int mkfs(uuid_d osd_uuid, const bluefs_layout_t& layout); int mount(); int maybe_verify_layout(const bluefs_layout_t& layout) const; - void umount(); + void umount(bool avoid_compact = false); int prepare_new_device(int id, const bluefs_layout_t& layout); int log_dump(); @@ -514,7 +514,7 @@ public: void compact_log(); /// sync any uncommitted state to disk - void sync_metadata(); + void sync_metadata(bool avoid_compact); void set_slow_device_expander(BlueFSDeviceExpander* a) { slow_dev_expander = a; diff --git a/src/os/bluestore/BlueRocksEnv.cc b/src/os/bluestore/BlueRocksEnv.cc index 7f2f8991b9e1..51614c09d2cd 100644 --- a/src/os/bluestore/BlueRocksEnv.cc +++ b/src/os/bluestore/BlueRocksEnv.cc @@ -299,7 +299,7 @@ class BlueRocksDirectory : public rocksdb::Directory { // Fsync directory. Can be called concurrently from multiple threads. rocksdb::Status Fsync() override { // it is sufficient to flush the log. - fs->sync_metadata(); + fs->sync_metadata(false); return rocksdb::Status::OK(); } }; diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index 42bd5c5360cf..995a39a9eabd 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -5481,9 +5481,9 @@ int BlueStore::_open_bluefs(bool create) return r; } -void BlueStore::_close_bluefs() +void BlueStore::_close_bluefs(bool cold_close) { - bluefs->umount(); + bluefs->umount(cold_close); _minimal_close_bluefs(); } @@ -5548,7 +5548,7 @@ int BlueStore::_open_db_and_around(bool read_only) // now open in R/W mode if (!read_only) { - _close_db(); + _close_db(true); r = _open_db(false, false, false); if (r < 0) { @@ -5580,18 +5580,18 @@ int BlueStore::_open_db_and_around(bool read_only) out_fm: _close_fm(); out_db: - _close_db(); + _close_db(read_only); return r; } -void BlueStore::_close_db_and_around() +void BlueStore::_close_db_and_around(bool read_only) { if (bluefs) { - if (out_of_sync_fm.fetch_and(0)) { + if (!read_only && out_of_sync_fm.fetch_and(0)) { _sync_bluefs_and_fm(); } - _close_db(); - while(out_of_sync_fm.fetch_and(0)) { + _close_db(read_only); + while(!read_only && out_of_sync_fm.fetch_and(0)) { // if seen some allocations during close - repeat open_db, sync fm, close dout(0) << __func__ << " syncing FreelistManager" << dendl; int r = _open_db(false, false, false); @@ -5602,7 +5602,7 @@ void BlueStore::_close_db_and_around() break; } _sync_bluefs_and_fm(); - _close_db(); + _close_db(false); } if (!_kv_only) { _close_alloc(); @@ -5611,7 +5611,7 @@ void BlueStore::_close_db_and_around() } else { _close_alloc(); _close_fm(); - _close_db(); + _close_db(read_only); } } @@ -5779,7 +5779,7 @@ int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only) if (!db) { derr << __func__ << " error creating db" << dendl; if (bluefs) { - _close_bluefs(); + _close_bluefs(read_only); } // delete env manually here since we can't depend on db to do this // under this case @@ -5824,7 +5824,7 @@ int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only) } if (r) { derr << __func__ << " erroring opening db: " << err.str() << dendl; - _close_db(); + _close_db(read_only); return -EIO; } dout(1) << __func__ << " opened " << kv_backend @@ -5832,13 +5832,13 @@ int BlueStore::_open_db(bool create, bool to_repair_db, bool read_only) return 0; } -void BlueStore::_close_db() +void BlueStore::_close_db(bool cold_close) { ceph_assert(db); delete db; db = NULL; if (bluefs) { - _close_bluefs(); + _close_bluefs(cold_close); } } @@ -6469,7 +6469,7 @@ int BlueStore::mkfs() out_close_fm: _close_fm(); out_close_db: - _close_db(); + _close_db(false); out_close_bdev: _close_bdev(); out_close_fsid: @@ -6518,7 +6518,7 @@ int BlueStore::_mount_for_bluefs() void BlueStore::_umount_for_bluefs() { - _close_bluefs(); + _close_bluefs(false); _close_fsid(); _close_path(); } @@ -7057,7 +7057,7 @@ int BlueStore::_mount(bool kv_only, bool open_db) out_coll: _flush_cache(); out_db: - _close_db_and_around(); + _close_db_and_around(false); out_bdev: _close_bdev(); out_fsid: @@ -7083,7 +7083,7 @@ int BlueStore::umount() dout(20) << __func__ << " closing" << dendl; } - _close_db_and_around(); + _close_db_and_around(false); _close_bdev(); _close_fsid(); _close_path(); @@ -7135,7 +7135,7 @@ int BlueStore::cold_open() } int BlueStore::cold_close() { - _close_db_and_around(); + _close_db_and_around(true); _close_bdev(); _close_fsid(); _close_path(); @@ -8201,7 +8201,7 @@ out_scan: mempool_thread.shutdown(); _flush_cache(); out_db: - _close_db_and_around(); + _close_db_and_around(false); out_bdev: _close_bdev(); out_fsid: @@ -8290,8 +8290,7 @@ int BlueStore::_fsck_on_open(BlueStore::FSCKDepth depth, bool repair) e.get_start(), e.get_len(), fm->get_alloc_size(), used_blocks, [&](uint64_t pos, mempool_dynamic_bitset &bs) { bs.set(pos); - } - ); + }); } int r = bluefs->fsck(); if (r < 0) { diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index cffcba03fd1c..e95fafa5d954 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -2244,7 +2244,7 @@ private: int _minimal_open_bluefs(bool create); void _minimal_close_bluefs(); int _open_bluefs(bool create); - void _close_bluefs(); + void _close_bluefs(bool cold_close); // Limited (u)mount intended for BlueFS operations only int _mount_for_bluefs(); @@ -2257,7 +2257,7 @@ private: * in the proper order */ int _open_db_and_around(bool read_only); - void _close_db_and_around(); + void _close_db_and_around(bool read_only); // updates legacy bluefs related recs in DB to a state valid for // downgrades from nautilus. @@ -2270,7 +2270,7 @@ private: int _open_db(bool create, bool to_repair_db=false, bool read_only = false); - void _close_db(); + void _close_db(bool read_only); int _open_fm(KeyValueDB::Transaction t); void _close_fm(); int _open_alloc(); diff --git a/src/test/objectstore/test_bluefs.cc b/src/test/objectstore/test_bluefs.cc index ef838ab124f2..f6e47950b501 100644 --- a/src/test/objectstore/test_bluefs.cc +++ b/src/test/objectstore/test_bluefs.cc @@ -339,7 +339,7 @@ void sync_fs(BlueFS &fs) while (1) { if (writes_done == true) break; - fs.sync_metadata(); + fs.sync_metadata(false); sleep(1); } } @@ -502,10 +502,10 @@ TEST(BlueFS, test_simple_compaction_sync) { string file = "file."; file.append(to_string(j)); fs.unlink(dir, file); - fs.sync_metadata(); + fs.sync_metadata(false); } ASSERT_EQ(0, fs.rmdir(dir)); - fs.sync_metadata(); + fs.sync_metadata(false); } } fs.compact_log(); @@ -555,10 +555,10 @@ TEST(BlueFS, test_simple_compaction_async) { string file = "file."; file.append(to_string(j)); fs.unlink(dir, file); - fs.sync_metadata(); + fs.sync_metadata(false); } ASSERT_EQ(0, fs.rmdir(dir)); - fs.sync_metadata(); + fs.sync_metadata(false); } } fs.compact_log();