419b93c56f
Summary: Previously each time we write a blob we write blog_record_header + key + value + blob_record_footer to blob log. The footer only contains a sequence and a crc for the sequence number. The sequence number was used in garbage collection to verify the value is recent. After #2703 we moved to use optimistic transaction and no longer use sequence number from the footer. Remove the footer altogether. There's another usage of sequence number and we are keeping it: Each blob log file keep track of sequence number range of keys in it, and use it to check if it is reference by a snapshot, before being deleted. Closes https://github.com/facebook/rocksdb/pull/3005 Differential Revision: D6057585 Pulled By: yiwu-arbug fbshipit-source-id: d6da53c457a316e9723f359a1b47facfc3ffe090
96 lines
2.7 KiB
C++
96 lines
2.7 KiB
C++
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
|
// 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).
|
|
//
|
|
#pragma once
|
|
|
|
#ifndef ROCKSDB_LITE
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "rocksdb/options.h"
|
|
#include "rocksdb/slice.h"
|
|
#include "rocksdb/status.h"
|
|
#include "utilities/blob_db/blob_log_format.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
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 {
|
|
kReadHeader,
|
|
kReadHeaderKey,
|
|
kReadHeaderKeyBlob,
|
|
};
|
|
|
|
// Create a reader that will return log records from "*file".
|
|
// "*file" must remain live while this Reader is in use.
|
|
//
|
|
// If "reporter" is non-nullptr, it is notified whenever some data is
|
|
// dropped due to a detected corruption. "*reporter" must remain
|
|
// live while this Reader is in use.
|
|
//
|
|
// If "checksum" is true, verify checksums if available.
|
|
//
|
|
// The Reader will start reading at the first record located at physical
|
|
// position >= initial_offset within the file.
|
|
Reader(std::shared_ptr<Logger> info_log,
|
|
std::unique_ptr<SequentialFileReader>&& file);
|
|
|
|
~Reader();
|
|
|
|
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.
|
|
// If blob_offset is non-null, return offset of the blob through it.
|
|
Status ReadRecord(BlobLogRecord* record, ReadLevel level = kReadHeader,
|
|
uint64_t* blob_offset = nullptr);
|
|
|
|
SequentialFileReader* file() { return file_.get(); }
|
|
|
|
void ResetNextByte() { next_byte_ = 0; }
|
|
|
|
uint64_t GetNextByte() const { return next_byte_; }
|
|
|
|
const SequentialFileReader* file_reader() const { return file_.get(); }
|
|
|
|
private:
|
|
char* GetReadBuffer() { return &(backing_store_[0]); }
|
|
|
|
private:
|
|
std::shared_ptr<Logger> info_log_;
|
|
const std::unique_ptr<SequentialFileReader> file_;
|
|
|
|
std::string backing_store_;
|
|
Slice buffer_;
|
|
|
|
// which byte to read next. For asserting proper usage
|
|
uint64_t next_byte_;
|
|
|
|
// No copying allowed
|
|
Reader(const Reader&) = delete;
|
|
Reader& operator=(const Reader&) = delete;
|
|
};
|
|
|
|
} // namespace blob_db
|
|
} // namespace rocksdb
|
|
#endif // ROCKSDB_LITE
|