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.
95 lines
2.7 KiB
95 lines
2.7 KiB
8 years ago
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||
7 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 <cstdint>
|
||
|
#include <memory>
|
||
|
#include <string>
|
||
|
|
||
5 years ago
|
#include "db/blob/blob_log_format.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"
|
||
|
#include "rocksdb/types.h"
|
||
|
|
||
5 years ago
|
namespace ROCKSDB_NAMESPACE {
|
||
8 years ago
|
|
||
|
class WritableFileWriter;
|
||
|
|
||
|
namespace blob_db {
|
||
|
|
||
|
/**
|
||
|
* Writer is the blob log stream writer. It provides an append-only
|
||
|
* abstraction for writing blob data.
|
||
|
*
|
||
|
*
|
||
|
* Look at blob_db_format.h to see the details of the record formats.
|
||
|
*/
|
||
|
|
||
|
class Writer {
|
||
|
public:
|
||
|
// Create a writer that will append data to "*dest".
|
||
|
// "*dest" must be initially empty.
|
||
|
// "*dest" must remain live while this Writer is in use.
|
||
7 years ago
|
Writer(std::unique_ptr<WritableFileWriter>&& dest, Env* env,
|
||
|
Statistics* statistics, uint64_t log_number, uint64_t bpsync,
|
||
|
bool use_fsync, uint64_t boffset = 0);
|
||
7 years ago
|
// No copying allowed
|
||
|
Writer(const Writer&) = delete;
|
||
|
Writer& operator=(const Writer&) = delete;
|
||
|
|
||
5 years ago
|
~Writer() = default;
|
||
|
|
||
7 years ago
|
static void ConstructBlobHeader(std::string* buf, const Slice& key,
|
||
|
const Slice& val, uint64_t expiration);
|
||
8 years ago
|
|
||
|
Status AddRecord(const Slice& key, const Slice& val, uint64_t* key_offset,
|
||
|
uint64_t* blob_offset);
|
||
|
|
||
7 years ago
|
Status AddRecord(const Slice& key, const Slice& val, uint64_t expiration,
|
||
|
uint64_t* key_offset, uint64_t* blob_offset);
|
||
8 years ago
|
|
||
|
Status EmitPhysicalRecord(const std::string& headerbuf, const Slice& key,
|
||
|
const Slice& val, uint64_t* key_offset,
|
||
|
uint64_t* blob_offset);
|
||
|
|
||
7 years ago
|
Status AppendFooter(BlobLogFooter& footer);
|
||
8 years ago
|
|
||
7 years ago
|
Status WriteHeader(BlobLogHeader& header);
|
||
8 years ago
|
|
||
|
WritableFileWriter* file() { return dest_.get(); }
|
||
|
|
||
|
const WritableFileWriter* file() const { return dest_.get(); }
|
||
|
|
||
|
uint64_t get_log_number() const { return log_number_; }
|
||
|
|
||
|
bool ShouldSync() const { return block_offset_ > next_sync_offset_; }
|
||
|
|
||
7 years ago
|
Status Sync();
|
||
8 years ago
|
|
||
|
void ResetSyncPointer() { next_sync_offset_ += bytes_per_sync_; }
|
||
|
|
||
|
private:
|
||
|
std::unique_ptr<WritableFileWriter> dest_;
|
||
7 years ago
|
Env* env_;
|
||
|
Statistics* statistics_;
|
||
8 years ago
|
uint64_t log_number_;
|
||
|
uint64_t block_offset_; // Current offset in block
|
||
|
uint64_t bytes_per_sync_;
|
||
|
uint64_t next_sync_offset_;
|
||
|
bool use_fsync_;
|
||
|
|
||
|
public:
|
||
7 years ago
|
enum ElemType { kEtNone, kEtFileHdr, kEtRecord, kEtFileFooter };
|
||
8 years ago
|
ElemType last_elem_type_;
|
||
|
};
|
||
|
|
||
|
} // namespace blob_db
|
||
5 years ago
|
} // namespace ROCKSDB_NAMESPACE
|
||
8 years ago
|
#endif // ROCKSDB_LITE
|