Skip to content

Commit

Permalink
Add Exension and ExtensionFactory classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrambacher committed Apr 18, 2019
1 parent c6ced75 commit c2c8aaa
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
67 changes: 67 additions & 0 deletions include/rocksdb/extensions.h
@@ -0,0 +1,67 @@
// An Env is an interface used by the rocksdb implementation to access
// operating system functionality like the filesystem etc. Callers
// may wish to provide a custom Env object when opening a database to
// get fine gain control; e.g., to rate limit file system operations.
//
// All Env implementations are safe for concurrent access from
// multiple threads without any external synchronization.

#ifndef STORAGE_ROCKSDB_INCLUDE_EXTENSION_H_
#define STORAGE_ROCKSDB_INCLUDE_EXTENSION_H_

#include <string>
#include <vector>
#include <unordered_map>
#include "rocksdb/status.h"

namespace rocksdb {
struct DBOptions;
struct ColumnFamilyOptions;

using std::unique_ptr;
using std::shared_ptr;


class Extension {
public:
virtual ~Extension() {}
// Names starting with "rocksdb." are reserved and should not be used
// by any clients of this package.
virtual const char* Name() const = 0;

// Sanitizes the specified DB Options and ColumnFamilyOptions.
//
// If the function cannot find a way to sanitize the input DB Options,
// a non-ok Status will be returned.
virtual Status SetOptions(const std::unordered_map<std::string, std::string> &,
const DBOptions &,
const ColumnFamilyOptions &) const {
return Status::OK();
}

// Return a string that contains printable format of table configurations.
// RocksDB prints configurations at DB Open().
virtual std::string GetPrintableTableOptions() const {
return "";
}

virtual Status GetOptionString(std::string* /*opt_string*/,
const std::string& /*delimiter*/) const {
return Status::NotSupported(
"The table factory doesn't implement GetOptionString().");
}

};

class EventListener;

class ExtensionFactory {
public:
virtual ~ExtensionFactory() { }
virtual Status LoadEventListener(const std::string & name, std::shared_ptr<EventListener> * ) {
return Status::NotFound("Event Listener not found", name);
}
};
} // namespace rocksdb

#endif // STORAGE_ROCKSDB_INCLUDE_EXTENSION_H_
5 changes: 4 additions & 1 deletion include/rocksdb/listener.h
Expand Up @@ -12,6 +12,7 @@
#include <unordered_map>
#include <vector>
#include "rocksdb/compaction_job_stats.h"
#include "rocksdb/extensions.h"
#include "rocksdb/status.h"
#include "rocksdb/table_properties.h"

Expand Down Expand Up @@ -285,7 +286,9 @@ struct ExternalFileIngestionInfo {
// the current thread holding any DB mutex. This is to prevent potential
// deadlock and performance issue when using EventListener callback
// in a complex way.
class EventListener {
class EventListener: public Extension {
public: // Methods from Extension
virtual const char * Name() const { return ""; }
public:
// A callback function to RocksDB which will be called whenever a
// registered RocksDB flushes a file. The default implementation is
Expand Down
3 changes: 2 additions & 1 deletion include/rocksdb/table.h
Expand Up @@ -24,6 +24,7 @@

#include "rocksdb/cache.h"
#include "rocksdb/env.h"
#include "rocksdb/extensions.h"
#include "rocksdb/iterator.h"
#include "rocksdb/options.h"
#include "rocksdb/status.h"
Expand Down Expand Up @@ -435,7 +436,7 @@ extern TableFactory* NewCuckooTableFactory(
class RandomAccessFileReader;

// A base class for table factories.
class TableFactory {
class TableFactory : public Extension {
public:
virtual ~TableFactory() {}

Expand Down

0 comments on commit c2c8aaa

Please sign in to comment.