-
Notifications
You must be signed in to change notification settings - Fork 25
refactor: separate backend operations #409
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
base: main
Are you sure you want to change the base?
Conversation
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.
Love the direction, feel like there is a bit more error handling needed at certain places. Need to take another, deeper look at RepoPacker
, few TODOs and docs still open.
pub fn needs_save(&self) -> bool { | ||
// check if IndexFile needs to be saved | ||
let elapsed = self.created.elapsed().unwrap_or_else(|err| { | ||
warn!("couldn't get elapsed time from system time: {err:?}"); |
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.
This should be part of the error handling here and not a warning in the logs.
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.
This is the error handling. When we can't get an elapsed time when we check if an index file should be saved, we have two options:
- return an error which would mean we don't finish the backup
- omit the check on the elapsed time, i.e. only write when the index file is "full" and warn the user. This will successfully finish the backup.
I strongly prefer option 2) which is the current error handling.
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.
This wasn't what I meant, what I meant was if we have a warning in the log, user of rustic_core are not able to handle this, instead of a log warning this should return a rustic_error with the message so a user can handle this if we get to it from somewhere.
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.
We could discuss is we don't log the warning but just silently handle this case.
Anyway, this discussion doesn't belong to this PR, IMO, as the behavior is not changed w.r.t. main, see https://github.com/rustic-rs/rustic_core/blob/main/crates/core/src/blob/packer.rs#L610.
finish: finish_rx, | ||
}; | ||
|
||
let _join_handle = std::thread::spawn(move || { |
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.
Don't we want to use the join handles somewhere and join the threads, e.g. in case we get Ctrl + C or something?
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.
This is a good question. Actually the _join_handle_raw
is joined by waiting for the status which is sent via a channel. And the join_handle
is joined by the fact that it sends to the second thread, i.e. the _join_handle_raw
will not finish unless _join_handle
finishes. I'm not aware if there is a problem about something like Ctrl+C - can you depict what would be happening in this case?
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.
I believe the threads can terminate quite "normally" even in case of an interruption in the main thread because they "simply" iterate on the rx
:
- main threads closes
- tx is closed/dropped
- _join_handle thread will then terminate
- tx_raw is closed/dropped
- _join_handle_raw thread will then terminate
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.
I think these are nice API changes, it's good to see the BE
backend generic type be less propagated if that makes sense.
pub fn save(&self) -> RusticResult<()> { | ||
if (self.file.packs.len() + self.file.packs_to_delete.len()) > 0 { | ||
_ = self.be.save_file(&self.file)?; | ||
pub fn save(&mut self) -> Option<IndexFile> { |
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.
This method has totally changed, some other methods totally changed as well, would you mind quickly updating their documentations pls :)?
Also, do you think it deserves a rename? (same questions for other methods that changed signature)
/// * `id` - The id to check. | ||
pub fn has(&self, id: &BlobId) -> bool { | ||
pub fn has(&mut self, id: &BlobId) -> bool { | ||
self.indexed | ||
.as_ref() | ||
.as_mut() | ||
.is_some_and(|indexed| indexed.contains(id)) | ||
} |
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.
I am not sure we need mut
there, is there any reason you left it as such?
finish: finish_rx, | ||
}; | ||
|
||
let _join_handle = std::thread::spawn(move || { |
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.
I believe the threads can terminate quite "normally" even in case of an interruption in the main thread because they "simply" iterate on the rx
:
- main threads closes
- tx is closed/dropped
- _join_handle thread will then terminate
- tx_raw is closed/dropped
- _join_handle_raw thread will then terminate
This PR refactors indexer and packer into a version which is completely independent from I/O and concurrency but simply provides the functionality.
This can then be separated into real "core" functionality.
As a side effect, this PR solves the following topics:
copy
command may copy duplicate data #146)self
in thefinalize
methods.