Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: appengine/tumble/tumble.go

Issue 1395293002: Add "tumble" distributed transaction processing service for appengine. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: use exists Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/tumble/process.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package tumble
6
7 import (
8 "fmt"
9
10 "github.com/luci/gae/filter/txnBuf"
11 "github.com/luci/gae/service/datastore"
12 "golang.org/x/net/context"
13 )
14
15 // EnterTransaction is the method to use when doing transactional operations
16 // in the tumble ecosystem. It allows work to be done in the entity group
17 // specified by `fromRoot`, and any returned Mutation objects will be
18 // transactionally queued for the tumble backend.
19 //
20 // Usually this is called from your application's handlers to begin a tumble
21 // state machine as a result of some API interaction.
22 func EnterTransaction(c context.Context, fromRoot *datastore.Key, f func(context .Context) ([]Mutation, error)) error {
23 shardSet, _, err := enterTransactionInternal(txnBuf.FilterRDS(c), fromRo ot, f)
24 if err != nil {
25 return err
26 }
27 fireTasks(c, shardSet)
28 return nil
29 }
30
31 func enterTransactionInternal(c context.Context, fromRoot *datastore.Key, f func (context.Context) ([]Mutation, error)) (map[uint64]struct{}, uint, error) {
32 if fromRoot == nil {
33 return nil, 0, fmt.Errorf("tumble: Passing nil as fromRoot is il legal")
34 }
35
36 shardSet := map[uint64]struct{}(nil)
37 numNewMuts := uint(0)
38
39 err := datastore.Get(c).RunInTransaction(func(c context.Context) error {
40 // do a Get on the fromRoot to ensure that this transaction is a ssociated
41 // with that entity group.
42 _, _ = datastore.Get(c).Exists(fromRoot)
43
44 muts, err := f(c)
45 if err != nil {
46 return err
47 }
48
49 numNewMuts = uint(len(muts))
50 shardSet, err = putMutations(c, fromRoot, muts)
51
52 return err
53 }, nil)
54 if err != nil {
55 return nil, 0, err
56 }
57
58 return shardSet, numNewMuts, nil
59 }
OLDNEW
« no previous file with comments | « appengine/tumble/process.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698