-
Notifications
You must be signed in to change notification settings - Fork 259
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
Add db set store #4154
Add db set store #4154
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe recent changes to the FlexiDag project involve significant updates to the consensus database and type structures. These include new schema definitions, caching mechanisms, and database operations, along with modifications to handle these new features. The updates improve the functionality for reachability data, batch writing, and data caching. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ConsensusDb
participant Cache
participant FlexiDagStorage
User->>ConsensusDb: initialize()
ConsensusDb->>Cache: Create CachedDbSetAccess
User->>ConsensusDb: append_child()
ConsensusDb->>Cache: Update children_access
User->>ConsensusDb: insert_future_covering_item()
ConsensusDb->>Cache: Update fcs_access
User->>FlexiDagStorage: write_batch()
FlexiDagStorage->>RocksDB: Write data with batch
User->>FlexiDagStorage: flush_opt(wait)
FlexiDagStorage->>RocksDB: Flush data with options
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
eeb2672
to
b6c8dbc
Compare
Benchmark for bdb9978Click to view benchmark
|
b6c8dbc
to
0050f48
Compare
Benchmark for 2719b3cClick to view benchmark
|
Benchmark for c631527Click to view benchmark
|
Benchmark for 5377aeeClick to view benchmark
|
Benchmark for 13702dbClick to view benchmark
|
@simonjiao: I will review the changes. Actions performedReview triggered.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (11)
- flexidag/src/consensusdb/access.rs (1 hunks)
- flexidag/src/consensusdb/consensus_reachability.rs (1 hunks)
- flexidag/src/consensusdb/consensus_relations.rs (8 hunks)
- flexidag/src/consensusdb/db.rs (3 hunks)
- flexidag/src/consensusdb/item.rs (1 hunks)
- flexidag/src/consensusdb/mod.rs (1 hunks)
- flexidag/src/consensusdb/set_access.rs (1 hunks)
- flexidag/src/consensusdb/writer.rs (4 hunks)
- storage/src/db_storage/mod.rs (4 hunks)
- storage/src/storage.rs (2 hunks)
- sync/tests/common_test_sync_libs.rs (2 hunks)
Files skipped from review due to trivial changes (5)
- flexidag/src/consensusdb/access.rs
- flexidag/src/consensusdb/consensus_reachability.rs
- flexidag/src/consensusdb/item.rs
- storage/src/storage.rs
- sync/tests/common_test_sync_libs.rs
Additional comments not posted (26)
flexidag/src/consensusdb/mod.rs (1)
12-12
: Addition ofset_access
module looks good.The new module
set_access
is correctly declared.flexidag/src/consensusdb/writer.rs (4)
11-15
: Addition ofput_inner
method toDbWriter
trait looks good.The method signature is correct and follows the trait's style.
44-56
: Addition ofput_inner
method toDirectDbWriter
implementation looks good.The method correctly follows the
put
operation logic and handles errors appropriately.
83-90
: Addition ofput_inner
method toBatchDbWriter
implementation looks good.The method correctly follows the
put
operation logic and handles errors appropriately.
104-111
: Addition ofput_inner
method toDbWriter
implementation for&mut T
looks good.The method correctly delegates the
put_inner
operation.flexidag/src/consensusdb/db.rs (3)
110-112
: Addition ofwrite_batch
method toFlexiDagStorage
looks good.The method correctly delegates the batch write operation and handles errors appropriately.
114-122
: Addition ofwrite_batch_opt
method toFlexiDagStorage
looks good.The method correctly delegates the batch write operation with options and handles errors appropriately.
124-129
: Addition offlush_opt
method toFlexiDagStorage
looks good.The method correctly delegates the flush operation and handles errors appropriately.
flexidag/src/consensusdb/set_access.rs (6)
15-21
: Addition ofDbSetAccess::new
method looks good.The method correctly initializes the
DbSetAccess
struct.
23-27
: Addition ofDbSetAccess::read
method looks good.The method correctly reads data from the database and handles errors appropriately.
29-43
: Addition ofDbSetAccess::write
method looks good.The method correctly writes data to the database and handles errors appropriately.
45-70
: Addition ofDbSetAccess::seek_iterator
method looks good.The method correctly seeks the iterator in the database and handles errors appropriately.
79-84
: Addition ofCachedDbSetAccess::new
method looks good.The method correctly initializes the
CachedDbSetAccess
struct.
104-121
: Addition ofCachedDbSetAccess::write
method looks good.The method correctly writes data to the database with caching and handles errors appropriately.
flexidag/src/consensusdb/consensus_relations.rs (7)
6-6
: Import added: Ensure usage ofCachedDbSetAccess
.The import of
CachedDbSetAccess
seems appropriate. Verify its correct usage in the file.
33-33
: Schema definition modified: Verify correctness.The
RelationChildren
schema definition was changed fromArc<Vec<Hash>>
toHash
. Ensure that the new definition is correct and compatible with the rest of the code.
63-69
: ValueCodec implementation modified: Verify correctness.The
ValueCodec
implementation forRelationChildren
was changed fromArc<Vec<Hash>>
toHash
. Ensure that the new implementation is correct and compatible with the rest of the code.
79-79
: Field type updated: Verify correctness.The
children_access
field inDbRelationsStore
was updated to useCachedDbSetAccess
. Ensure that the new field type is correct and used appropriately in the struct.
88-88
: Constructor updated: Verify correctness.The constructor of
DbRelationsStore
was updated to initialize the newchildren_access
field type. Ensure that the constructor correctly initializes the new field type.
110-116
: Method updated: Verify correctness.The
insert_batch
method was updated to handle the newchildren_access
field type. Ensure that the method correctly performs the necessary operations with the new field type.
128-132
: Method updated: Verify correctness.The
get_children
method was updated to use the newchildren_access
field type. Ensure that the method correctly retrieves the children using the new field type.storage/src/db_storage/mod.rs (5)
471-479
: Method added: Verify correctness.The
raw_iterator_cf_opt
method was added. Ensure that the method is correctly implemented and used appropriately in the file.
481-483
: Method added: Verify correctness.The
raw_iterator_opt
method was added. Ensure that the method is correctly implemented and used appropriately in the file.
Line range hint
485-492
:
Method added: Verify correctness.The
raw_get_pinned_cf
method was added. Ensure that the method is correctly implemented and used appropriately in the file.
497-500
: Method added: Verify correctness.The
raw_write_batch
method was added. Ensure that the method is correctly implemented and used appropriately in the file.
502-510
: Methods added: Verify correctness.The
raw_write_batch_opt
andflush_opt
methods were added. Ensure that the methods are correctly implemented and used appropriately in the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (1)
flexidag/tests/tests.rs (1)
163-165
: Inconsistent return type forget_children
function.The
get_children
function has inconsistent return types across different files. While some instances returnArc<RwLock<Vec<HashValue>>>
, others returnBlockHashes
. This inconsistency can lead to potential issues.
- Files and Lines to Review:
sync/src/tasks/mock.rs
: Line 1flexidag/src/reachability/tests.rs
: Line 1flexidag/src/reachability/extensions.rs
: Lines 1, 2flexidag/src/reachability/inquirer.rs
: Line 1flexidag/src/reachability/reindex.rs
: Lines 1, 2, 3, 4, 5, 6, 7, 8flexidag/src/blockdag.rs
: Line 1flexidag/src/consensusdb/consensus_relations.rs
: Lines 1, 2flexidag/src/consensusdb/consensus_reachability.rs
: Lines 1, 2, 3, 4, 5, 6, 7, 8chain/service/src/chain_service.rs
: Line 1Please ensure that all instances of
get_children
returnArc<RwLock<Vec<HashValue>>>
to maintain consistency across the codebase.Analysis chain
LGTM! But verify the function usage in the codebase.
The code changes are approved.
However, ensure that all function calls to
get_children
match the new return type.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify all function calls to `get_children` match the new return type. # Test: Search for the function usage. Expect: Only occurances of the new return type. rg --type rust -A 5 $'get_children'Length of output: 13515
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (6)
- chain/service/src/chain_service.rs (1 hunks)
- flexidag/src/blockdag.rs (2 hunks)
- flexidag/src/consensusdb/consensus_relations.rs (9 hunks)
- flexidag/src/reachability/relations_service.rs (2 hunks)
- flexidag/tests/tests.rs (2 hunks)
- sync/src/tasks/mock.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- flexidag/src/consensusdb/consensus_relations.rs
Additional comments not posted (5)
flexidag/src/reachability/relations_service.rs (1)
27-29
: LGTM!The change to return
Arc<RwLock<Vec<HashValue>>>
for better concurrency handling is appropriate.flexidag/src/blockdag.rs (1)
243-248
: LGTM!The change to return
Arc<RwLock<Vec<HashValue>>>
for better concurrency handling is appropriate.sync/src/tasks/mock.rs (1)
400-400
: LGTM!The change to handle read and iteration over block children using
Arc<RwLock<Vec<HashValue>>>
is appropriate.chain/service/src/chain_service.rs (1)
451-451
: LGTM!The change to handle read and iteration over block children using
Arc<RwLock<Vec<HashValue>>>
is appropriate.flexidag/tests/tests.rs (1)
224-233
: LGTM! But verify the function usage in the codebase.The code changes are approved.
However, ensure that all function calls to
get_children
match the new return type.
Benchmark for dc596bfClick to view benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (5)
flexidag/src/types/reachability.rs (1)
1-13
: Struct definition update: Removal of fieldsThe removal of
children
andfuture_covering_set
fields fromReachabilityData
struct has not been fully propagated throughout the codebase. The following files still contain references to these fields and need to be updated or removed:
sync/tests/common_test_sync_libs.rs
: Lines 1-5sync/src/verified_rpc_client.rs
: Lines 1-10sync/src/tasks/mock.rs
: Lines 1-10sync/src/tasks/tests.rs
: Lines 1-10sync/src/tasks/mod.rs
: Lines 1-10sync/src/tasks/block_sync_task.rs
: Lines 1-10storage/src/tests/test_block.rs
: Lines 1-10storage/src/block/mod.rs
: Lines 1-10network-rpc/src/rpc.rs
: Lines 1-10network-rpc/api/src/lib.rs
: Lines 1-10flexidag/src/blockdag.rs
: Lines 1-10flexidag/src/reachability/relations_service.rs
: Lines 1-10flexidag/tests/tests.rs
: Lines 1-10flexidag/src/ghostdag/protocol.rs
: Lines 1-10flexidag/src/reachability/tests.rs
: Lines 1-10flexidag/src/reachability/reindex.rs
: Lines 1-10flexidag/src/reachability/inquirer.rs
: Lines 1-10flexidag/src/consensusdb/consensus_relations.rs
: Lines 1-10flexidag/src/consensusdb/consensus_reachability.rs
: Lines 1-10flexidag/src/reachability/extensions.rs
: Lines 1-10flexidag/src/reachability/tree.rs
: Lines 1-10chain/api/src/service.rs
: Lines 1-10chain/service/src/chain_service.rs
: Lines 1-10commons/forkable-jellyfish-merkle/src/lib.rs
: Lines 1-10commons/forkable-jellyfish-merkle/src/jellyfish_merkle_test.rs
: Lines 1-10commons/forkable-jellyfish-merkle/src/iterator/mod.rs
: Lines 1-10commons/forkable-jellyfish-merkle/src/node_type/node_type_test.rs
: Lines 1-10commons/forkable-jellyfish-merkle/src/node_type/mod.rs
: Lines 1-10commons/accumulator/src/tree.rs
: Lines 1-10Please ensure that all references and manipulations related to these fields are updated or removed in the entire codebase to maintain consistency.
Analysis chain
Struct definition update: Removal of fields
The removal of
children
andfuture_covering_set
fields fromReachabilityData
struct simplifies the data structure but could have broader implications on data management and access patterns in the system. Ensure that all references and manipulations related to these fields are updated or removed in the entire codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify that all references to the removed fields are updated or removed. # Test: Search for the usage of `children` and `future_covering_set`. Expect: No occurrences. rg --type rust -A 5 $'children|future_covering_set'Length of output: 97908
flexidag/src/consensusdb/consensus_reachability.rs (4)
Line range hint
14-55
: Introduction of new caching mechanisms and schema definitionsThe addition of new schemas (
ReachabilityChildren
,ReachabilityFcs
) and caching mechanisms (CachedDbSetAccess
) appears to enhance data handling efficiency. Ensure that these new schemas are integrated properly across the system, and consider adding unit tests to validate their behavior and performance.Consider further optimization by exploring fixed-length constants for store prefixes as noted in the TODO comment. This could potentially improve performance in key lookups.
Line range hint
65-141
: Codec implementations for new schemasThe implementation of
KeyCodec
andValueCodec
for the new schemas is crucial for ensuring data integrity and efficient serialization/deserialization. Review and test these implementations thoroughly to prevent data corruption or performance issues.Consider adding more detailed error handling or logging within these codec implementations to aid in debugging and maintenance.
Line range hint
222-239
: Method updates inDbReachabilityStore
The updates to methods like
append_child
andinsert_future_covering_item
to utilize the new caching layers need careful testing to ensure they handle data correctly and efficiently.Would you like me to help in setting up more comprehensive tests for these updated methods?
Line range hint
270-587
: Handling of children and future covering sets in reader methodsThe methods
get_children
andget_future_covering_set
now utilize the new caching layers. It's important to ensure that these methods return accurate and up-to-date data. The TODO comments suggest potential improvements like removing unnecessary cloning, which should be addressed to optimize performance.- Ok(Arc::new(self.children_acess.read(hash)?.read().clone())) + Ok(self.children_acess.read(hash)?.read().clone())This change removes unnecessary use of
Arc
which could improve performance by reducing memory overhead.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- flexidag/src/consensusdb/consensus_reachability.rs (18 hunks)
- flexidag/src/consensusdb/set_access.rs (1 hunks)
- flexidag/src/types/reachability.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
- flexidag/src/consensusdb/set_access.rs
Additional comments not posted (1)
flexidag/src/consensusdb/consensus_reachability.rs (1)
Line range hint
147-209
: Updates toDbReachabilityStore
with new access layersThe modifications to
DbReachabilityStore
to handlechildren_access
andfcs_access
are significant. It's essential to ensure that these changes do not disrupt existing functionalities and that they are compatible with the rest of the system's architecture.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- flexidag/src/consensusdb/db.rs (4 hunks)
Files skipped from review as they are similar to previous changes (1)
- flexidag/src/consensusdb/db.rs
Benchmark for 94e2b50Click to view benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- flexidag/src/consensusdb/consensus_reachability.rs (18 hunks)
- flexidag/src/consensusdb/set_access.rs (1 hunks)
- flexidag/src/types/interval.rs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- flexidag/src/consensusdb/consensus_reachability.rs
- flexidag/src/consensusdb/set_access.rs
Additional comments not posted (1)
flexidag/src/types/interval.rs (1)
4-4
: LGTM! The addition ofPartialOrd
andOrd
traits is appropriate.This change allows
Interval
instances to be used in ordered collections and comparisons.
Benchmark for 6a23ea7Click to view benchmark
|
Benchmark for 71bb247Click to view benchmark
|
b917f34
to
e7e94b1
Compare
Benchmark for 4bb28adClick to view benchmark
|
afece09
to
e1d180d
Compare
Benchmark for cc4a9bdClick to view benchmark
|
* mark empty children for new block
1. sort keys before caching
7b8c507
to
b801f80
Compare
Benchmark for 0d76fe2Click to view benchmark
|
c8f2a3a
to
5c409e6
Compare
1. fix a typo 2. remove unused codes
5c409e6
to
8cb13cf
Compare
Benchmark for 69ee51dClick to view benchmark
|
Pull request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: N/A
What is the new behavior?
Other information
Summary by CodeRabbit
Enhancements
Interval
struct to support more operations.Removed
ReachabilityData
struct, simplifying data structures.New Features
Bug Fixes