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

Add support for table initializers to gate keep pruning #3

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented Mar 28, 2024

It's often important to avoid pruning data before the table has been fully populated by writers. Add support for this in the form of table initializers that can be registered before the application starts. Make the reconciler pruning conditional on the table being fully initialized.

The initializers are stored in the table entry, which means that the initializer count is coupled to the snapshot and thus a reader won't think the table is initialized before it gets a snapshot that indeed is initialized.

Example:

  // Adding an initializer (called before start)
  txn := db.WriteTxn(myTable)
  done := myTable.RegisterInitializer(txn)
  txn.Commit()

  rtxn1 := db.ReadTxn()
  myTable.Initialized(rtxn1) == false

  txn = db.WriteTxn(myTable)
  done(txn)
  txn.Commit()

  rtxn2 := db.ReadTxn()
  myTable.Initialized(rtxn1) == false
  myTable.Initialized(rtxn2) == true

It's often important to avoid pruning data before the table has
been fully populated by writers. Add support for this in the form
of table initializers that can be registered before the application
starts. Make the reconciler pruning conditional on the table being
fully initialized.

The initializers are stored in the table entry, which means that
the initializer count is coupled to the snapshot and thus a reader
won't think the table is initialized before it gets a snapshot that
indeed is initialized.

Example:

  // Adding an initializer (called before start)
  txn := db.WriteTxn(myTable)
  done := myTable.RegisterInitializer(txn)
  txn.Commit()

  rtxn1 := db.ReadTxn()
  myTable.Initialized(rtxn1) == false

  txn = db.WriteTxn(myTable)
  done(txn)
  txn.Commit()

  rtxn2 := db.ReadTxn()
  myTable.Initialized(rtxn1) == false
  myTable.Initialized(rtxn2) == true

Signed-off-by: Jussi Maki <[email protected]>
@joamaki joamaki requested review from pippolo84 and bimmlerd March 28, 2024 14:49
Copy link
Member

@pippolo84 pippolo84 left a comment

Choose a reason for hiding this comment

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

LGTM! 🚀

// RegisterInitializer adds an initializers to the table. Returns
// a function to mark the initializer done. Once all initializers are
// done, Table[*].Initialized() will return true.
// This should only be used before the application has started.

This comment was marked as resolved.

@joamaki joamaki merged commit 7319e92 into main Apr 2, 2024
1 check passed
@joamaki joamaki deleted the pr/joamaki/initializers branch April 2, 2024 07:11
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.

2 participants