mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-26 07:30:54 +00:00
953a885ebf
Summary: Currently users have no idea a key is add, delete or merge from TablePropertiesCollector call back. Add a new function to add it. Also refactor the codes so that (1) make table property collector and internal table property collector two separate data structures with the later one now exposed (2) table builders only receive internal table properties Test Plan: Add cases in table_properties_collector_test to cover both of old and new ways of using TablePropertiesCollector. Reviewers: yhchiang, igor.sugak, rven, igor Reviewed By: rven, igor Subscribers: meyering, yoshinorim, maykov, leveldb, dhruba Differential Revision: https://reviews.facebook.net/D35373
125 lines
3.9 KiB
C++
125 lines
3.9 KiB
C++
// Copyright (c) 2013, 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.
|
|
//
|
|
// This file defines a collection of statistics collectors.
|
|
#pragma once
|
|
|
|
#include "rocksdb/table_properties.h"
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace rocksdb {
|
|
|
|
struct InternalKeyTablePropertiesNames {
|
|
static const std::string kDeletedKeys;
|
|
};
|
|
|
|
// Base class for internal table properties collector.
|
|
class IntTblPropCollector {
|
|
public:
|
|
virtual ~IntTblPropCollector() {}
|
|
virtual Status Finish(UserCollectedProperties* properties) = 0;
|
|
|
|
virtual const char* Name() const = 0;
|
|
|
|
// @params key the user key that is inserted into the table.
|
|
// @params value the value that is inserted into the table.
|
|
virtual Status InternalAdd(const Slice& key, const Slice& value,
|
|
uint64_t file_size) = 0;
|
|
|
|
virtual UserCollectedProperties GetReadableProperties() const = 0;
|
|
};
|
|
|
|
// Facrtory for internal table properties collector.
|
|
class IntTblPropCollectorFactory {
|
|
public:
|
|
virtual ~IntTblPropCollectorFactory() {}
|
|
// has to be thread-safe
|
|
virtual IntTblPropCollector* CreateIntTblPropCollector() = 0;
|
|
|
|
// The name of the properties collector can be used for debugging purpose.
|
|
virtual const char* Name() const = 0;
|
|
};
|
|
|
|
// Collecting the statistics for internal keys. Visible only by internal
|
|
// rocksdb modules.
|
|
class InternalKeyPropertiesCollector : public IntTblPropCollector {
|
|
public:
|
|
virtual Status InternalAdd(const Slice& key, const Slice& value,
|
|
uint64_t file_size) override;
|
|
|
|
virtual Status Finish(UserCollectedProperties* properties) override;
|
|
|
|
virtual const char* Name() const override {
|
|
return "InternalKeyPropertiesCollector";
|
|
}
|
|
|
|
UserCollectedProperties GetReadableProperties() const override;
|
|
|
|
private:
|
|
uint64_t deleted_keys_ = 0;
|
|
};
|
|
|
|
class InternalKeyPropertiesCollectorFactory
|
|
: public IntTblPropCollectorFactory {
|
|
public:
|
|
virtual IntTblPropCollector* CreateIntTblPropCollector() override {
|
|
return new InternalKeyPropertiesCollector();
|
|
}
|
|
|
|
virtual const char* Name() const override {
|
|
return "InternalKeyPropertiesCollectorFactory";
|
|
}
|
|
};
|
|
|
|
// When rocksdb creates a new table, it will encode all "user keys" into
|
|
// "internal keys", which contains meta information of a given entry.
|
|
//
|
|
// This class extracts user key from the encoded internal key when Add() is
|
|
// invoked.
|
|
class UserKeyTablePropertiesCollector : public IntTblPropCollector {
|
|
public:
|
|
// transfer of ownership
|
|
explicit UserKeyTablePropertiesCollector(TablePropertiesCollector* collector)
|
|
: collector_(collector) {}
|
|
|
|
virtual ~UserKeyTablePropertiesCollector() {}
|
|
|
|
virtual Status InternalAdd(const Slice& key, const Slice& value,
|
|
uint64_t file_size) override;
|
|
|
|
virtual Status Finish(UserCollectedProperties* properties) override;
|
|
|
|
virtual const char* Name() const override { return collector_->Name(); }
|
|
|
|
UserCollectedProperties GetReadableProperties() const override;
|
|
|
|
protected:
|
|
std::unique_ptr<TablePropertiesCollector> collector_;
|
|
};
|
|
|
|
class UserKeyTablePropertiesCollectorFactory
|
|
: public IntTblPropCollectorFactory {
|
|
public:
|
|
explicit UserKeyTablePropertiesCollectorFactory(
|
|
std::shared_ptr<TablePropertiesCollectorFactory> user_collector_factory)
|
|
: user_collector_factory_(user_collector_factory) {}
|
|
virtual IntTblPropCollector* CreateIntTblPropCollector() override {
|
|
return new UserKeyTablePropertiesCollector(
|
|
user_collector_factory_->CreateTablePropertiesCollector());
|
|
}
|
|
|
|
virtual const char* Name() const override {
|
|
return user_collector_factory_->Name();
|
|
}
|
|
|
|
private:
|
|
std::shared_ptr<TablePropertiesCollectorFactory> user_collector_factory_;
|
|
};
|
|
|
|
} // namespace rocksdb
|