-
Notifications
You must be signed in to change notification settings - Fork 289
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
Write the dag relationship in batch #4304
Draft
jackzhhuang
wants to merge
36
commits into
dag-master
Choose a base branch
from
write-batch
base: dag-master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
a6403bc
no store the sync dag block
jackzhhuang c173559
add rm sync in kube file
jackzhhuang 48c9bac
use ghostdata to verify the dag block
jackzhhuang c8b259a
use ghodata if the verify is not correct
jackzhhuang 1a6c851
use ghostdata instead of verify
jackzhhuang 264a5d6
add verification code for discovering the blue blocks error
jackzhhuang 3b2a145
verify and if it fails it use ghostdata
jackzhhuang 197bc4f
bail out if the ghost data checking is wrong
jackzhhuang adfcb23
remove to print red blocks avoiding lots log data
jackzhhuang e06797d
test dag verification
jackzhhuang 86ee296
add log to trace
jackzhhuang 8250159
add reachability data with parents
jackzhhuang b0a9dde
add worker scheduler for stopping the worker gracefully
jackzhhuang f5b729c
tell the worker to stop before a new syncp process starts
jackzhhuang 39aaa26
add test and log
jackzhhuang 5b75651
add drop helper for scheduler
jackzhhuang 573bc89
fix fmt
jackzhhuang e3dca70
use unordered_mergeset_without_selected_parent when storing into the …
jackzhhuang 248b7fb
rm commented codes
jackzhhuang e4eff6c
add uncle test in reachability
jackzhhuang a516332
add worker scheduler for stopping the worker gracefully
jackzhhuang 289c05b
tell the worker to stop before a new syncp process starts
jackzhhuang 7000a99
add test and log
jackzhhuang 57f73af
add drop helper for scheduler
jackzhhuang 3ff4ab4
cancel when sync is interrupted
jackzhhuang 71c8f01
Merge branch 'loop-break-sync' of github.com:starcoinorg/starcoin int…
jackzhhuang ed41063
add batch write
jackzhhuang d19e726
add cache and db test case
jackzhhuang 4f15309
add batch write parent and children in dag
jackzhhuang 63ab93a
add push the new child in parent's vec
jackzhhuang 0685111
fix fmt
jackzhhuang 327649c
1, fix encode bug
jackzhhuang 216d7b4
1, flush cache if batch writing done
jackzhhuang aa0c54d
no use sync writing
jackzhhuang 018e02d
fix sync_block_process
jackzhhuang 799f99d
revert the mergeset code
jackzhhuang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
use super::schema::{KeyCodec, ValueCodec}; | ||
use super::{ | ||
db::DBStorage, | ||
prelude::{BatchDbWriter, CachedDbAccess, DirectDbWriter, StoreError}, | ||
prelude::{CachedDbAccess, StoreError}, | ||
}; | ||
use crate::define_schema; | ||
use rocksdb::WriteBatch; | ||
use starcoin_crypto::HashValue as Hash; | ||
use starcoin_storage::batch::{WriteBatch, WriteBatchData, WriteBatchWithColumn}; | ||
use starcoin_storage::storage::{InnerStore, WriteOp}; | ||
use starcoin_types::blockhash::{BlockHashes, BlockLevel}; | ||
use std::collections::HashMap; | ||
use std::sync::Arc; | ||
|
||
/// Reader API for `RelationsStore`. | ||
pub trait RelationsStoreReader { | ||
fn get_parents(&self, hash: Hash) -> Result<BlockHashes, StoreError>; | ||
|
@@ -90,41 +91,6 @@ impl DbRelationsStore { | |
pub fn clone_with_new_cache(&self, cache_size: usize) -> Self { | ||
Self::new(Arc::clone(&self.db), self.level, cache_size) | ||
} | ||
|
||
pub fn insert_batch( | ||
&mut self, | ||
batch: &mut WriteBatch, | ||
hash: Hash, | ||
parents: BlockHashes, | ||
) -> Result<(), StoreError> { | ||
if self.has(hash)? { | ||
return Err(StoreError::KeyAlreadyExists(hash.to_string())); | ||
} | ||
|
||
// Insert a new entry for `hash` | ||
self.parents_access | ||
.write(BatchDbWriter::new(batch, &self.db), hash, parents.clone())?; | ||
|
||
// The new hash has no children yet | ||
self.children_access.write( | ||
BatchDbWriter::new(batch, &self.db), | ||
hash, | ||
BlockHashes::new(Vec::new()), | ||
)?; | ||
|
||
// Update `children` for each parent | ||
for parent in parents.iter().cloned() { | ||
let mut children = (*self.get_children(parent)?).clone(); | ||
children.push(hash); | ||
self.children_access.write( | ||
BatchDbWriter::new(batch, &self.db), | ||
parent, | ||
BlockHashes::new(children), | ||
)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
||
impl RelationsStoreReader for DbRelationsStore { | ||
|
@@ -147,35 +113,69 @@ impl RelationsStoreReader for DbRelationsStore { | |
} | ||
|
||
impl RelationsStore for DbRelationsStore { | ||
/// See `insert_batch` as well | ||
/// TODO: use one function with DbWriter for both this function and insert_batch | ||
fn insert(&self, hash: Hash, parents: BlockHashes) -> Result<(), StoreError> { | ||
if self.has(hash)? { | ||
return Err(StoreError::KeyAlreadyExists(hash.to_string())); | ||
} | ||
|
||
// Insert a new entry for `hash` | ||
self.parents_access | ||
.write(DirectDbWriter::new(&self.db), hash, parents.clone())?; | ||
let mut parent_to_children = HashMap::new(); | ||
parent_to_children.insert(hash, vec![]); | ||
|
||
// The new hash has no children yet | ||
self.children_access.write( | ||
DirectDbWriter::new(&self.db), | ||
hash, | ||
BlockHashes::new(Vec::new()), | ||
)?; | ||
|
||
// Update `children` for each parent | ||
for parent in parents.iter().cloned() { | ||
let mut children = (*self.get_children(parent)?).clone(); | ||
let mut children = match self.get_children(parent) { | ||
Ok(children) => (*children).clone(), | ||
Err(e) => match e { | ||
StoreError::KeyNotFound(_) => vec![], | ||
_ => return std::result::Result::Err(e), | ||
}, | ||
}; | ||
children.push(hash); | ||
self.children_access.write( | ||
DirectDbWriter::new(&self.db), | ||
parent, | ||
BlockHashes::new(children), | ||
)?; | ||
parent_to_children.insert(parent, children); | ||
} | ||
|
||
let batch = WriteBatchWithColumn { | ||
data: vec![ | ||
WriteBatchData { | ||
column: PARENTS_CF.to_string(), | ||
row_data: WriteBatch::new_with_rows(vec![( | ||
hash.to_vec(), | ||
WriteOp::Value( | ||
<Arc<Vec<Hash>> as ValueCodec<RelationParent>>::encode_value(&parents)?, | ||
), | ||
)]), | ||
}, | ||
WriteBatchData { | ||
column: CHILDREN_CF.to_string(), | ||
row_data: WriteBatch::new_with_rows( | ||
parent_to_children | ||
.iter() | ||
.map(|(key, value)| { | ||
std::result::Result::Ok(( | ||
key.to_vec(), | ||
WriteOp::Value(<Arc<Vec<Hash>> as ValueCodec< | ||
RelationChildren, | ||
>>::encode_value( | ||
&Arc::new(value.clone()) | ||
)?), | ||
)) | ||
}) | ||
.collect::<std::result::Result<Vec<_>, StoreError>>()?, | ||
), | ||
}, | ||
], | ||
}; | ||
self.db | ||
.write_batch_with_column(batch) | ||
.map_err(|e| StoreError::DBIoError(e.to_string()))?; | ||
Comment on lines
+167
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Enhance error handling for database operations The current error handling converts all database errors to a generic string. Consider preserving more error context. - .map_err(|e| StoreError::DBIoError(e.to_string()))?;
+ .map_err(|e| StoreError::DBIoError(format!("Failed to write batch: {}", e)))?; Also consider adding:
|
||
|
||
self.parents_access.flush_cache(&[(hash, parents)])?; | ||
self.children_access.flush_cache( | ||
&parent_to_children | ||
.into_iter() | ||
.map(|(key, value)| (key, BlockHashes::new(value))) | ||
.collect::<Vec<_>>(), | ||
)?; | ||
|
||
Ok(()) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Remove temporary debug print statement.
This appears to be accidentally committed debugging code. The
println!
with "jacktest" prefix is inconsistent with the codebase's logging practices and bypasses the logging framework. Additionally, this change seems unrelated to the PR's objective of implementing batch DAG relationship writing.If additional error visibility is needed, consider using the existing logging framework: