Repository navigation
impl: KVS Instance state registry [cpp] - #538
karolnowak wants to merge 1 commit into
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run --lockfile_mode=error //:license-checkStatus: Click to expand output |
3168f21 to
f6be05e
Compare
|
Documentation preview for this pull request is available at: |
f6be05e to
cc7e450
Compare
arkjedrz
left a comment
There was a problem hiding this comment.
Review is probably not exhaustive, but discussions might be needed at this points.
cc7e450 to
e734e41
Compare
e734e41 to
614a402
Compare
614a402 to
62b64f8
Compare
62b64f8 to
e30a0d8
Compare
e30a0d8 to
4ee69cc
Compare
8cb4da0 to
c86f424
Compare
c86f424 to
8c87d3a
Compare
8c87d3a to
f2984c1
Compare
f2984c1 to
6071260
Compare
6071260 to
46aae14
Compare
46aae14 to
af49c4e
Compare
af49c4e to
a72c746
Compare
| } | ||
|
|
||
| kvs.state_ = entry; | ||
| return std::move(kvs); |
There was a problem hiding this comment.
here you are providing new instance for same storage :
- each instance will has it's own mutex but both writing to same storage file .
what if both instances triggered Flush() ???
i would recommend to make builder returns shared pointer to kvs , and we can have multiple pointers to same kvs instance.
There was a problem hiding this comment.
here you are providing new instance for same storage :
No, no new instance is created here. The "handle" to the existing instance is provided.
Considering your case, two Kvs objects will be created which will share the same instance, that said, there will be only one mutex as two objects will be using the mutex the given instance provides.
Kvs_1 Kvs_2
| |
| |
\ /
\ /
INSTANCE_1
|
the mutex of the instance
then
Kvs_1.Flush() will use `INSTANCE_1.mutex`
Kvs_2.Flush() will use `INSTANCE_1.mutex`
i would recommend to make builder returns shared pointer to kvs , and we can have multiple pointers to same kvs instance.
When you look at kvs.h file, you will find std::shared_ptr<KvsInstanceState> state_;. It is kind of what you are expecting. The builder return a new Kvs object that has the handle to Pimpl (or internal members that are not exposed).
Nevertheless, I agree with you regarding this that the builder should return the shared pointer to kvs - I came up with the same idea at first, however, I wanted to be aligned with the Rust impl. I would do it as a follow up task, I believe we should first refine the public interface so that we know what we want to provide: Kvs object or std::shared_ptr.
There was a problem hiding this comment.
Other reported issues:
score/kvs/docs/safety_analysis/dfa.rst:57, score/kvs/docs/safety_analysis/dfa.rst:104, coding-standards.yaml:125
- The DFA row says "Function arguments only; no global data (
comp_req__kvs__multi_instance)". The commit adds a process-wide mutable registry, so that justification is false, and the "Data per instance" row at line 104 needs the registry added. - The new
kvs-instance-state-registrydeviation covers only thestaticline. The registry's public mutablemutexandarraymembers are not addressed.
| } | ||
| } | ||
|
|
||
| bool KvsInstanceState::operator==(const KvsInstanceState& other) const noexcept |
| (max_storage_bytes == other.max_storage_bytes); | ||
| } | ||
|
|
||
| bool KvsInstanceState::operator!=(const KvsInstanceState& other) const noexcept |
| /// Handles opened for the same filename prefix share this state, including the | ||
| /// snapshot and storage limits. The storage limit applies to this store's files, | ||
| /// not to storage used by other KVS instances. | ||
| struct KvsInstanceState final |
A registry to share the same state of a given KVS Instance. It avoids loading a given KVS Instance from disk again which could otherwise lead to the use of different versions of the same instance. Signed-off-by: Karol Nowak <Karol.Novak.Ext@qorix.ai>
Problem
The existing [cpp] impl allows to load the same instance from disk many times.
After loading, each KVS operates on its own non-shared entries.
This can affect data integrity when two KVSs, which refer to the same instance, save their entries on disk.
Solution
A registry to share the same state of a given KVS Instance.
Note
At the moment, the registry implements the Singleton pattern and is hidden from the lib user.
I believe that the registry should be rewritten so that: