-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need a means of sharing configuration data between objects #6644
Comments
I'm concerned that the factory interface
requires any shared objects to live forever. Or more precisely: exactly as long as the factory. If the factory keeps ownership, it doesn't know that it's ever safe to deallocate (before its own deallocation); alternately, the factory cannot share the object if it passes on ownership. This suggests a shared_ptr+weak_ptr solution. Though it might seem heavy-handed, memory leaks can be nightmares for RocksDB users. A possible alternative would be requiring a compile-time name to be used to (uniquely) identify a shared object. This effectively limits their number. |
This issue is being addressed in #8658 by the addition of ManagedObjects. Here is the basic premise:
ManagedObjects are stored as weak/shared pointers and must be an extension of Customizable. By using weak pointers, if an object associated with a name is deleted, the map entry still exists but the object does not. This distinction means that f an object is destroyed, it will no longer be Managed and the name can be re-used/point to a new object. Here is an example of how ManagedObjects can be used to store and retrieve a Cache from the Options file.
When reading in Options from a string/properties file, if there are two Caches with the same "long" ID, these two objects will share the same cache object. Note that this model does not require that ManagedObjects in the registry be serialized/saved independently. It is the responsibility of each "Type" (Cache, etc) to determine that it is a "ManagedObject" and interact with the ObjectRegistry as appropriate. In fact, the ManagedObject list is not required during serialization. Furthermore, the ManagedObject does not itself know of its registration in an ObjectRegistry. Note that if two independent ObjectRegistry objects are used, then the same name in both registries may refer to different objects. For example, if a TableFactory is serialized with ObjectRegistryA and re-created with the same ObjectRegistryA, then the caches in the two table factories will be the same instance. However, if the serialization happens with ObjectRegistryA and the re-creation with ObjectRegistryB, then the caches in the two table factories may be different (to guarantee they are the same, the Cache should be registered with the "Default" ObjectRegistry). |
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?
The text was updated successfully, but these errors were encountered: