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

chop: offline event log truncation #165

Merged
merged 29 commits into from
Feb 9, 2023
Merged

Conversation

matthew-levan
Copy link
Contributor

@matthew-levan matthew-levan commented Jan 25, 2023

chop

urbit chop <pier> implements a simple, offline event log truncation1 tool.

chop gracefully stops the given pier (if running), backs up the current snapshot to <pier>/.urb/bhk, makes sure a current snapshot exists (i.e., is fully written to disk in chk/*.bin with no existing patch files), reads the metadata and the last event from the pier's event log, initializes a fresh event log in the <pier>/.urb/log/chop directory, writes the metadata and last event from the original log into the fresh one, renames the original event log to <pier>/.urb/log/chop/data_<first>_<last>.mdb.bak where first and last are the first and last event numbers from the event log, and exits.

Pilots are then free to move, archive, or delete their .bak event log file, resume normal operation of their ship, and enjoy the many benefits of lowered disk pressure and any reductions in associated hosting costs.

I've tested chop successfully on my own planet ~mastyr-bottec (multiple times), three different comets (all fresh), and multitudes of fake galaxies.

Resolves #122.

Note: knit, which is the "undo" button for chop, is being implemented in its own PR #184.

Footnotes

  1. https://roadmap.urbit.org/project/event-log-truncation

pkg/vere/db/lmdb.c Outdated Show resolved Hide resolved
pkg/vere/db/lmdb.c Outdated Show resolved Hide resolved
@matthew-levan
Copy link
Contributor Author

matthew-levan commented Jan 27, 2023

This code has now been tested successfully on fake ships, two comets, and my own planet ~mastyr-bottec. Thanks to @mopfel-winrux for helping me clean the code up a little, but it still needs more polish.

Additionally, since chopping one's pier leaves a backup event log file behind (and pilots may indeed chop their piers multiple times throughout its life), we also had the idea to include an urbit knit subcommand in this PR that would accept a list of event log backup files and insert their events back into a single .mdb file of the user's choice (whether that's a new one or the existing data.mdb). This command would allow previously chopped event logs to be restored and replayed, if desired/necessary.

pkg/vere/main.c Outdated Show resolved Hide resolved
Copy link
Contributor

@belisarius222 belisarius222 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

@matthew-levan matthew-levan marked this pull request as ready for review January 31, 2023 17:01
@matthew-levan matthew-levan requested a review from a team as a code owner January 31, 2023 17:01
@matthew-levan matthew-levan changed the base branch from develop to master January 31, 2023 17:05
@matthew-levan matthew-levan changed the base branch from master to develop January 31, 2023 17:05
Copy link

@mcevoypeter mcevoypeter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for churning this out so quickly. The overall work looks great, but I have a number of comments and questions on small details.

pkg/vere/db/lmdb.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
@belisarius222 belisarius222 changed the title chop chop: offline event log truncation Feb 1, 2023
pkg/noun/events.c Outdated Show resolved Hide resolved
@matthew-levan matthew-levan requested review from joemfb and mcevoypeter and removed request for joemfb and mcevoypeter February 3, 2023 07:33
@jalehman jalehman requested a review from joemfb February 6, 2023 12:42
Copy link
Member

@joemfb joemfb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code is clear and makes sense. I've noted a few spots where we'll need more/better error handling:

pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
joemfb
joemfb previously requested changes Feb 8, 2023
pkg/noun/events.c Show resolved Hide resolved
pkg/noun/events.c Outdated Show resolved Hide resolved
pkg/noun/events.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
pkg/vere/main.c Outdated Show resolved Hide resolved
@matthew-levan
Copy link
Contributor Author

matthew-levan commented Feb 8, 2023

Here's an example output @joemfb:

matt@mbp14 vere % ./urbit chop zod         
loom: mapped 2048MB
boot: protected loom
live: loaded: MB/139.001.856
boot: installed 652 jets
loom: image backup complete
chop: event log truncation complete
      event log backup written to zod/.urb/log/chop/data_152-152.mdb.bak
      WARNING: ENSURE YOU CAN RESTART YOUR SHIP BEFORE DELETING YOUR EVENT LOG BACKUP FILE!
      if you can't, restore your log by running:
      `mv zod/.urb/log/chop/data_152-152.mdb.bak zod/.urb/log/data.mdb` then try again

@belisarius222 belisarius222 dismissed stale reviews from joemfb and mcevoypeter February 9, 2023 15:00

all comments addressed

@jalehman jalehman merged commit 7098eb8 into urbit:develop Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement chop (event log truncation tool)
5 participants