mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Summary: * Logstore requests a valid change of reutrning an empty iterator and not an error in case of no log files. * Changed the code to return the writebatch containing the sequence number requested from GetupdatesSince even if it lies in the middle. Earlier we used to return the next writebatch,. This also allows me oto guarantee that no files played upon by the iterator are redundant. I mean the starting log file has at least a sequence number >= the sequence number requested form GetupdatesSince. * Cleaned up redundant logic in Iterator::Next and made a new function SeekToStartSequence for greater readability and maintainibilty. * Modified a test in db_test accordingly Please check the logic carefully and suggest improvements. I have a separate patch out for more improvements like restricting reader to read till written sequences. Test Plan: * transaction log iterator tests in db_test, * db_repl_stress. * rocks_log_iterator_test in fbcode/wormhole/rocksdb/test - 2 tests thriving on hacks till now can get simplified * testing on the shadow setup for sigma with replication Reviewers: dhruba, haobo, kailiu, sdong Reviewed By: dhruba CC: leveldb Differential Revision: https://reviews.facebook.net/D13437
82 lines
2.4 KiB
C++
82 lines
2.4 KiB
C++
// Copyright 2008-present Facebook. All Rights Reserved.
|
|
#ifndef STORAGE_ROCKSDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
|
|
#define STORAGE_ROCKSDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
|
|
|
|
#include "rocksdb/status.h"
|
|
#include "rocksdb/types.h"
|
|
#include "rocksdb/write_batch.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
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 pathname relative to the main db dir
|
|
// Eg. For a live-log-file = /000003.log
|
|
// For an archived-log-file = /archive/000003.log
|
|
virtual std::string PathName() 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;
|
|
};
|
|
|
|
struct BatchResult {
|
|
SequenceNumber sequence;
|
|
std::unique_ptr<WriteBatch> writeBatchPtr;
|
|
};
|
|
|
|
// 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.
|
|
// Can read data from a valid iterator.
|
|
virtual bool Valid() = 0;
|
|
|
|
// Moves the iterator to the next WriteBatch.
|
|
// REQUIRES: Valid() to be true.
|
|
virtual void Next() = 0;
|
|
|
|
// Returns ok if the iterator is valid.
|
|
// Returns the Error when something has gone wrong.
|
|
virtual Status status() = 0;
|
|
|
|
// If valid return's the current write_batch and the sequence number of the
|
|
// latest transaction contained in the batch.
|
|
// ONLY use if Valid() is true and status() is OK.
|
|
virtual BatchResult GetBatch() = 0;
|
|
};
|
|
} // namespace rocksdb
|
|
|
|
#endif // STORAGE_ROCKSDB_INCLUDE_TRANSACTION_LOG_ITERATOR_H_
|