2012-11-30 02:28:37 +01:00
|
|
|
// Copyright 2008-present Facebook. All Rights Reserved.
|
|
|
|
#ifndef STORAGE_LEVELDB_INCLUDE_WRITES_ITERATOR_IMPL_H_
|
|
|
|
#define STORAGE_LEVELDB_INCLUDE_WRITES_ITERATOR_IMPL_H_
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include "leveldb/env.h"
|
|
|
|
#include "leveldb/options.h"
|
|
|
|
#include "leveldb/types.h"
|
|
|
|
#include "leveldb/transaction_log_iterator.h"
|
|
|
|
#include "db/log_file.h"
|
|
|
|
#include "db/log_reader.h"
|
2013-03-15 01:00:04 +01:00
|
|
|
#include "util/storage_options.h"
|
2012-11-30 02:28:37 +01:00
|
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
|
|
|
|
struct LogReporter : public log::Reader::Reporter {
|
|
|
|
Env* env;
|
|
|
|
Logger* info_log;
|
|
|
|
virtual void Corruption(size_t bytes, const Status& s) {
|
2013-04-29 22:19:24 +02:00
|
|
|
Log(info_log, "dropping %zu bytes; %s", bytes, s.ToString().c_str());
|
2012-11-30 02:28:37 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class TransactionLogIteratorImpl : public TransactionLogIterator {
|
|
|
|
public:
|
|
|
|
TransactionLogIteratorImpl(const std::string& dbname,
|
2013-01-20 11:07:13 +01:00
|
|
|
const Options* options,
|
2013-03-15 01:00:04 +01:00
|
|
|
const StorageOptions& soptions,
|
2013-01-20 11:07:13 +01:00
|
|
|
SequenceNumber& seqNum,
|
2013-04-09 22:21:11 +02:00
|
|
|
std::unique_ptr<std::vector<LogFile>> files,
|
2013-03-04 19:44:04 +01:00
|
|
|
SequenceNumber const * const lastFlushedSequence);
|
|
|
|
|
2012-11-30 02:28:37 +01:00
|
|
|
virtual bool Valid();
|
|
|
|
|
|
|
|
virtual void Next();
|
|
|
|
|
|
|
|
virtual Status status();
|
|
|
|
|
2013-03-04 19:44:04 +01:00
|
|
|
virtual BatchResult GetBatch();
|
2012-11-30 02:28:37 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string& dbname_;
|
|
|
|
const Options* options_;
|
2013-03-15 01:00:04 +01:00
|
|
|
const StorageOptions& soptions_;
|
2013-04-09 01:28:09 +02:00
|
|
|
const uint64_t startingSequenceNumber_;
|
2013-04-09 22:21:11 +02:00
|
|
|
std::unique_ptr<std::vector<LogFile>> files_;
|
2012-11-30 02:28:37 +01:00
|
|
|
bool started_;
|
|
|
|
bool isValid_; // not valid when it starts of.
|
|
|
|
Status currentStatus_;
|
|
|
|
size_t currentFileIndex_;
|
2013-03-04 19:44:04 +01:00
|
|
|
std::unique_ptr<WriteBatch> currentBatch_;
|
2013-01-20 11:07:13 +01:00
|
|
|
unique_ptr<log::Reader> currentLogReader_;
|
|
|
|
Status OpenLogFile(const LogFile& logFile, unique_ptr<SequentialFile>* file);
|
2013-04-29 22:19:24 +02:00
|
|
|
LogReporter reporter_;
|
2013-03-04 19:44:04 +01:00
|
|
|
SequenceNumber const * const lastFlushedSequence_;
|
|
|
|
// represents the sequence number being read currently.
|
|
|
|
SequenceNumber currentSequence_;
|
|
|
|
|
|
|
|
void UpdateCurrentWriteBatch(const Slice& record);
|
2013-04-09 01:28:09 +02:00
|
|
|
Status OpenLogReader(const LogFile& file);
|
2012-11-30 02:28:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace leveldb
|
|
|
|
#endif // STORAGE_LEVELDB_INCLUDE_WRITES_ITERATOR_IMPL_H_
|