Skip to content

Commit

Permalink
librbd: flush journal commit position after stopping replay
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit bcfcbcf)
  • Loading branch information
Jason Dillaman authored and Prashant D committed Feb 16, 2018
1 parent 3e86319 commit d501e0a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/librbd/Journal.cc
Expand Up @@ -1302,6 +1302,10 @@ void Journal<I>::handle_replay_complete(int r) {
handle_flushing_replay();
}
});
ctx = new FunctionContext([this, ctx](int r) {
// ensure the commit position is flushed to disk
m_journaler->flush_commit_position(ctx);
});
ctx = new FunctionContext([this, cct, cancel_ops, ctx](int r) {
ldout(cct, 20) << this << " handle_replay_complete: "
<< "shut down replay" << dendl;
Expand Down Expand Up @@ -1348,16 +1352,21 @@ void Journal<I>::handle_replay_process_safe(ReplayEntry replay_entry, int r) {
m_lock.Unlock();

// stop replay, shut down, and restart
Context *ctx = new FunctionContext([this, cct](int r) {
Context* ctx = create_context_callback<
Journal<I>, &Journal<I>::handle_flushing_restart>(this);
ctx = new FunctionContext([this, ctx](int r) {
// ensure the commit position is flushed to disk
m_journaler->flush_commit_position(ctx);
});
ctx = new FunctionContext([this, cct, ctx](int r) {
ldout(cct, 20) << this << " handle_replay_process_safe: "
<< "shut down replay" << dendl;
{
Mutex::Locker locker(m_lock);
assert(m_state == STATE_FLUSHING_RESTART);
}

m_journal_replay->shut_down(true, create_context_callback<
Journal<I>, &Journal<I>::handle_flushing_restart>(this));
m_journal_replay->shut_down(true, ctx);
});
m_journaler->stop_replay(ctx);
return;
Expand Down
13 changes: 13 additions & 0 deletions src/test/librbd/test_mock_Journal.cc
Expand Up @@ -488,6 +488,7 @@ class TestMockJournal : public TestMockFixture {
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_committed(mock_journaler, 0);
expect_flush_commit_position(mock_journaler);
expect_start_append(mock_journaler);
ASSERT_EQ(0, when_open(mock_journal));
}
Expand Down Expand Up @@ -548,6 +549,7 @@ TEST_F(TestMockJournal, StateTransitions) {
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_committed(mock_journaler, 3);
expect_flush_commit_position(mock_journaler);

expect_start_append(mock_journaler);

Expand Down Expand Up @@ -604,6 +606,7 @@ TEST_F(TestMockJournal, ReplayCompleteError) {
MockJournalReplay mock_journal_replay;
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0, true);
expect_flush_commit_position(mock_journaler);
expect_shut_down_journaler(mock_journaler);

// replay failure should result in replay-restart
Expand All @@ -617,6 +620,7 @@ TEST_F(TestMockJournal, ReplayCompleteError) {

expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_flush_commit_position(mock_journaler);
expect_start_append(mock_journaler);
ASSERT_EQ(0, when_open(mock_journal));

Expand Down Expand Up @@ -655,6 +659,7 @@ TEST_F(TestMockJournal, FlushReplayError) {
std::bind(&invoke_replay_complete, _1, 0));
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, -EINVAL);
expect_flush_commit_position(mock_journaler);
expect_shut_down_journaler(mock_journaler);

// replay flush failure should result in replay-restart
Expand All @@ -668,6 +673,7 @@ TEST_F(TestMockJournal, FlushReplayError) {

expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_flush_commit_position(mock_journaler);
expect_start_append(mock_journaler);
ASSERT_EQ(0, when_open(mock_journal));

Expand Down Expand Up @@ -704,6 +710,7 @@ TEST_F(TestMockJournal, CorruptEntry) {
EXPECT_CALL(mock_journal_replay, decode(_, _)).WillOnce(Return(-EBADMSG));
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0, true);
expect_flush_commit_position(mock_journaler);
expect_shut_down_journaler(mock_journaler);

// replay failure should result in replay-restart
Expand All @@ -716,6 +723,7 @@ TEST_F(TestMockJournal, CorruptEntry) {
std::bind(&invoke_replay_complete, _1, 0));
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_flush_commit_position(mock_journaler);
expect_start_append(mock_journaler);
ASSERT_EQ(0, when_open(mock_journal));

Expand Down Expand Up @@ -749,6 +757,7 @@ TEST_F(TestMockJournal, StopError) {
MockJournalReplay mock_journal_replay;
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_flush_commit_position(mock_journaler);
expect_start_append(mock_journaler);
ASSERT_EQ(0, when_open(mock_journal));

Expand Down Expand Up @@ -794,6 +803,7 @@ TEST_F(TestMockJournal, ReplayOnDiskPreFlushError) {
mock_replay_entry);
expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0, true);
expect_flush_commit_position(mock_journaler);
expect_shut_down_journaler(mock_journaler);

// replay write-to-disk failure should result in replay-restart
Expand All @@ -808,6 +818,7 @@ TEST_F(TestMockJournal, ReplayOnDiskPreFlushError) {

expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_flush_commit_position(mock_journaler);
expect_start_append(mock_journaler);

C_SaferCond ctx;
Expand Down Expand Up @@ -871,6 +882,7 @@ TEST_F(TestMockJournal, ReplayOnDiskPostFlushError) {
EXPECT_CALL(mock_journal_replay, shut_down(false, _))
.WillOnce(DoAll(SaveArg<1>(&on_flush),
InvokeWithoutArgs(this, &TestMockJournal::wake_up)));
expect_flush_commit_position(mock_journaler);

// replay write-to-disk failure should result in replay-restart
expect_shut_down_journaler(mock_journaler);
Expand All @@ -884,6 +896,7 @@ TEST_F(TestMockJournal, ReplayOnDiskPostFlushError) {

expect_stop_replay(mock_journaler);
expect_shut_down_replay(mock_image_ctx, mock_journal_replay, 0);
expect_flush_commit_position(mock_journaler);
expect_start_append(mock_journaler);

C_SaferCond ctx;
Expand Down

0 comments on commit d501e0a

Please sign in to comment.