From b95dabba38d2e877046c9f69464c483fd010df0b Mon Sep 17 00:00:00 2001 From: Amnon Heiman Date: Tue, 19 May 2015 12:22:56 +0300 Subject: [PATCH] Expose the segment names in commit log This adds a method to return a vector with full-path to the active segment names. It will be used by the API. Signed-off-by: Amnon Heiman --- db/commitlog/commitlog.cc | 18 ++++++++++++++++++ db/commitlog/commitlog.hh | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index 54224af793..4e41e5af80 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -172,6 +172,7 @@ public: _timer.arm(std::chrono::milliseconds(cfg.commitlog_sync_period_in_ms)); } + std::vector get_active_names() const; private: uint64_t _ids = 0; std::vector _segments; @@ -460,6 +461,9 @@ public: bool contains(const replay_position& pos) { return pos.id == _desc.id; } + sstring get_segment_name() const { + return _desc.filename(); + } }; const size_t db::commitlog::segment::default_size; @@ -639,6 +643,17 @@ void db::commitlog::segment_manager::sync() { } arm(); } + +std::vector db::commitlog::segment_manager::get_active_names() const { + std::vector res; + for (auto i: _segments) { + if (!i->is_unused()) { + // Each shared is located in its own directory + res.push_back(cfg.commit_log_location + "/" + i->get_segment_name()); + } + } + return res; +} /** * Add mutation. */ @@ -806,3 +821,6 @@ subscription> db::commitlog::read_log_file(file f, commit return ret; } +std::vector db::commitlog::get_active_segment_names() const { + return _segment_manager->get_active_names(); +} diff --git a/db/commitlog/commitlog.hh b/db/commitlog/commitlog.hh index 081c088a53..b88fd59616 100644 --- a/db/commitlog/commitlog.hh +++ b/db/commitlog/commitlog.hh @@ -165,6 +165,11 @@ public: */ void discard_completed_segments(const cf_id_type&, const replay_position&); + /** + * Returns a vector of the segment names + */ + std::vector get_active_segment_names() const; + /** * Returns the largest amount of data that can be written in a single "mutation". */