Skip to content

Commit caa77ed

Browse files
committed
Revert "os/bluestore: Split _deferred_replay into 1) apply IO and 2) remove keys"
This reverts commit f2b33bc. Signed-off-by: Matan Breizman <[email protected]>
1 parent d2b4948 commit caa77ed

File tree

2 files changed

+57
-64
lines changed

2 files changed

+57
-64
lines changed

src/os/bluestore/BlueStore.cc

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7769,19 +7769,9 @@ int BlueStore::_is_bluefs(bool create, bool* ret)
77697769
* opens both DB and dependant super_meta, FreelistManager and allocator
77707770
* in the proper order
77717771
*/
7772-
int BlueStore::_open_db_and_around(
7773-
bool read_only,
7774-
bool to_repair,
7775-
bool apply_deferred,
7776-
bool remove_deferred)
7777-
{
7778-
dout(5) << __func__ << "read_only=" << read_only
7779-
<< ", to_repair=" << to_repair
7780-
<< ", deferred=" << (apply_deferred?"apply;":"noapply;")
7781-
<< (remove_deferred?"remove":"noremove") << dendl;
7782-
ceph_assert(remove_deferred == false || apply_deferred == true);
7783-
ceph_assert(read_only == false || remove_deferred == false);
7784-
std::vector<std::string> keys_to_remove;
7772+
int BlueStore::_open_db_and_around(bool read_only, bool to_repair)
7773+
{
7774+
dout(5) << __func__ << "::NCB::read_only=" << read_only << ", to_repair=" << to_repair << dendl;
77857775
{
77867776
string type;
77877777
int r = read_meta("type", &type);
@@ -7841,11 +7831,6 @@ int BlueStore::_open_db_and_around(
78417831
if (bdev_label_multi) {
78427832
_main_bdev_label_try_reserve();
78437833
}
7844-
// This is the place where we can apply deferred writes
7845-
// without risk of some interaction with RocksDB allocating.
7846-
if (apply_deferred) {
7847-
_deferred_replay(remove_deferred ? &keys_to_remove : nullptr);
7848-
}
78497834

78507835
// Re-open in the proper mode(s).
78517836

@@ -7863,14 +7848,6 @@ int BlueStore::_open_db_and_around(
78637848
_post_init_alloc();
78647849
}
78657850

7866-
if (remove_deferred && !keys_to_remove.empty()) {
7867-
KeyValueDB::Transaction deferred_keys_remove_txn = db->get_transaction();
7868-
for (auto& s : keys_to_remove) {
7869-
deferred_keys_remove_txn->rmkey(PREFIX_DEFERRED, s);
7870-
}
7871-
db->submit_transaction_sync(deferred_keys_remove_txn);
7872-
}
7873-
78747851
// when function is called in repair mode (to_repair=true) we skip db->open()/create()
78757852
// we can't change bluestore allocation so no need to invlidate allocation-file
78767853
if (fm->is_null_manager() && !read_only && !to_repair) {
@@ -9252,7 +9229,7 @@ int BlueStore::mount_readonly()
92529229
}
92539230
});
92549231

9255-
r = _deferred_replay(nullptr);
9232+
r = _deferred_replay();
92569233
if (r < 0) {
92579234
return r;
92589235
}
@@ -9388,7 +9365,8 @@ int BlueStore::_mount()
93889365
return -EINVAL;
93899366
}
93909367

9391-
int r = _open_db_and_around(false, false, true, true);
9368+
dout(5) << __func__ << "::NCB::calling open_db_and_around(read/write)" << dendl;
9369+
int r = _open_db_and_around(false);
93929370
if (r < 0) {
93939371
return r;
93949372
}
@@ -9426,6 +9404,11 @@ int BlueStore::_mount()
94269404
}
94279405
});
94289406

9407+
r = _deferred_replay();
9408+
if (r < 0) {
9409+
return r;
9410+
}
9411+
94299412
mempool_thread.init();
94309413

94319414
if ((!per_pool_stat_collection || per_pool_omap != OMAP_PER_PG) &&
@@ -10781,7 +10764,7 @@ int BlueStore::_fsck(BlueStore::FSCKDepth depth, bool repair)
1078110764

1078210765
// in deep mode we need R/W write access to be able to replay deferred ops
1078310766
const bool read_only = !(repair || depth == FSCK_DEEP);
10784-
int r = _open_db_and_around(read_only, false, !read_only, !read_only);
10767+
int r = _open_db_and_around(read_only);
1078510768
if (r < 0) {
1078610769
return r;
1078710770
}
@@ -10807,6 +10790,17 @@ int BlueStore::_fsck(BlueStore::FSCKDepth depth, bool repair)
1080710790
mempool_thread.shutdown();
1080810791
_shutdown_cache();
1080910792
});
10793+
// we need finisher and kv_{sync,finalize}_thread *just* for replay
10794+
// enable in repair or deep mode modes only
10795+
if (!read_only) {
10796+
_kv_start();
10797+
r = _deferred_replay();
10798+
_kv_stop();
10799+
}
10800+
10801+
if (r < 0) {
10802+
return r;
10803+
}
1081010804
return _fsck_on_open(depth, repair);
1081110805
}
1081210806

@@ -14959,7 +14953,6 @@ void BlueStore::_kv_sync_thread()
1495914953
deque<DeferredBatch*> deferred_stable_queue; ///< deferred ios done + stable
1496014954
std::unique_lock l{kv_lock};
1496114955
ceph_assert(!kv_sync_started);
14962-
ceph_assert(!db_was_opened_read_only);
1496314956
kv_sync_started = true;
1496414957
kv_cond.notify_all();
1496514958

@@ -15511,7 +15504,7 @@ void BlueStore::_deferred_aio_finish(OpSequencer *osr)
1551115504
}
1551215505
}
1551315506

15514-
int BlueStore::_deferred_replay(std::vector<std::string>* keys_to_remove)
15507+
int BlueStore::_deferred_replay()
1551515508
{
1551615509
dout(10) << __func__ << " start" << dendl;
1551715510
int count = 0;
@@ -15527,46 +15520,50 @@ int BlueStore::_deferred_replay(std::vector<std::string>* keys_to_remove)
1552715520
}
1552815521
if (tracepoint_debug_deferred_replay_start) tracepoint_debug_deferred_replay_start();
1552915522
IOContext ioctx(cct, nullptr);
15523+
KeyValueDB::Transaction t = db->get_transaction();
1553015524
KeyValueDB::Iterator it = db->get_iterator(PREFIX_DEFERRED);
15531-
for (it->lower_bound(string()); it->valid(); /*iterator update outside*/) {
15525+
for (it->lower_bound(string()); it->valid(); it->next(), ++count) {
1553215526
dout(20) << __func__ << " replay " << pretty_binary_string(it->key())
1553315527
<< dendl;
15534-
if (keys_to_remove) {
15535-
keys_to_remove->push_back(it->key());
15536-
}
15537-
bluestore_deferred_transaction_t deferred_txn;
15528+
t->rmkey(PREFIX_DEFERRED, it->key());
15529+
bluestore_deferred_transaction_t *deferred_txn =
15530+
new bluestore_deferred_transaction_t;
1553815531
bufferlist bl = it->value();
1553915532
auto p = bl.cbegin();
1554015533
try {
15541-
decode(deferred_txn, p);
15542-
15543-
bool has_some = _eliminate_outdated_deferred(&deferred_txn, bluefs_extents);
15544-
if (has_some) {
15545-
if (tracepoint_debug_deferred_replay_track) tracepoint_debug_deferred_replay_track(deferred_txn);
15546-
for (auto& op: deferred_txn.ops) {
15547-
for (auto& e : op.extents) {
15548-
bufferlist t;
15549-
op.data.splice(0, e.length, &t);
15550-
bdev->aio_write(e.offset, t, &ioctx, false);
15551-
}
15552-
}
15553-
}
15534+
decode(*deferred_txn, p);
1555415535
} catch (ceph::buffer::error& e) {
1555515536
derr << __func__ << " failed to decode deferred txn "
1555615537
<< pretty_binary_string(it->key()) << dendl;
15538+
delete deferred_txn;
1555715539
r = -EIO;
15540+
goto out;
1555815541
}
15559-
// update loop iteration here, so we can inject action
15560-
++count;
15561-
it->next();
15562-
if (ioctx.num_pending.load() > 100 || !it->valid()) {
15563-
dout(20) << __func__ << "submitting IO batch" << dendl;
15564-
bdev->aio_submit(&ioctx);
15565-
ioctx.aio_wait();
15566-
dout(20) << __func__ << "wait done" << dendl;
15567-
ioctx.release_running_aios();
15542+
bool has_some = _eliminate_outdated_deferred(deferred_txn, bluefs_extents);
15543+
if (has_some) {
15544+
if (tracepoint_debug_deferred_replay_track) tracepoint_debug_deferred_replay_track(*deferred_txn);
15545+
for (auto& op: deferred_txn->ops) {
15546+
for (auto& e : op.extents) {
15547+
bufferlist t;
15548+
op.data.splice(0, e.length, &t);
15549+
bdev->aio_write(e.offset, t, &ioctx, false);
15550+
}
15551+
}
15552+
} else {
15553+
delete deferred_txn;
1556815554
}
1556915555
}
15556+
out:
15557+
bdev->aio_submit(&ioctx);
15558+
dout(20) << __func__ << "waiting to complete IO" << dendl;
15559+
ioctx.aio_wait();
15560+
dout(20) << __func__ << "wait done" << dendl;
15561+
if (!db_was_opened_read_only) {
15562+
db->submit_transaction_sync(t);
15563+
dout(20) << __func__ << "removed L keys" << dendl;
15564+
} else {
15565+
dout(10) << __func__ << "DB read-pnly, skipped L keys removal" << dendl;
15566+
}
1557015567
if (tracepoint_debug_deferred_replay_end) tracepoint_debug_deferred_replay_end();
1557115568
dout(10) << __func__ << " completed " << count << " events" << dendl;
1557215569
return r;

src/os/bluestore/BlueStore.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,11 +2833,7 @@ class BlueStore : public ObjectStore,
28332833
* opens both DB and dependant super_meta, FreelistManager and allocator
28342834
* in the proper order
28352835
*/
2836-
int _open_db_and_around(
2837-
bool read_only,
2838-
bool to_repair = false,
2839-
bool apply_deferred = false,
2840-
bool remove_deferred = false);
2836+
int _open_db_and_around(bool read_only, bool to_repair = false);
28412837
void _close_db_and_around();
28422838
void _close_around_db();
28432839

@@ -2961,7 +2957,7 @@ class BlueStore : public ObjectStore,
29612957
private:
29622958
void _deferred_submit_unlock(OpSequencer *osr);
29632959
void _deferred_aio_finish(OpSequencer *osr);
2964-
int _deferred_replay(std::vector<std::string>* keys_to_remove);
2960+
int _deferred_replay();
29652961
bool _eliminate_outdated_deferred(bluestore_deferred_transaction_t* deferred_txn,
29662962
interval_set<uint64_t>& bluefs_extents);
29672963

0 commit comments

Comments
 (0)