Skip to content
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

Merged
merged 13 commits into from
Jun 12, 2024
Merged

Conversation

spoonincode
Copy link
Member

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 to cfile 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")

@ericpassmore
Copy link
Contributor

Note:start
group: STABILITY
category: INTERNALS
summary: Refactor ship log to no longer hold a mutex that can potentially block the main thread for extended (or even indefinite) time.
Note:end

Copy link
Member

@linh2931 linh2931 left a 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.

t.check_not_present(7);
t.check_range_present(4, 6);
});

Copy link
Member Author

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.

Copy link
Member Author

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)

@linh2931
Copy link
Member

linh2931 commented Jun 6, 2024

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.

After I reviewed

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 has a large number of new unit tests. We can just go through old SHiP issues and add more integration tests to reflect production usages.

Base automatically changed from ship_thread_refactor to main June 12, 2024 00:03
@spoonincode spoonincode merged commit b31aa58 into main Jun 12, 2024
36 of 37 checks passed
@spoonincode spoonincode deleted the ship_log_refactor branch June 12, 2024 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants