Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 is a distributed multi-stage transaction processor for | |
| 6 // appengine. | |
| 7 // | |
| 8 // What it is | |
| 9 // | |
| 10 // Tumble allows you to make multi-entity-group transaction chains, even when | |
| 11 // you need to affect more than the number of entities allowed by appengine | |
| 12 // (currently capped at 25 entity groups). These chains can be transactionally | |
| 13 // started from a single entity group, and will process 'in the background'. | |
| 14 // Tumble guarantees that once a transaction chain starts, it will eventually | |
| 15 // complete, though it makes no guarantees of how long that might take. | |
| 16 // | |
| 17 // This can be used for doing very large-scale fan-out, and also for large-scale | |
| 18 // fan-in. | |
| 19 // | |
| 20 // How it works | |
| 21 // | |
| 22 // An app using tumble declares one or more Mutation object. These objects | |
| 23 // are responsible for enacting a single link in the transaction chain, and | |
| 24 // may affect entities within a single entity group. Mutations must be | |
| 25 // idempotent (they will occasionally be run more than once). Mutations | |
| 26 // primarially implement a RollForward method which transactionally manipulates | |
| 27 // an entity, and then returns zero or more Mutations (which may be for other | |
| 28 // entities). Tumble's task queues and/or cron job (see Setup), will eventually | |
| 29 // pick up these new Mutations and process them, possibly introducing more | |
| 30 // Mutations, etc. | |
| 31 // | |
| 32 // When the app wants to begin a transaction chain, it uses | |
| 33 // tumble.EnterTransaction, allows the app to transactionally manipulate the | |
| 34 // starting entity, and also return one or more Mutation objects. If | |
| 35 // the transaction is successful, EnterTransaction will also fire off any | |
| 36 // necessary taskqueue tasks to process the new mutations in the background. | |
| 37 // | |
| 38 // When the transaction is committed, it's committed along with all the | |
| 39 // Mutations it produced. Either they're all committed successfully (and so | |
| 40 // the tumble transaction chain is started), or none of them are committed. | |
| 41 // | |
| 42 // Required Setup | |
| 43 // | |
| 44 // There are a couple prerequisites for using tumble. | |
| 45 // | |
| 46 // 1. You must register the tumble routes in your appengine app. You can do this | |
| 47 // like: | |
| 48 // | |
| 49 // import ( | |
| 50 // "github.com/julienschmidt/httprouter" | |
| 51 // "github.com/luci/luci-go/appengine/tumble" | |
| 52 // "net/http" | |
| 53 // ) | |
| 54 // | |
| 55 // var tumbleService = tumble.DefaultConfig() | |
| 56 // | |
| 57 // def init() { | |
| 58 // router := httprouter.New() | |
| 59 // tumbleService.InstallHandlers(router) | |
| 60 // http.Handle("/", router) | |
| 61 // } | |
| 62 // | |
| 63 // 2. You must add the following index to your index.yml: | |
| 64 // | |
| 65 // - kind: tumble.Mutation | |
| 66 // properties: | |
| 67 // - name: ExpandedShard | |
| 68 // - name: TargetRoot | |
| 69 // | |
| 70 // 3. You must add a new taskqueue for tumble (example parameters): | |
| 71 // | |
| 72 // - name: tumble # NOTE: name must match the name in the tumble.Config. | |
| 73 // rate: 32/s | |
| 74 // bucket_size: 32 | |
| 75 // retry_parameters: | |
| 76 // task_age_limit: 2m # aggressive task age pruning is desirable | |
| 77 // min_backoff_seconds: 2 | |
| 78 // max_backoff_seconds: 6 | |
| 79 // max_doublings: 7 # tops out at 2**(6 - 1) * 2 == 128 sec | |
| 80 // | |
| 81 // 4. All Mutation implementations must be registered at init() time using | |
| 82 // tumble.Register((*MyMutation)(nil)). | |
| 83 // | |
| 84 // 5. You must remember to add tumbleService to all of your handlers' | |
| 85 // contexts with tumble.Use(ctx, tumbleService). This last step is not | |
| 86 // necessary if you use all of the default configuration for tumble. | |
| 87 // | |
| 88 // Optional Setup | |
|
Vadim Sh.
2015/10/12 20:05:14
strictly speaking, one also needs app.yaml routes
iannucci
2015/10/13 02:39:46
right, I'll mention that (though the middleware he
| |
| 89 // | |
| 90 // You may choose to add a new cron entry. This prevents work from slipping | |
| 91 // through the cracks. If your app has constant tumble throughput and good key | |
| 92 // distribution, this is not necessary. | |
| 93 // | |
| 94 // - description: tumble fire_all_tasks invocation | |
| 95 // url: /internal/tumble/fire_all_tasks # NOTE: must match tumble.Config.Fi reAllTasksURL() | |
| 96 // schedule: every 5 minutes # maximium task latency you can tol erate. | |
| 97 package tumble | |
| OLD | NEW |