facebook / facebook/rocksdb

Need a means of sharing configuration data between objects

Open
#6,644 2 comments 0 reactions 1 assignee Claimed by @mrambacher View on GitHub
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

The Options interfaces allow objects to be serialized to strings and stored in initialization files. Each object serializes and stores its objects individually.

However, some objects may potentially be shared between these configured objects. For example, there may be one block cache shared across the multiple table factories in the system. There is currently no mechanism of representing these shared configurations via the options file.

I would propose the following:
-> The ObjectRegistry be expanded to hold "configurations". Configurations would have an "ID", "Type" (Environment, Cache, etc), an "options string" representing the serialized form of this object, and a weak_ptr.
-> When the Customizable class goes to create a new object (CreateFromString), it would first look for it in the ObjectRegistry. If the ID is found there, the one in the registry is used. If not, a new object is created as today. Note that CreateFromString for each type that is registered would need to follow this pattern.
-> When a Customizable object is converted to a string, it sees if it is in the ObjectRegistry. If so, only the ID is written (and not the entire configuration).
-> Unique IDs can be generated for objects added to the Registry by combining the Name() of the object with its address (e.g. LRUCache@0xdeadbeef).
-> The configurations will be serialized and written to the options file. This will allow them to be re-established on a restart.

Classes that would benefit from this sort of registry include Cache, MemoryAllocator, Logger, and Env (there may be others but this is the obvious first pass list).

One question is when would objects be registered and unregistered. Is it done automatically or is there another step (API call) a developer would be required to take? How would a configuration in the registry be updated?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.