#pragma once
|
|
#include "db/dbformat.h"
|
|
#include <cstddef>
|
|
#include <cstdint>
|
|
#include "leveldb/env.h"
|
|
#include "leveldb/slice.h"
|
|
#include "leveldb/status.h"
|
|
#include "leveldb/write_batch.h"
|
|
namespace leveldb {
|
|
|
|
struct FilePointer {
|
|
uint64_t FileNumber;
|
|
uint64_t FileOffset;
|
|
uint64_t Size;
|
|
};
|
|
|
|
void EncodeFP(const struct FilePointer &fp,char *scratch);
|
|
void DecodeFp(struct FilePointer &fp, char *src);
|
|
|
|
class KVLog {
|
|
public:
|
|
explicit KVLog(WritableFile *dest,uint64_t file_number);
|
|
KVLog(WritableFile *dest, uint64_t dest_length,uint64_t file_number);
|
|
|
|
KVLog(const KVLog&) = delete;
|
|
KVLog& operator=(const KVLog&) = delete;
|
|
|
|
~KVLog() = default;
|
|
|
|
Status AddRecord(const Slice& slice,FilePointer &fp);
|
|
private:
|
|
WritableFile* dest_;
|
|
uint64_t pos_;
|
|
uint64_t file_number;
|
|
char buf[8];
|
|
};
|
|
|
|
|
|
class KVLogReader {
|
|
public:
|
|
KVLogReader(SequentialFile *file):file(file),rep_(nullptr),rep_size(0),valid(true)
|
|
{ Next();};
|
|
|
|
~KVLogReader() {
|
|
delete rep_;
|
|
}
|
|
|
|
ValueType Type() {return type;}
|
|
Slice Key() {return key;}
|
|
Slice Value() {return value;}
|
|
SequenceNumber Seq() {return seq;}
|
|
bool Valid() {return valid;}
|
|
void Next();
|
|
private:
|
|
void NextWriteBatch();
|
|
void NextKV();
|
|
|
|
private:
|
|
Slice key;
|
|
Slice value;
|
|
SequenceNumber seq;
|
|
ValueType type;
|
|
bool valid;
|
|
|
|
SequentialFile *file;
|
|
Slice input;
|
|
uint64_t rep_size;
|
|
char *rep_;
|
|
char number[8];
|
|
};
|
|
|
|
}
|