2012-11-30 02:28:37 +01:00
|
|
|
// Copyright 2008-present Facebook. All Rights Reserved.
|
|
|
|
#ifndef STORAGE_LEVELDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
|
|
|
|
#define STORAGE_LEVELDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
|
|
|
|
|
|
|
|
#include "leveldb/status.h"
|
2013-08-06 21:54:37 +02:00
|
|
|
#include "leveldb/types.h"
|
2012-11-30 02:28:37 +01:00
|
|
|
#include "leveldb/write_batch.h"
|
|
|
|
|
|
|
|
namespace leveldb {
|
|
|
|
|
2013-08-06 21:54:37 +02:00
|
|
|
class LogFile;
|
|
|
|
typedef std::vector<std::unique_ptr<LogFile>> VectorLogPtr;
|
|
|
|
|
|
|
|
enum WalFileType {
|
|
|
|
/* Indicates that WAL file is in archive directory. WAL files are moved from
|
|
|
|
* the main db directory to archive directory once they are not live and stay
|
|
|
|
* there for a duration of WAL_ttl_seconds which can be set in Options
|
|
|
|
*/
|
|
|
|
kArchivedLogFile = 0,
|
|
|
|
|
|
|
|
/* Indicates that WAL file is live and resides in the main db directory */
|
|
|
|
kAliveLogFile = 1
|
|
|
|
} ;
|
|
|
|
|
|
|
|
class LogFile {
|
|
|
|
public:
|
|
|
|
LogFile() {}
|
|
|
|
virtual ~LogFile() {}
|
|
|
|
|
|
|
|
// Returns log file's name excluding the db path
|
|
|
|
virtual std::string Filename() const = 0;
|
|
|
|
|
|
|
|
// Primary identifier for log file.
|
|
|
|
// This is directly proportional to creation time of the log file
|
|
|
|
virtual uint64_t LogNumber() const = 0;
|
|
|
|
|
|
|
|
// Log file can be either alive or archived
|
|
|
|
virtual WalFileType Type() const = 0;
|
|
|
|
|
|
|
|
// Starting sequence number of writebatch written in this log file
|
|
|
|
virtual SequenceNumber StartSequence() const = 0;
|
|
|
|
|
|
|
|
// Size of log file on disk in Bytes
|
|
|
|
virtual uint64_t SizeFileBytes() const = 0;
|
|
|
|
};
|
2012-11-30 02:28:37 +01:00
|
|
|
|
2013-03-04 19:44:04 +01:00
|
|
|
struct BatchResult {
|
|
|
|
SequenceNumber sequence;
|
|
|
|
std::unique_ptr<WriteBatch> writeBatchPtr;
|
|
|
|
};
|
|
|
|
|
2012-11-30 02:28:37 +01:00
|
|
|
// A TransactionLogIterator is used to iterate over the Transaction's in a db.
|
|
|
|
class TransactionLogIterator {
|
|
|
|
public:
|
|
|
|
TransactionLogIterator() {}
|
|
|
|
virtual ~TransactionLogIterator() {}
|
|
|
|
|
|
|
|
// An iterator is either positioned at a WriteBatch or not valid.
|
|
|
|
// This method returns true if the iterator is valid.
|
2013-03-04 19:44:04 +01:00
|
|
|
// Can read data from a valid iterator.
|
2012-11-30 02:28:37 +01:00
|
|
|
virtual bool Valid() = 0;
|
|
|
|
|
|
|
|
// Moves the iterator to the next WriteBatch.
|
|
|
|
// REQUIRES: Valid() to be true.
|
|
|
|
virtual void Next() = 0;
|
|
|
|
|
2013-03-04 19:44:04 +01:00
|
|
|
// Return's ok if the iterator is valid.
|
|
|
|
// Return the Error when something has gone wrong.
|
2012-11-30 02:28:37 +01:00
|
|
|
virtual Status status() = 0;
|
|
|
|
|
2012-12-11 21:24:55 +01:00
|
|
|
// If valid return's the current write_batch and the sequence number of the
|
|
|
|
// latest transaction contained in the batch.
|
2013-03-04 19:44:04 +01:00
|
|
|
// ONLY use if Valid() is true and status() is OK.
|
|
|
|
virtual BatchResult GetBatch() = 0;
|
2012-11-30 02:28:37 +01:00
|
|
|
};
|
|
|
|
} // namespace leveldb
|
|
|
|
|
|
|
|
#endif // STORAGE_LEVELDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
|