From 9920d58b70904a1c3c6225d28a20da296ce6a05e Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 6 May 2015 09:43:04 +0300 Subject: [PATCH 1/3] db/commitlog: Use C++ type aliases Signed-off-by: Pekka Enberg --- db/commitlog/commitlog.cc | 14 +++++++------- db/commitlog/commitlog.hh | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/db/commitlog/commitlog.cc b/db/commitlog/commitlog.cc index c8502d941e..6ff39c3039 100644 --- a/db/commitlog/commitlog.cc +++ b/db/commitlog/commitlog.cc @@ -103,9 +103,9 @@ public: semaphore _new_segment_semaphore; // TODO: verify that we're ok with not-so-great granularity - typedef lowres_clock clock_type; - typedef clock_type::time_point time_point; - typedef lw_shared_ptr sseg_ptr; + using clock_type = lowres_clock; + using time_point = clock_type::time_point; + using sseg_ptr = lw_shared_ptr; segment_manager(config cfg) : cfg(cfg), max_size( @@ -166,10 +166,10 @@ class db::commitlog::segment: public enable_lw_shared_from_this { uint64_t _buf_pos = 0; bool _closed = false; - typedef temporary_buffer buffer_type; - typedef segment_manager::sseg_ptr sseg_ptr; - typedef segment_manager::clock_type clock_type; - typedef segment_manager::time_point time_point; + using buffer_type = temporary_buffer; + using sseg_ptr = segment_manager::sseg_ptr; + using clock_type = segment_manager::clock_type; + using time_point = segment_manager::time_point; buffer_type _buffer; rwlock _dwrite; // used as a barrier between write & flush diff --git a/db/commitlog/commitlog.hh b/db/commitlog/commitlog.hh index 491f7eee0e..4571613bf7 100644 --- a/db/commitlog/commitlog.hh +++ b/db/commitlog/commitlog.hh @@ -35,9 +35,9 @@ namespace db { class config; -typedef uint64_t segment_id_type; -typedef uint64_t position_type; -typedef utils::UUID cf_id_type; +using segment_id_type = uint64_t; +using position_type = uint64_t; +using cf_id_type = utils::UUID; struct replay_position { replay_position(segment_id_type i = 0, position_type p = 0) : id(i), pos(p) {}; @@ -124,8 +124,8 @@ public: * of data to be written. (See add). * Don't write less, absolutely don't write more... */ - typedef data_output output; - typedef std::function serializer_func; + using output = data_output; + using serializer_func = std::function; /** * Add a "Mutation" to the commit log. From a32ae69b2b8b46f0b7af018d9e8fc6c96cf18051 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 6 May 2015 09:47:21 +0300 Subject: [PATCH 2/3] db/commitlog: Minor formatting fixes Signed-off-by: Pekka Enberg --- db/commitlog/commitlog.hh | 47 +++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/db/commitlog/commitlog.hh b/db/commitlog/commitlog.hh index 4571613bf7..0c3bdc4b3e 100644 --- a/db/commitlog/commitlog.hh +++ b/db/commitlog/commitlog.hh @@ -40,11 +40,13 @@ using position_type = uint64_t; using cf_id_type = utils::UUID; struct replay_position { - replay_position(segment_id_type i = 0, position_type p = 0) : id(i), pos(p) {}; - segment_id_type id; position_type pos; + replay_position(segment_id_type i = 0, position_type p = 0) + : id(i), pos(p) + { } + bool operator<(const replay_position & r) const { return id < r.id ? true : (r.id < id ? false : pos < r.pos); } @@ -54,38 +56,45 @@ struct replay_position { }; /* - * Commit Log tracks every write operation into the system. The aim of the commit log is to be able to - * successfully recover data that was not stored to disk via the Memtable. + * Commit Log tracks every write operation into the system. The aim of + * the commit log is to be able to successfully recover data that was + * not stored to disk via the Memtable. * * This impl is cassandra log format compatible (for what it is worth). * The behaviour is similar, but not 100% identical as "stock cl". * - * Files are managed with "normal" file writes (as normal as seastar gets) - no mmapping. - * Data is kept in internal buffers which, when full, are written to disk (see below). - * Files are also flushed periodically (or always), ensuring all data is written + writes are complete. + * Files are managed with "normal" file writes (as normal as seastar + * gets) - no mmapping. Data is kept in internal buffers which, when + * full, are written to disk (see below). Files are also flushed + * periodically (or always), ensuring all data is written + writes are + * complete. * - * In BATCH mode, every write to the log will also send the data to disk + issue a flush and wait for both to complete. + * In BATCH mode, every write to the log will also send the data to disk + * + issue a flush and wait for both to complete. * - * In PERIODIC mode, most writes will only add to the internal memory buffers. If the mem buffer is saturated, data is sent to - * disk, but we don't wait for the write to complete. However, if periodic (timer) flushing has not been done in X ms, we will - * write + flush to file. In which case we wait for it. + * In PERIODIC mode, most writes will only add to the internal memory + * buffers. If the mem buffer is saturated, data is sent to disk, but we + * don't wait for the write to complete. However, if periodic (timer) + * flushing has not been done in X ms, we will write + flush to file. In + * which case we wait for it. * - * The commitlog does not guarantee any ordering between "add" callers (due to the above). The actual order in the commitlog is however + * The commitlog does not guarantee any ordering between "add" callers + * (due to the above). The actual order in the commitlog is however * identified by the replay_position returned. * - * Like the stock cl, the log segments keep track of the highest dirty (added) internal position for a given table id (cf_id_type / UUID). - * Code should ensure to use discard_completed_segments with UUID + highest rp once a memtable has been flushed. This will allow discarding - * used segments. Failure to do so will keep stuff indefinately. - * + * Like the stock cl, the log segments keep track of the highest dirty + * (added) internal position for a given table id (cf_id_type / UUID). + * Code should ensure to use discard_completed_segments with UUID + + * highest rp once a memtable has been flushed. This will allow + * discarding used segments. Failure to do so will keep stuff + * indefinately. */ class commitlog { class segment_manager; class segment; class descriptor; - std::unique_ptr - _segment_manager; - + std::unique_ptr _segment_manager; public: enum class sync_mode { PERIODIC, BATCH From bf1734c48015d660f2c98a19777ae96bd06dbbc0 Mon Sep 17 00:00:00 2001 From: Pekka Enberg Date: Wed, 6 May 2015 09:47:42 +0300 Subject: [PATCH 3/3] db/commitlog: Use 'pragma once' in commitlog.hh Signed-off-by: Pekka Enberg --- db/commitlog/commitlog.hh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/db/commitlog/commitlog.hh b/db/commitlog/commitlog.hh index 0c3bdc4b3e..e3d61f4b3e 100644 --- a/db/commitlog/commitlog.hh +++ b/db/commitlog/commitlog.hh @@ -21,8 +21,7 @@ * Copyright 2015 Cloudius Systems */ -#ifndef DB_COMMITLOG_COMMITLOG_HH -#define DB_COMMITLOG_COMMITLOG_HH +#pragma once #include @@ -176,5 +175,3 @@ private: }; } - -#endif // DB_COMMITLOG_COMMITLOG_HH