dolt
dolt copied to clipboard
Capability to lock a branch
Hi, I wanted to open a request for the ability to lock a branch with functionality similar to a table level lock, or an advisory lock. This would allow the ability to protect a branch during operations like a migration when an application is rolling out and other writers might exist that try to merge into the target branch in the same window of time.
Cool feature @n0mn0m! Thanks for opening this tracking issue. Tim mentioned @Hydrocharged may be able to take a look at pick this up as part of work with grants.
HI @n0mn0m, can you clarify your expectations about what should happen when a branch is locked?
- Presumably only the holder of the lock can create new commits on the branch named, including things like
dolt reset
that would move the HEAD? - Can another user commit a transaction that modifies the working set of that branch (but not create a dolt commit and therefore move the HEAD)? I'm thinking no?
Good question, I was thinking in the realm of your first bullet point. There are times when maybe you want an almost atomic, ordered set of operations to happen without allowing any operations to impact the branch until you release the lock. That said maybe it would make sense to run these on a branch and then merge it to dev.
For our concrete use case the context is running migrations. I could run them on a branch, then merge that branch to dev, but I think that could get messy since these migrations are typically fully automated. Granted if the merge fails having that break the deployment of the migration may be a good thing.
I am just thinking about avoiding a scenario where a merge or schema migration turns into a race with a data merge from two different writers, the data merge wins over the schema migration merge and requires the migration to be updated rather than locking a branch to apply the migration, then forcing any users/applications that then want to merge data diffs to reconcile with any schema updates.
Does that help any? It would be nice to control this in the db with a type of LOCK
, but maybe it has to be outside the db. Just thinking about the fact we have automated systems and human in the loop systems using dolt, controlling the automated systems and data races is a bit easier than what may happen from a query console.
@Hydrocharged is currently looking at branch level permissions. He should take a gander at this bug.
We implemented branch permissions and I think this does what you want:
https://docs.dolthub.com/sql-reference/server/branch-permissions
Let us know if that doesn't meet your needs.