Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rollback when rollback to tail_lsn. #532

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "6.4.53"
version = "6.4.54"

homepage = "https://github.com/eBay/Homestore"
description = "HomeStore Storage Engine"
Expand Down
1 change: 1 addition & 0 deletions src/include/homestore/logstore/log_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ class HomeLogStore : public std::enable_shared_from_this< HomeLogStore > {
* @brief Rollback the given instance to the given sequence number
*
* @param to_lsn Sequence number back which logs are to be rollbacked
* the to_lsn will be the tail_lsn after rollback.
* @return True on success
*/
bool rollback(logstore_seq_num_t to_lsn);
Expand Down
12 changes: 8 additions & 4 deletions src/lib/logstore/log_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,17 @@ void HomeLogStore::flush(logstore_seq_num_t upto_lsn) {
}

bool HomeLogStore::rollback(logstore_seq_num_t to_lsn) {
// Validate if the lsn to which it is rolledback to is not truncated.
auto ret = m_records.status(to_lsn + 1);
if (ret.is_out_of_range) {
HS_LOG_ASSERT(false, "Attempted to rollback to {} which is already truncated", to_lsn);
//Fast path
if (to_lsn == m_tail_lsn.load()) {
return true;
}

if (to_lsn > m_tail_lsn.load() || to_lsn < m_start_lsn.load()) {
HS_LOG_ASSERT(false, "Attempted to rollback to {} which is not in the range of [{}, {}]", to_lsn, m_start_lsn.load(), m_tail_lsn.load());
return false;
}

Copy link
Contributor

@yamingk yamingk Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we also have an assert here for HS_DEBUG_ASSERT(m_records.status(to_lsn + 1).is_out_of_range == false)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are two angle,

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the sisl one can be take as a bug, IMO.

THIS_LOGSTORE_LOG(INFO, "Rolling back to {}, tail {}", to_lsn, m_tail_lsn.load());
bool do_flush{false};
do {
{
Expand Down
3 changes: 3 additions & 0 deletions src/tests/test_log_dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ TEST_F(LogDevTest, Rollback) {
logstore_seq_num_t cur_lsn = 0;
kickstart_inserts(log_store, cur_lsn, 500);

LOGINFO("Step 3.0: Rollback last 0 entries and validate if pre-rollback entries are intact");
rollback_validate(log_store, cur_lsn, 0); // Last entry = 500

LOGINFO("Step 3: Rollback last 50 entries and validate if pre-rollback entries are intact");
rollback_validate(log_store, cur_lsn, 50); // Last entry = 450

Expand Down
5 changes: 0 additions & 5 deletions src/tests/test_log_store_long_run.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,6 @@ class SampleLogStoreClient {
}

void rollback_validate(uint32_t num_lsns_to_rollback) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe @sanebay hit this issue when he was doing the log store long running... he worked around in the UT but with the fix in implementation we dont need this work around in UT.

if (m_log_store->truncated_upto() == m_log_store->get_contiguous_completed_seq_num(-1)) {
// No records to rollback.
return;
}
if ((m_cur_lsn - num_lsns_to_rollback - 1) <= m_log_store->get_contiguous_issued_seq_num(-1)) { return; }
auto const upto_lsn = m_cur_lsn.fetch_sub(num_lsns_to_rollback) - num_lsns_to_rollback - 1;
m_log_store->rollback(upto_lsn);
Expand Down
Loading