Introducing the concept of NULL block handle

main
Kai Liu 11 years ago
parent 3a0e98d558
commit 5dec7acd91
  1. 1
      table/format.cc
  2. 26
      table/format.h

@ -34,6 +34,7 @@ Status BlockHandle::DecodeFrom(Slice* input) {
return Status::Corruption("bad block handle"); return Status::Corruption("bad block handle");
} }
} }
const BlockHandle BlockHandle::kNullBlockHandle(0, 0);
void Footer::EncodeTo(std::string* dst) const { void Footer::EncodeTo(std::string* dst) const {
#ifndef NDEBUG #ifndef NDEBUG

@ -26,6 +26,7 @@ struct ReadOptions;
class BlockHandle { class BlockHandle {
public: public:
BlockHandle(); BlockHandle();
BlockHandle(uint64_t offset, uint64_t size);
// The offset of the block in the file. // The offset of the block in the file.
uint64_t offset() const { return offset_; } uint64_t offset() const { return offset_; }
@ -38,12 +39,24 @@ class BlockHandle {
void EncodeTo(std::string* dst) const; void EncodeTo(std::string* dst) const;
Status DecodeFrom(Slice* input); Status DecodeFrom(Slice* input);
// if the block handle's offset and size are both "0", we will view it
// as a null block handle that points to no where.
bool IsNull() const {
return offset_ == 0 && size_ == 0;
}
static const BlockHandle& NullBlockHandle() {
return kNullBlockHandle;
}
// Maximum encoding length of a BlockHandle // Maximum encoding length of a BlockHandle
enum { kMaxEncodedLength = 10 + 10 }; enum { kMaxEncodedLength = 10 + 10 };
private: private:
uint64_t offset_; uint64_t offset_ = 0;
uint64_t size_; uint64_t size_ = 0;
static const BlockHandle kNullBlockHandle;
}; };
// Footer encapsulates the fixed information stored at the tail // Footer encapsulates the fixed information stored at the tail
@ -116,8 +129,13 @@ extern Status UncompressBlockContents(const char* data,
// Implementation details follow. Clients should ignore, // Implementation details follow. Clients should ignore,
inline BlockHandle::BlockHandle() inline BlockHandle::BlockHandle()
: offset_(~static_cast<uint64_t>(0)), : BlockHandle(~static_cast<uint64_t>(0),
size_(~static_cast<uint64_t>(0)) { ~static_cast<uint64_t>(0)) {
}
inline BlockHandle::BlockHandle(uint64_t offset, uint64_t size)
: offset_(offset),
size_(size) {
} }
} // namespace rocksdb } // namespace rocksdb

Loading…
Cancel
Save