commitlog: factor out code for checking mutation size

In a subsequent patch, I'll use this code in a different place. To
prepare for that, we move it out as a method. It also fits a lot better
inside the segment manager, so move it there.

Signed-off-by: Glauber Costa <glauber@scylladb.com>
This commit is contained in:
Glauber Costa
2016-10-19 13:19:18 -04:00
parent a50996f376
commit aec724bbda

View File

@@ -46,6 +46,7 @@
#include <boost/range/adaptor/map.hpp>
#include <unordered_map>
#include <unordered_set>
#include <exception>
#include <core/align.hh>
#include <core/reactor.hh>
@@ -237,6 +238,16 @@ public:
return ++_ids;
}
std::exception_ptr sanity_check_size(size_t size) {
if (size > max_mutation_size) {
return make_exception_ptr(std::invalid_argument(
"Mutation of " + std::to_string(size)
+ " bytes is too large for the maxiumum size of "
+ std::to_string(max_mutation_size)));
}
return nullptr;
}
future<> init();
future<sseg_ptr> new_segment();
future<sseg_ptr> active_segment();
@@ -773,12 +784,9 @@ public:
future<replay_position> allocate(const cf_id_type& id, shared_ptr<entry_writer> writer) {
const auto size = writer->size(*this);
const auto s = size + entry_overhead_size; // total size
if (s > _segment_manager->max_mutation_size) {
return make_exception_future<replay_position>(
std::invalid_argument(
"Mutation of " + std::to_string(s)
+ " bytes is too large for the maxiumum size of "
+ std::to_string(_segment_manager->max_mutation_size)));
auto ep = _segment_manager->sanity_check_size(s);
if (ep) {
return make_exception_future<replay_position>(std::move(ep));
}
std::experimental::optional<future<sseg_ptr>> op;