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

Support atomic writes in the docstore #3500

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion docstore/awsdynamodb/dynamo.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (c *collection) RunActions(ctx context.Context, actions []*driver.Action, o
go func() { defer close(ch2); c.transactWrite(ctx, writesTx, errs, opts) }()
c.runGets(ctx, gets, errs, opts)
<-ch
jba marked this conversation as resolved.
Show resolved Hide resolved
<-ch2
c.runGets(ctx, afterGets, errs, opts)
return driver.NewActionListError(errs)
}
Expand Down Expand Up @@ -615,10 +616,12 @@ func revisionPrecondition(doc driver.Document, revField string) (*expression.Con
return &cb, nil
}

// transactWrite execute the write actions in an atomic manner, either they all succeed or they all fail together.
jba marked this conversation as resolved.
Show resolved Hide resolved
func (c *collection) transactWrite(ctx context.Context, actions []*driver.Action, errs []error, opts *driver.RunActionsOptions) {
jba marked this conversation as resolved.
Show resolved Hide resolved
if len(actions) == 0 {
return
}
// all actions will fail atomically even if a single action fails
setErr := func(err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The idea here is that if anything in this function fails, everything fails (since it's atomic). Document that here.

for _, a := range actions {
errs[a.Index] = err
Expand All @@ -630,7 +633,8 @@ func (c *collection) transactWrite(ctx context.Context, actions []*driver.Action
for _, w := range actions {
op, err := c.newWriteOp(w, opts)
if err != nil {
errs[w.Index] = err
setErr(err)
return
} else {
ops = append(ops, op)
tws = append(tws, op.writeItem)
Expand Down
Loading