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;
|
|
|
|
uint64_t log_number;
|
|
|
|
virtual void Corruption(size_t bytes, const Status& s) {
|
|
|
|
Log(info_log, "%ld: dropping %d bytes; %s",
|
|
|
|
log_number, static_cast<int>(bytes), s.ToString().c_str());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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-03-04 19:44:04 +01:00
|
|
|
std::vector<LogFile>* files,
|
|
|
|
SequenceNumber const * const lastFlushedSequence);
|
|
|
|
|
2012-11-30 02:28:37 +01:00
|
|
|
virtual ~TransactionLogIteratorImpl() {
|
|
|
|
// TODO move to cc file.
|
|
|
|
delete files_;
|
|
|
|
}
|
|
|
|
|
|
|
|
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_;
|
2012-11-30 02:28:37 +01:00
|
|
|
const uint64_t sequenceNumber_;
|
|
|
|
const std::vector<LogFile>* files_;
|
|
|
|
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);
|
2012-11-30 02:28:37 +01:00
|
|
|
LogReporter NewLogReporter(uint64_t logNumber);
|
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);
|
2012-11-30 02:28:37 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace leveldb
|
|
|
|
#endif // STORAGE_LEVELDB_INCLUDE_WRITES_ITERATOR_IMPL_H_
|