mirror of
https://github.com/facebook/rocksdb.git
synced 2024-12-02 10:15:54 +00:00
2fdf91a4f8
Summary: Replace manual memory management with std::unique_ptr in a number of places; not exhaustive, but this fixes a few leaks with file handles as well as clarifies semantics of the ownership of file handles with log classes. Test Plan: db_stress, make check Reviewers: dhruba Reviewed By: dhruba CC: zshao, leveldb, heyongqiang Differential Revision: https://reviews.facebook.net/D8043
64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
// 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"
|
|
|
|
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,
|
|
const Options* options,
|
|
SequenceNumber& seqNum,
|
|
std::vector<LogFile>* files);
|
|
virtual ~TransactionLogIteratorImpl() {
|
|
// TODO move to cc file.
|
|
delete files_;
|
|
}
|
|
|
|
virtual bool Valid();
|
|
|
|
virtual void Next();
|
|
|
|
virtual Status status();
|
|
|
|
virtual void GetBatch(WriteBatch* batch, SequenceNumber* seq);
|
|
|
|
private:
|
|
const std::string& dbname_;
|
|
const Options* options_;
|
|
const uint64_t sequenceNumber_;
|
|
const std::vector<LogFile>* files_;
|
|
bool started_;
|
|
bool isValid_; // not valid when it starts of.
|
|
Status currentStatus_;
|
|
size_t currentFileIndex_;
|
|
Slice currentRecord_;
|
|
unique_ptr<log::Reader> currentLogReader_;
|
|
Status OpenLogFile(const LogFile& logFile, unique_ptr<SequentialFile>* file);
|
|
LogReporter NewLogReporter(uint64_t logNumber);
|
|
};
|
|
|
|
|
|
|
|
} // namespace leveldb
|
|
#endif // STORAGE_LEVELDB_INCLUDE_WRITES_ITERATOR_IMPL_H_
|