|
|
|
@ -17,11 +17,11 @@ |
|
|
|
|
#include "util/stop_watch.h" |
|
|
|
|
|
|
|
|
|
namespace ROCKSDB_NAMESPACE { |
|
|
|
|
namespace blob_db { |
|
|
|
|
|
|
|
|
|
Writer::Writer(std::unique_ptr<WritableFileWriter>&& dest, Env* env, |
|
|
|
|
Statistics* statistics, uint64_t log_number, uint64_t bpsync, |
|
|
|
|
bool use_fs, uint64_t boffset) |
|
|
|
|
BlobLogWriter::BlobLogWriter(std::unique_ptr<WritableFileWriter>&& dest, |
|
|
|
|
Env* env, Statistics* statistics, |
|
|
|
|
uint64_t log_number, uint64_t bpsync, bool use_fs, |
|
|
|
|
uint64_t boffset) |
|
|
|
|
: dest_(std::move(dest)), |
|
|
|
|
env_(env), |
|
|
|
|
statistics_(statistics), |
|
|
|
@ -32,14 +32,14 @@ Writer::Writer(std::unique_ptr<WritableFileWriter>&& dest, Env* env, |
|
|
|
|
use_fsync_(use_fs), |
|
|
|
|
last_elem_type_(kEtNone) {} |
|
|
|
|
|
|
|
|
|
Status Writer::Sync() { |
|
|
|
|
Status BlobLogWriter::Sync() { |
|
|
|
|
StopWatch sync_sw(env_, statistics_, BLOB_DB_BLOB_FILE_SYNC_MICROS); |
|
|
|
|
Status s = dest_->Sync(use_fsync_); |
|
|
|
|
RecordTick(statistics_, BLOB_DB_BLOB_FILE_SYNCED); |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status Writer::WriteHeader(BlobLogHeader& header) { |
|
|
|
|
Status BlobLogWriter::WriteHeader(BlobLogHeader& header) { |
|
|
|
|
assert(block_offset_ == 0); |
|
|
|
|
assert(last_elem_type_ == kEtNone); |
|
|
|
|
std::string str; |
|
|
|
@ -56,7 +56,7 @@ Status Writer::WriteHeader(BlobLogHeader& header) { |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status Writer::AppendFooter(BlobLogFooter& footer) { |
|
|
|
|
Status BlobLogWriter::AppendFooter(BlobLogFooter& footer) { |
|
|
|
|
assert(block_offset_ != 0); |
|
|
|
|
assert(last_elem_type_ == kEtFileHdr || last_elem_type_ == kEtRecord); |
|
|
|
|
|
|
|
|
@ -76,9 +76,9 @@ Status Writer::AppendFooter(BlobLogFooter& footer) { |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status Writer::AddRecord(const Slice& key, const Slice& val, |
|
|
|
|
uint64_t expiration, uint64_t* key_offset, |
|
|
|
|
uint64_t* blob_offset) { |
|
|
|
|
Status BlobLogWriter::AddRecord(const Slice& key, const Slice& val, |
|
|
|
|
uint64_t expiration, uint64_t* key_offset, |
|
|
|
|
uint64_t* blob_offset) { |
|
|
|
|
assert(block_offset_ != 0); |
|
|
|
|
assert(last_elem_type_ == kEtFileHdr || last_elem_type_ == kEtRecord); |
|
|
|
|
|
|
|
|
@ -89,8 +89,8 @@ Status Writer::AddRecord(const Slice& key, const Slice& val, |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status Writer::AddRecord(const Slice& key, const Slice& val, |
|
|
|
|
uint64_t* key_offset, uint64_t* blob_offset) { |
|
|
|
|
Status BlobLogWriter::AddRecord(const Slice& key, const Slice& val, |
|
|
|
|
uint64_t* key_offset, uint64_t* blob_offset) { |
|
|
|
|
assert(block_offset_ != 0); |
|
|
|
|
assert(last_elem_type_ == kEtFileHdr || last_elem_type_ == kEtRecord); |
|
|
|
|
|
|
|
|
@ -101,8 +101,8 @@ Status Writer::AddRecord(const Slice& key, const Slice& val, |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Writer::ConstructBlobHeader(std::string* buf, const Slice& key, |
|
|
|
|
const Slice& val, uint64_t expiration) { |
|
|
|
|
void BlobLogWriter::ConstructBlobHeader(std::string* buf, const Slice& key, |
|
|
|
|
const Slice& val, uint64_t expiration) { |
|
|
|
|
BlobLogRecord record; |
|
|
|
|
record.key = key; |
|
|
|
|
record.value = val; |
|
|
|
@ -110,9 +110,10 @@ void Writer::ConstructBlobHeader(std::string* buf, const Slice& key, |
|
|
|
|
record.EncodeHeaderTo(buf); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Status Writer::EmitPhysicalRecord(const std::string& headerbuf, |
|
|
|
|
const Slice& key, const Slice& val, |
|
|
|
|
uint64_t* key_offset, uint64_t* blob_offset) { |
|
|
|
|
Status BlobLogWriter::EmitPhysicalRecord(const std::string& headerbuf, |
|
|
|
|
const Slice& key, const Slice& val, |
|
|
|
|
uint64_t* key_offset, |
|
|
|
|
uint64_t* blob_offset) { |
|
|
|
|
StopWatch write_sw(env_, statistics_, BLOB_DB_BLOB_FILE_WRITE_MICROS); |
|
|
|
|
Status s = dest_->Append(Slice(headerbuf)); |
|
|
|
|
if (s.ok()) { |
|
|
|
@ -134,6 +135,5 @@ Status Writer::EmitPhysicalRecord(const std::string& headerbuf, |
|
|
|
|
return s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} // namespace blob_db
|
|
|
|
|
} // namespace ROCKSDB_NAMESPACE
|
|
|
|
|
#endif // ROCKSDB_LITE
|
|
|
|
|