2016-02-09 23:12:00 +00:00
|
|
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
2017-07-15 23:03:42 +00:00
|
|
|
// This source code is licensed under both the GPLv2 (found in the
|
|
|
|
// COPYING file in the root directory) and Apache 2.0 License
|
|
|
|
// (found in the LICENSE.Apache file in the root directory).
|
2014-10-30 00:43:37 +00:00
|
|
|
//
|
|
|
|
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <deque>
|
|
|
|
#include <limits>
|
|
|
|
#include <set>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include <memory>
|
|
|
|
|
2016-09-23 23:34:04 +00:00
|
|
|
#include "db/version_set.h"
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "options/db_options.h"
|
2014-10-30 00:43:37 +00:00
|
|
|
#include "port/port.h"
|
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/status.h"
|
2016-09-23 23:34:04 +00:00
|
|
|
#include "rocksdb/transaction_log.h"
|
|
|
|
#include "rocksdb/types.h"
|
2014-10-30 00:43:37 +00:00
|
|
|
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
class WalManager {
|
|
|
|
public:
|
2016-09-23 23:34:04 +00:00
|
|
|
WalManager(const ImmutableDBOptions& db_options,
|
|
|
|
const EnvOptions& env_options)
|
2014-10-30 00:43:37 +00:00
|
|
|
: db_options_(db_options),
|
|
|
|
env_options_(env_options),
|
|
|
|
env_(db_options.env),
|
|
|
|
purge_wal_files_last_run_(0) {}
|
|
|
|
|
2014-11-10 22:39:38 +00:00
|
|
|
Status GetSortedWalFiles(VectorLogPtr& files);
|
2014-10-30 00:43:37 +00:00
|
|
|
|
2014-11-10 22:39:38 +00:00
|
|
|
Status GetUpdatesSince(
|
2014-10-30 00:43:37 +00:00
|
|
|
SequenceNumber seq_number, std::unique_ptr<TransactionLogIterator>* iter,
|
|
|
|
const TransactionLogIterator::ReadOptions& read_options,
|
|
|
|
VersionSet* version_set);
|
|
|
|
|
|
|
|
void PurgeObsoleteWALFiles();
|
|
|
|
|
|
|
|
void ArchiveWALFile(const std::string& fname, uint64_t number);
|
|
|
|
|
|
|
|
Status TEST_ReadFirstRecord(const WalFileType type, const uint64_t number,
|
|
|
|
SequenceNumber* sequence) {
|
|
|
|
return ReadFirstRecord(type, number, sequence);
|
|
|
|
}
|
|
|
|
|
2016-09-15 16:55:02 +00:00
|
|
|
Status TEST_ReadFirstLine(const std::string& fname, const uint64_t number,
|
2014-10-30 00:43:37 +00:00
|
|
|
SequenceNumber* sequence) {
|
2016-09-15 16:55:02 +00:00
|
|
|
return ReadFirstLine(fname, number, sequence);
|
2014-10-30 00:43:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Status GetSortedWalsOfType(const std::string& path, VectorLogPtr& log_files,
|
|
|
|
WalFileType type);
|
|
|
|
// Requires: all_logs should be sorted with earliest log file first
|
|
|
|
// Retains all log files in all_logs which contain updates with seq no.
|
|
|
|
// Greater Than or Equal to the requested SequenceNumber.
|
|
|
|
Status RetainProbableWalFiles(VectorLogPtr& all_logs,
|
|
|
|
const SequenceNumber target);
|
|
|
|
|
|
|
|
Status ReadFirstRecord(const WalFileType type, const uint64_t number,
|
|
|
|
SequenceNumber* sequence);
|
|
|
|
|
2016-09-15 16:55:02 +00:00
|
|
|
Status ReadFirstLine(const std::string& fname, const uint64_t number,
|
|
|
|
SequenceNumber* sequence);
|
2014-10-30 00:43:37 +00:00
|
|
|
|
|
|
|
// ------- state from DBImpl ------
|
2016-09-23 23:34:04 +00:00
|
|
|
const ImmutableDBOptions& db_options_;
|
2014-10-30 00:43:37 +00:00
|
|
|
const EnvOptions& env_options_;
|
|
|
|
Env* env_;
|
|
|
|
|
|
|
|
// ------- WalManager state -------
|
|
|
|
// cache for ReadFirstRecord() calls
|
|
|
|
std::unordered_map<uint64_t, SequenceNumber> read_first_record_cache_;
|
|
|
|
port::Mutex read_first_record_cache_mutex_;
|
|
|
|
|
|
|
|
// last time when PurgeObsoleteWALFiles ran.
|
|
|
|
uint64_t purge_wal_files_last_run_;
|
|
|
|
|
|
|
|
// obsolete files will be deleted every this seconds if ttl deletion is
|
|
|
|
// enabled and archive size_limit is disabled.
|
|
|
|
static const uint64_t kDefaultIntervalToDeleteObsoleteWAL = 600;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
} // namespace rocksdb
|