Summary: reland https://reviews.facebook.net/D62523 - Update SstFileWriter to include a property for a global sequence number in the SST file `rocksdb.external_sst_file.global_seqno` - Update TableProperties to be aware of the offset of each property in the file - Update BlockBasedTableReader and Block to be able to honor the sequence number in `rocksdb.external_sst_file.global_seqno` property and use it to overwrite all sequence number in the file Something worth mentioning is that we don't update the seqno in the index block since and when doing a binary search, the reason for that is that it's guaranteed that SST files with global seqno will have only one user_key and each key will have seqno=0 encoded in it, This mean that this key is greater than any other key with seqno> 0. That mean that we can actually keep the current logic for these blocks Test Plan: unit tests Reviewers: sdong, yhchiang Subscribers: andrewkr, dhruba Differential Revision: https://reviews.facebook.net/D65211main
parent
08616b4933
commit
b88f8e87c5
@ -0,0 +1,84 @@ |
|||||||
|
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
|
||||||
|
// This source code is licensed under the BSD-style license found in the
|
||||||
|
// LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
// of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
|
||||||
|
#pragma once |
||||||
|
#include <string> |
||||||
|
#include "rocksdb/types.h" |
||||||
|
#include "util/string_util.h" |
||||||
|
|
||||||
|
namespace rocksdb { |
||||||
|
|
||||||
|
// Table Properties that are specific to tables created by SstFileWriter.
|
||||||
|
struct ExternalSstFilePropertyNames { |
||||||
|
// value of this property is a fixed uint32 number.
|
||||||
|
static const std::string kVersion; |
||||||
|
// value of this property is a fixed uint64 number.
|
||||||
|
static const std::string kGlobalSeqno; |
||||||
|
}; |
||||||
|
|
||||||
|
// PropertiesCollector used to add properties specific to tables
|
||||||
|
// generated by SstFileWriter
|
||||||
|
class SstFileWriterPropertiesCollector : public IntTblPropCollector { |
||||||
|
public: |
||||||
|
explicit SstFileWriterPropertiesCollector(int32_t version, |
||||||
|
SequenceNumber global_seqno) |
||||||
|
: version_(version), global_seqno_(global_seqno) {} |
||||||
|
|
||||||
|
virtual Status InternalAdd(const Slice& key, const Slice& value, |
||||||
|
uint64_t file_size) override { |
||||||
|
// Intentionally left blank. Have no interest in collecting stats for
|
||||||
|
// individual key/value pairs.
|
||||||
|
return Status::OK(); |
||||||
|
} |
||||||
|
|
||||||
|
virtual Status Finish(UserCollectedProperties* properties) override { |
||||||
|
// File version
|
||||||
|
std::string version_val; |
||||||
|
PutFixed32(&version_val, static_cast<uint32_t>(version_)); |
||||||
|
properties->insert({ExternalSstFilePropertyNames::kVersion, version_val}); |
||||||
|
|
||||||
|
// Global Sequence number
|
||||||
|
std::string seqno_val; |
||||||
|
PutFixed64(&seqno_val, static_cast<uint64_t>(global_seqno_)); |
||||||
|
properties->insert({ExternalSstFilePropertyNames::kGlobalSeqno, seqno_val}); |
||||||
|
|
||||||
|
return Status::OK(); |
||||||
|
} |
||||||
|
|
||||||
|
virtual const char* Name() const override { |
||||||
|
return "SstFileWriterPropertiesCollector"; |
||||||
|
} |
||||||
|
|
||||||
|
virtual UserCollectedProperties GetReadableProperties() const override { |
||||||
|
return {{ExternalSstFilePropertyNames::kVersion, ToString(version_)}}; |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
int32_t version_; |
||||||
|
SequenceNumber global_seqno_; |
||||||
|
}; |
||||||
|
|
||||||
|
class SstFileWriterPropertiesCollectorFactory |
||||||
|
: public IntTblPropCollectorFactory { |
||||||
|
public: |
||||||
|
explicit SstFileWriterPropertiesCollectorFactory(int32_t version, |
||||||
|
SequenceNumber global_seqno) |
||||||
|
: version_(version), global_seqno_(global_seqno) {} |
||||||
|
|
||||||
|
virtual IntTblPropCollector* CreateIntTblPropCollector( |
||||||
|
uint32_t column_family_id) override { |
||||||
|
return new SstFileWriterPropertiesCollector(version_, global_seqno_); |
||||||
|
} |
||||||
|
|
||||||
|
virtual const char* Name() const override { |
||||||
|
return "SstFileWriterPropertiesCollector"; |
||||||
|
} |
||||||
|
|
||||||
|
private: |
||||||
|
int32_t version_; |
||||||
|
SequenceNumber global_seqno_; |
||||||
|
}; |
||||||
|
|
||||||
|
} // namespace rocksdb
|
Loading…
Reference in new issue