From a50996f376ee5aa6fc98b9f7a48bb1ac96a6e4db Mon Sep 17 00:00:00 2001 From: Glauber Costa Date: Sun, 16 Oct 2016 11:35:19 -0400 Subject: [PATCH] commitlog: calculate segment-independent size of mutations Goal is to calculate a size that is lesser or equal than the segment-dependent size. This was originally written by Tomasz, and featured in his submission "commitlog: Handle overload more gracefully" Extracted here so it sits clearly in a different patch. Signed-off-by: Glauber Costa --- db/commitlog/commitlog.cc | 4 ++++ db/commitlog/commitlog.hh | 2 ++ db/commitlog/commitlog_entry.hh | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index dbd26a520e..85c924dd01 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -1424,6 +1424,7 @@ future db::commitlog::add(const cf_id_type& id, : _func(std::move(func)), _size(sz) { } virtual size_t size(segment&) override { return _size; } + virtual size_t size() override { return _size; } virtual void write(segment&, output& out) override { _func(out); } @@ -1444,6 +1445,9 @@ future db::commitlog::add_entry(const cf_id_type& id, const _writer.set_with_schema(!seg.is_schema_version_known(_writer.schema())); return _writer.size(); } + virtual size_t size() override { + return _writer.mutation_size(); + } virtual void write(segment& seg, output& out) override { if (_writer.with_schema()) { seg.add_schema_version(_writer.schema()); diff --git a/db/commitlog/commitlog.hh b/db/commitlog/commitlog.hh index 5b56c486f3..786a96b663 100644 --- a/db/commitlog/commitlog.hh +++ b/db/commitlog/commitlog.hh @@ -321,6 +321,8 @@ private: struct entry_writer { virtual size_t size(segment&) = 0; + // Returns segment-independent size of the entry. Must be <= than segment-dependant size. + virtual size_t size() = 0; virtual void write(segment&, output&) = 0; }; }; diff --git a/db/commitlog/commitlog_entry.hh b/db/commitlog/commitlog_entry.hh index 925fbc0bfe..25149c951b 100644 --- a/db/commitlog/commitlog_entry.hh +++ b/db/commitlog/commitlog_entry.hh @@ -74,6 +74,10 @@ public: return _size; } + size_t mutation_size() const { + return _mutation.representation().size(); + } + void write(data_output& out) const; };