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

Fast forward API to truncate upto a log index #334

Merged
merged 6 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -2,7 +2,7 @@

class HomestoreConan(ConanFile):
name = "homestore"
version = "3.6.14"
version = "3.7.1"

homepage = "https://github.corp.ebay.com/SDS/homestore"
description = "HomeStore"
Expand Down
47 changes: 44 additions & 3 deletions src/homelogstore/log_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void HomeLogStore::truncate(const logstore_seq_num_t upto_seq_num, const bool in
// First try to block the flushing of logdevice and if we are successfully able to do, then
auto shared_this{shared_from_this()};
const bool locked_now{m_logdev.try_lock_flush([shared_this, upto_seq_num, in_memory_truncate_only]() {
shared_this->do_truncate(upto_seq_num);
shared_this->do_truncate(upto_seq_num, false /*persist meta now*/);
if (!in_memory_truncate_only) {
[[maybe_unused]] const auto key{shared_this->get_family().do_device_truncate()};
}
Expand All @@ -237,13 +237,54 @@ void HomeLogStore::truncate(const logstore_seq_num_t upto_seq_num, const bool in
if (locked_now) { m_logdev.unlock_flush(); }
}

void HomeLogStore::truncate_sync(const logstore_seq_num_t upto_seq_num, const bool in_memory_truncate_only) {
hkadayam marked this conversation as resolved.
Show resolved Hide resolved
#ifndef NDEBUG
const auto s{m_safe_truncation_boundary.seq_num.load(std::memory_order_acquire)};
// Don't check this if we don't know our truncation boundary. The call is made to inform us about
// correct truncation point.
if (s != -1) {
HS_DBG_ASSERT_LE(upto_seq_num, get_contiguous_completed_seq_num(s),
"Logstore {} expects truncation to be contiguously completed", m_store_id);
}
#endif

struct Context {
std::mutex truncate_mutex;
std::condition_variable truncate_cv;
bool truncate_done{false};
};
auto ctx{std::make_shared< Context >()};

auto shared_this{shared_from_this()};
const bool locked_now{m_logdev.try_lock_flush([shared_this, upto_seq_num, in_memory_truncate_only, ctx]() {
shared_this->do_truncate(upto_seq_num, true /*persist meta now*/);
if (!in_memory_truncate_only) {
[[maybe_unused]] const auto key{shared_this->get_family().do_device_truncate()};
}
{
std::unique_lock< std::mutex > lk{ctx->truncate_mutex};
ctx->truncate_done = true;
}
ctx->truncate_cv.notify_one();
})};

if (locked_now) {
m_logdev.unlock_flush();
} else {
{
std::unique_lock< std::mutex > lk{ctx->truncate_mutex};
ctx->truncate_cv.wait(lk, [&ctx] { return ctx->truncate_done; });
}
}
}

// NOTE: This method assumes the flush lock is already acquired by the caller
void HomeLogStore::do_truncate(const logstore_seq_num_t upto_seq_num) {
void HomeLogStore::do_truncate(const logstore_seq_num_t upto_seq_num, const bool persist_now) {
m_records.truncate(upto_seq_num);
m_safe_truncation_boundary.seq_num.store(upto_seq_num, std::memory_order_release);

// Need to update the superblock with meta, we don't persist yet, will be done as part of log dev truncation
hkadayam marked this conversation as resolved.
Show resolved Hide resolved
m_logdev.update_store_superblk(m_store_id, logstore_superblk{upto_seq_num + 1}, false /* persist_now */);
m_logdev.update_store_superblk(m_store_id, logstore_superblk{upto_seq_num + 1}, persist_now /* persist_now */);

const int ind{search_max_le(upto_seq_num)};
if (ind < 0) {
Expand Down
14 changes: 11 additions & 3 deletions src/homelogstore/log_store.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct log_dump_req {
std::shared_ptr< HomeLogStore > log_store; // if null all log stores are dumped
logstore_seq_num_t start_seq_num; // empty_key if from start of log file
logstore_seq_num_t end_seq_num; // empty_key if till last log entry
logstore_seq_num_t batch_size = 0; // Size of the output batch.
logstore_seq_num_t batch_size = 0; // Size of the output batch.
};

struct logstore_record {
Expand Down Expand Up @@ -94,7 +94,7 @@ struct logstore_req {
if (req->is_internal_req) { sisl::ObjectAllocator< logstore_req >::deallocate(req); }
}

friend class sisl::ObjectAllocator<logstore_req>;
friend class sisl::ObjectAllocator< logstore_req >;

private:
logstore_req() = default;
Expand Down Expand Up @@ -396,6 +396,14 @@ class HomeLogStore : public std::enable_shared_from_this< HomeLogStore > {
*/
void truncate(const logstore_seq_num_t upto_seq_num, const bool in_memory_truncate_only = true);

/**
* @brief Truncate the logs for this log store upto the seq_num provided (inclusive) and persist the metablock
* before returning. This API makes sure the log idx is durable after the truncation.
*
* see above truncate method for more details on parameters
*/
void truncate_sync(const logstore_seq_num_t upto_seq_num, const bool in_memory_truncate_only = true);

/**
* @brief Fill the gap in the seq_num with a dummy value. This ensures that get_contiguous_issued and completed
* seq_num methods move forward. The filled data is not readable and any attempt to read this seq_num will
Expand Down Expand Up @@ -513,7 +521,7 @@ class HomeLogStore : public std::enable_shared_from_this< HomeLogStore > {
void on_log_found(const logstore_seq_num_t seq_num, const logdev_key ld_key, const logdev_key flush_ld_key,
const log_buffer buf);
void on_batch_completion(const logdev_key& flush_batch_ld_key);
void do_truncate(const logstore_seq_num_t upto_seq_num);
void do_truncate(const logstore_seq_num_t upto_seq_num, const bool persist_now);
[[nodiscard]] int search_max_le(const logstore_seq_num_t input_sn);

private:
Expand Down
Loading