fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.3 KiB
83 lines
2.3 KiB
8 years ago
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||
8 years ago
|
// This source code is licensed under both the GPLv2 (found in the
|
||
|
// COPYING file in the root directory) and Apache 2.0 License
|
||
|
// (found in the LICENSE.Apache file in the root directory).
|
||
8 years ago
|
//
|
||
|
#pragma once
|
||
|
|
||
|
#ifndef ROCKSDB_LITE
|
||
|
|
||
|
#include <memory>
|
||
|
#include <string>
|
||
|
|
||
5 years ago
|
#include "db/blob/blob_log_format.h"
|
||
5 years ago
|
#include "file/random_access_file_reader.h"
|
||
7 years ago
|
#include "rocksdb/env.h"
|
||
8 years ago
|
#include "rocksdb/slice.h"
|
||
7 years ago
|
#include "rocksdb/statistics.h"
|
||
8 years ago
|
#include "rocksdb/status.h"
|
||
|
|
||
5 years ago
|
namespace ROCKSDB_NAMESPACE {
|
||
8 years ago
|
|
||
|
class SequentialFileReader;
|
||
|
class Logger;
|
||
|
|
||
|
namespace blob_db {
|
||
|
|
||
|
/**
|
||
|
* Reader is a general purpose log stream reader implementation. The actual job
|
||
|
* of reading from the device is implemented by the SequentialFile interface.
|
||
|
*
|
||
|
* Please see Writer for details on the file and record layout.
|
||
|
*/
|
||
|
class Reader {
|
||
|
public:
|
||
|
enum ReadLevel {
|
||
7 years ago
|
kReadHeader,
|
||
|
kReadHeaderKey,
|
||
|
kReadHeaderKeyBlob,
|
||
8 years ago
|
};
|
||
|
|
||
|
// Create a reader that will return log records from "*file".
|
||
|
// "*file" must remain live while this Reader is in use.
|
||
7 years ago
|
Reader(std::unique_ptr<RandomAccessFileReader>&& file_reader, Env* env,
|
||
7 years ago
|
Statistics* statistics);
|
||
7 years ago
|
// No copying allowed
|
||
|
Reader(const Reader&) = delete;
|
||
|
Reader& operator=(const Reader&) = delete;
|
||
8 years ago
|
|
||
5 years ago
|
~Reader() = default;
|
||
|
|
||
8 years ago
|
Status ReadHeader(BlobLogHeader* header);
|
||
|
|
||
|
// Read the next record into *record. Returns true if read
|
||
|
// successfully, false if we hit end of the input. May use
|
||
|
// "*scratch" as temporary storage. The contents filled in *record
|
||
|
// will only be valid until the next mutating operation on this
|
||
|
// reader or the next mutation to *scratch.
|
||
7 years ago
|
// If blob_offset is non-null, return offset of the blob through it.
|
||
7 years ago
|
Status ReadRecord(BlobLogRecord* record, ReadLevel level = kReadHeader,
|
||
7 years ago
|
uint64_t* blob_offset = nullptr);
|
||
8 years ago
|
|
||
|
void ResetNextByte() { next_byte_ = 0; }
|
||
|
|
||
|
uint64_t GetNextByte() const { return next_byte_; }
|
||
|
|
||
|
private:
|
||
6 years ago
|
Status ReadSlice(uint64_t size, Slice* slice, char* buf);
|
||
|
|
||
7 years ago
|
const std::unique_ptr<RandomAccessFileReader> file_;
|
||
7 years ago
|
Env* env_;
|
||
|
Statistics* statistics_;
|
||
8 years ago
|
|
||
|
Slice buffer_;
|
||
6 years ago
|
char header_buf_[BlobLogRecord::kHeaderSize];
|
||
8 years ago
|
|
||
|
// which byte to read next. For asserting proper usage
|
||
|
uint64_t next_byte_;
|
||
|
};
|
||
|
|
||
|
} // namespace blob_db
|
||
5 years ago
|
} // namespace ROCKSDB_NAMESPACE
|
||
8 years ago
|
#endif // ROCKSDB_LITE
|