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).
|
2016-09-23 23:34:04 +00:00
|
|
|
#pragma once
|
2014-04-15 20:39:26 +00:00
|
|
|
|
|
|
|
#ifndef ROCKSDB_LITE
|
2012-11-30 01:28:37 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2016-09-23 23:34:04 +00:00
|
|
|
#include "db/log_reader.h"
|
|
|
|
#include "db/version_set.h"
|
2019-05-30 03:44:08 +00:00
|
|
|
#include "file/filename.h"
|
2021-09-29 11:01:57 +00:00
|
|
|
#include "logging/logging.h"
|
2017-04-06 02:02:00 +00:00
|
|
|
#include "options/db_options.h"
|
2016-09-23 23:34:04 +00:00
|
|
|
#include "port/port.h"
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/transaction_log.h"
|
2016-09-23 23:34:04 +00:00
|
|
|
#include "rocksdb/types.h"
|
2012-11-30 01:28:37 +00:00
|
|
|
|
2020-02-20 20:07:53 +00:00
|
|
|
namespace ROCKSDB_NAMESPACE {
|
2012-11-30 01:28:37 +00:00
|
|
|
|
2013-08-06 19:54:37 +00:00
|
|
|
class LogFileImpl : public LogFile {
|
|
|
|
public:
|
|
|
|
LogFileImpl(uint64_t logNum, WalFileType logType, SequenceNumber startSeq,
|
|
|
|
uint64_t sizeBytes) :
|
|
|
|
logNumber_(logNum),
|
|
|
|
type_(logType),
|
|
|
|
startSequence_(startSeq),
|
|
|
|
sizeFileBytes_(sizeBytes) {
|
|
|
|
}
|
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
std::string PathName() const override {
|
2013-08-29 21:30:52 +00:00
|
|
|
if (type_ == kArchivedLogFile) {
|
|
|
|
return ArchivedLogFileName("", logNumber_);
|
|
|
|
}
|
|
|
|
return LogFileName("", logNumber_);
|
|
|
|
}
|
2013-08-06 19:54:37 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
uint64_t LogNumber() const override { return logNumber_; }
|
2013-08-06 19:54:37 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
WalFileType Type() const override { return type_; }
|
2013-08-06 19:54:37 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
SequenceNumber StartSequence() const override { return startSequence_; }
|
2013-08-06 19:54:37 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
uint64_t SizeFileBytes() const override { return sizeFileBytes_; }
|
2013-08-06 19:54:37 +00:00
|
|
|
|
|
|
|
bool operator < (const LogFile& that) const {
|
|
|
|
return LogNumber() < that.LogNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint64_t logNumber_;
|
|
|
|
WalFileType type_;
|
|
|
|
SequenceNumber startSequence_;
|
|
|
|
uint64_t sizeFileBytes_;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2012-11-30 01:28:37 +00:00
|
|
|
class TransactionLogIteratorImpl : public TransactionLogIterator {
|
|
|
|
public:
|
2014-02-28 19:50:36 +00:00
|
|
|
TransactionLogIteratorImpl(
|
2016-09-23 23:34:04 +00:00
|
|
|
const std::string& dir, const ImmutableDBOptions* options,
|
2014-02-28 19:50:36 +00:00
|
|
|
const TransactionLogIterator::ReadOptions& read_options,
|
|
|
|
const EnvOptions& soptions, const SequenceNumber seqNum,
|
2017-11-11 01:18:01 +00:00
|
|
|
std::unique_ptr<VectorLogPtr> files, VersionSet const* const versions,
|
2020-08-13 00:28:10 +00:00
|
|
|
const bool seq_per_batch, const std::shared_ptr<IOTracer>& io_tracer);
|
2013-03-04 18:44:04 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual bool Valid() override;
|
2012-11-30 01:28:37 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void Next() override;
|
2012-11-30 01:28:37 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual Status status() override;
|
2012-11-30 01:28:37 +00:00
|
|
|
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual BatchResult GetBatch() override;
|
2012-11-30 01:28:37 +00:00
|
|
|
|
|
|
|
private:
|
2013-10-01 21:46:52 +00:00
|
|
|
const std::string& dir_;
|
2016-09-23 23:34:04 +00:00
|
|
|
const ImmutableDBOptions* options_;
|
2014-02-28 19:50:36 +00:00
|
|
|
const TransactionLogIterator::ReadOptions read_options_;
|
2013-06-07 22:35:17 +00:00
|
|
|
const EnvOptions& soptions_;
|
2019-03-27 19:20:43 +00:00
|
|
|
SequenceNumber starting_sequence_number_;
|
2013-08-06 19:54:37 +00:00
|
|
|
std::unique_ptr<VectorLogPtr> files_;
|
2022-04-15 00:12:16 +00:00
|
|
|
// Used only to get latest seq. num
|
|
|
|
// TODO(icanadi) can this be just a callback?
|
|
|
|
VersionSet const* const versions_;
|
|
|
|
const bool seq_per_batch_;
|
|
|
|
std::shared_ptr<IOTracer> io_tracer_;
|
|
|
|
|
|
|
|
// State variables
|
2012-11-30 01:28:37 +00:00
|
|
|
bool started_;
|
2019-03-27 19:20:43 +00:00
|
|
|
bool is_valid_; // not valid when it starts of.
|
|
|
|
Status current_status_;
|
|
|
|
size_t current_file_index_;
|
|
|
|
std::unique_ptr<WriteBatch> current_batch_;
|
|
|
|
std::unique_ptr<log::Reader> current_log_reader_;
|
2019-08-26 18:24:40 +00:00
|
|
|
std::string scratch_;
|
2019-03-27 19:20:43 +00:00
|
|
|
Status OpenLogFile(const LogFile* log_file,
|
2018-11-09 19:17:34 +00:00
|
|
|
std::unique_ptr<SequentialFileReader>* file);
|
2014-11-06 19:14:28 +00:00
|
|
|
|
|
|
|
struct LogReporter : public log::Reader::Reporter {
|
|
|
|
Env* env;
|
|
|
|
Logger* info_log;
|
2015-02-26 19:28:41 +00:00
|
|
|
virtual void Corruption(size_t bytes, const Status& s) override {
|
2017-03-16 02:22:52 +00:00
|
|
|
ROCKS_LOG_ERROR(info_log, "dropping %" ROCKSDB_PRIszt " bytes; %s", bytes,
|
|
|
|
s.ToString().c_str());
|
2014-11-06 19:14:28 +00:00
|
|
|
}
|
2017-03-16 02:22:52 +00:00
|
|
|
virtual void Info(const char* s) { ROCKS_LOG_INFO(info_log, "%s", s); }
|
2014-11-06 19:14:28 +00:00
|
|
|
} reporter_;
|
|
|
|
|
2019-03-27 19:20:43 +00:00
|
|
|
SequenceNumber
|
|
|
|
current_batch_seq_; // sequence number at start of current batch
|
|
|
|
SequenceNumber current_last_seq_; // last sequence in the current batch
|
2013-10-21 02:06:19 +00:00
|
|
|
// Reads from transaction log only if the writebatch record has been written
|
2019-08-26 18:24:40 +00:00
|
|
|
bool RestrictedRead(Slice* record);
|
2022-04-15 00:12:16 +00:00
|
|
|
// Seeks to starting_sequence_number_ reading from start_file_index in files_.
|
|
|
|
// If strict is set, then must get a batch starting with
|
|
|
|
// starting_sequence_number_.
|
2019-03-27 19:20:43 +00:00
|
|
|
void SeekToStartSequence(uint64_t start_file_index = 0, bool strict = false);
|
2013-10-25 02:09:02 +00:00
|
|
|
// Implementation of Next. SeekToStartSequence calls it internally with
|
|
|
|
// internal=true to let it find next entry even if it has to jump gaps because
|
|
|
|
// the iterator may start off from the first available entry but promises to
|
|
|
|
// be continuous after that
|
|
|
|
void NextImpl(bool internal = false);
|
|
|
|
// Check if batch is expected, else return false
|
2019-03-27 19:20:43 +00:00
|
|
|
bool IsBatchExpected(const WriteBatch* batch, SequenceNumber expected_seq);
|
2022-04-15 00:12:16 +00:00
|
|
|
// Update current batch if a continuous batch is found.
|
2013-03-04 18:44:04 +00:00
|
|
|
void UpdateCurrentWriteBatch(const Slice& record);
|
2013-08-06 19:54:37 +00:00
|
|
|
Status OpenLogReader(const LogFile* file);
|
2012-11-30 01:28:37 +00:00
|
|
|
};
|
2020-02-20 20:07:53 +00:00
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
2014-04-15 20:39:26 +00:00
|
|
|
#endif // ROCKSDB_LITE
|