-
Notifications
You must be signed in to change notification settings - Fork 5
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
refactor state_history's logs to be mutex free #237
Conversation
libraries/state_history/include/eosio/state_history/log_catalog.hpp
Outdated
Show resolved
Hide resolved
Note:start |
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.
Since this is a rewrite of SHiP, we can go over old SHiP issues to make sure they are not regressed if still applicable, and add more unit and integration tests.
tests/ship_log.cpp
Outdated
t.check_not_present(7); | ||
t.check_range_present(4, 6); | ||
}); | ||
|
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 test applies a fork that decreases the resulting head block number, and then closes the log and reopens it. It was modified/removed because the new log implementation does not like this (to be specific, it fails on reopening the log file because the index contains more blocks than the log contains). Since this is now valid in savanna the log will need to be improved.
For the simple single-log case this is quite a trivial fix: truncate the index as appropriate -- nothing in the ship connection thread could be using the index. For the partitioned log case things get a wee bit more tricky.
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.
There has been a fairly substantial modification of the logic in b98fe82 to ensure that the log is left in a sane state when a fork with a block number less than the previous head block is applied (this isn't strictly a problem when "closes the log and reopens it" as previously discussed). The change will require careful review.
For the single-log case it is as trivial as expected: truncate the index and then tweak some state of the log a little (arguably simpler now).
For partitioned logs, the approach is to "unrotate" the logs as needed: if the applied block occurs before the first block in the head log, the head log is removed and the newest retained log is restored as the head log. A new unit test has been enhanced to probe in this area more. I've also restored more of this section of the ship_log test that was removed previously.
#221 comes along for the ride in the improvement because now random_access_file
and state_history_log
are moveable (1876cc8 and 1eccd39)
libraries/state_history/include/eosio/state_history/log_catalog.hpp
Outdated
Show resolved
Hide resolved
libraries/state_history/include/eosio/state_history/log_config.hpp
Outdated
Show resolved
Hide resolved
After I reviewed
|
truncate the index and "unrotate" logs as needed
macos fails tests unless this is done
Refactor ship log to no longer hold a mutex that can potentially block the main thread for extended (or even indefinite) time. Resolves #274. Coupled with AntelopeIO/leap#236 resolves AntelopeIO/leap#20.
The thread safety mostly comes from the new
random_access_file
that is similarish tocfile
but provides mutex free access to a file (at least, mutex free from the standpoint of our application -- there may serialization in the kernel). Additionally, the ship log is modified to be append only: previously the ship log would truncate away forked out blocks when applying a fork, now the forked out blocks remain in the log but are no longer "reachable" -- the index doesn't refer to them (but need to be careful when transversing the log in reverse, such as rebuilding the index; this may arguably make this a ship log "format change")