Merge branch 'penberg/commitlog-cleanups' of github.com:cloudius-systems/seastar-dev into db

Minor commitlog code cleanups, from Pekka.
This commit is contained in:
Avi Kivity
2015-05-06 10:01:27 +03:00
2 changed files with 41 additions and 35 deletions

View File

@@ -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<segment> sseg_ptr;
using clock_type = lowres_clock;
using time_point = clock_type::time_point;
using sseg_ptr = lw_shared_ptr<segment>;
segment_manager(config cfg)
: cfg(cfg), max_size(
@@ -166,10 +166,10 @@ class db::commitlog::segment: public enable_lw_shared_from_this<segment> {
uint64_t _buf_pos = 0;
bool _closed = false;
typedef temporary_buffer<char> 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<char>;
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

View File

@@ -21,8 +21,7 @@
* Copyright 2015 Cloudius Systems
*/
#ifndef DB_COMMITLOG_COMMITLOG_HH
#define DB_COMMITLOG_COMMITLOG_HH
#pragma once
#include <memory>
@@ -35,16 +34,18 @@ 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) {};
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 +55,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>
_segment_manager;
std::unique_ptr<segment_manager> _segment_manager;
public:
enum class sync_mode {
PERIODIC, BATCH
@@ -124,8 +132,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<void(output&)> serializer_func;
using output = data_output;
using serializer_func = std::function<void(output&)>;
/**
* Add a "Mutation" to the commit log.
@@ -167,5 +175,3 @@ private:
};
}
#endif // DB_COMMITLOG_COMMITLOG_HH