/** Check timestamp and make checkpoint if timestamp is large enough. * @returns error code and flag that indicates whether or not new checkpoint is created */ std::tuple<aku_Status, int> Sequencer::check_timestamp_(aku_Timestamp ts) { aku_Status error_code = AKU_SUCCESS; if (ts < top_timestamp_) { auto delta = top_timestamp_ - ts; if (delta > window_size_) { error_code = AKU_ELATE_WRITE; } return make_tuple(error_code, 0); } auto point = get_checkpoint_(ts); int flag = 0; if (point > checkpoint_) { // Create new checkpoint flag = make_checkpoint_(point); } top_timestamp_ = ts; return make_tuple(error_code, flag); }
Sequencer::Sequencer(PageHeader const* page, const aku_FineTuneParams &config) : window_size_(config.window_size) , page_(page) , top_timestamp_() , checkpoint_(0u) , sequence_number_ {0} , run_locks_(RUN_LOCK_FLAGS_SIZE) , c_threshold_(config.compression_threshold) { key_.reset(new SortedRun()); key_->push_back(TimeSeriesValue()); if (page) { auto cnt = page->get_entries_count(); if (cnt != 0) { auto ts = page->read_timestamp_at(cnt - 1); checkpoint_ = get_checkpoint_(ts); top_timestamp_ = get_timestamp_(ts); } } }
/** Check timestamp and make checkpoint if timestamp is large enough. * @returns error code and flag that indicates whether or not new checkpoint is created */ std::tuple<int, int> Sequencer::check_timestamp_(aku_Timestamp ts) { int error_code = AKU_SUCCESS; if (ts < top_timestamp_) { auto delta = top_timestamp_ - ts; if (delta > window_size_) { error_code = AKU_ELATE_WRITE; } return make_tuple(error_code, 0); } auto point = get_checkpoint_(ts); int flag = 0; if (point > checkpoint_) { // Create new checkpoint flag = make_checkpoint_(point); if (flag % 2 == 0) { // Previous checkpoint not completed error_code = AKU_EBUSY; } } top_timestamp_ = ts; return make_tuple(error_code, flag); }