2012-11-30 01:28:37 +00: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>
|
|
|
|
|
2013-08-23 15:38:13 +00:00
|
|
|
#include "rocksdb/env.h"
|
|
|
|
#include "rocksdb/options.h"
|
|
|
|
#include "rocksdb/types.h"
|
|
|
|
#include "rocksdb/transaction_log.h"
|
2012-11-30 01:28:37 +00:00
|
|
|
#include "db/log_reader.h"
|
2013-08-06 19:54:37 +00:00
|
|
|
#include "db/filename.h"
|
2012-11-30 01:28:37 +00:00
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
namespace rocksdb {
|
2012-11-30 01:28:37 +00:00
|
|
|
|
|
|
|
struct LogReporter : public log::Reader::Reporter {
|
|
|
|
Env* env;
|
|
|
|
Logger* info_log;
|
|
|
|
virtual void Corruption(size_t bytes, const Status& s) {
|
2013-04-29 20:19:24 +00:00
|
|
|
Log(info_log, "dropping %zu bytes; %s", bytes, s.ToString().c_str());
|
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) {
|
|
|
|
}
|
|
|
|
|
2013-08-29 21:30:52 +00:00
|
|
|
std::string PathName() const {
|
|
|
|
if (type_ == kArchivedLogFile) {
|
|
|
|
return ArchivedLogFileName("", logNumber_);
|
|
|
|
}
|
|
|
|
return LogFileName("", logNumber_);
|
|
|
|
}
|
2013-08-06 19:54:37 +00:00
|
|
|
|
|
|
|
uint64_t LogNumber() const { return logNumber_; }
|
|
|
|
|
|
|
|
WalFileType Type() const { return type_; }
|
|
|
|
|
|
|
|
SequenceNumber StartSequence() const { return startSequence_; }
|
|
|
|
|
|
|
|
uint64_t SizeFileBytes() const { return sizeFileBytes_; }
|
|
|
|
|
|
|
|
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:
|
|
|
|
TransactionLogIteratorImpl(const std::string& dbname,
|
2013-01-20 10:07:13 +00:00
|
|
|
const Options* options,
|
2013-06-07 22:35:17 +00:00
|
|
|
const EnvOptions& soptions,
|
2013-08-06 19:54:37 +00:00
|
|
|
const SequenceNumber seqNum,
|
|
|
|
std::unique_ptr<VectorLogPtr> files,
|
2013-03-04 18:44:04 +00:00
|
|
|
SequenceNumber const * const lastFlushedSequence);
|
|
|
|
|
2012-11-30 01:28:37 +00:00
|
|
|
virtual bool Valid();
|
|
|
|
|
|
|
|
virtual void Next();
|
|
|
|
|
|
|
|
virtual Status status();
|
|
|
|
|
2013-03-04 18:44:04 +00:00
|
|
|
virtual BatchResult GetBatch();
|
2012-11-30 01:28:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const std::string& dbname_;
|
|
|
|
const Options* options_;
|
2013-06-07 22:35:17 +00:00
|
|
|
const EnvOptions& soptions_;
|
2013-08-06 19:54:37 +00:00
|
|
|
const SequenceNumber startingSequenceNumber_;
|
|
|
|
std::unique_ptr<VectorLogPtr> files_;
|
2012-11-30 01:28:37 +00:00
|
|
|
bool started_;
|
|
|
|
bool isValid_; // not valid when it starts of.
|
|
|
|
Status currentStatus_;
|
|
|
|
size_t currentFileIndex_;
|
2013-03-04 18:44:04 +00:00
|
|
|
std::unique_ptr<WriteBatch> currentBatch_;
|
2013-01-20 10:07:13 +00:00
|
|
|
unique_ptr<log::Reader> currentLogReader_;
|
2013-08-06 19:54:37 +00:00
|
|
|
Status OpenLogFile(const LogFile* logFile, unique_ptr<SequentialFile>* file);
|
2013-04-29 20:19:24 +00:00
|
|
|
LogReporter reporter_;
|
2013-03-04 18:44:04 +00:00
|
|
|
SequenceNumber const * const lastFlushedSequence_;
|
|
|
|
// represents the sequence number being read currently.
|
|
|
|
SequenceNumber currentSequence_;
|
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-04 04:49:15 +00:00
|
|
|
} // namespace rocksdb
|
2012-11-30 01:28:37 +00:00
|
|
|
#endif // STORAGE_LEVELDB_INCLUDE_WRITES_ITERATOR_IMPL_H_
|