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 // Don't forget to add these to app.yaml (and/or dispatch.yaml). Additionally, |
| 64 // make sure to add them with `login: admin`, as they should never be accessed |
| 65 // from non-backend processes. |
| 66 // |
| 67 // 2. You must add the following index to your index.yaml: |
| 68 // |
| 69 // - kind: tumble.Mutation |
| 70 // properties: |
| 71 // - name: ExpandedShard |
| 72 // - name: TargetRoot |
| 73 // |
| 74 // 3. You must add a new taskqueue for tumble (example parameters): |
| 75 // |
| 76 // - name: tumble # NOTE: name must match the name in the tumble.Config. |
| 77 // rate: 32/s |
| 78 // bucket_size: 32 |
| 79 // retry_parameters: |
| 80 // task_age_limit: 2m # aggressive task age pruning is desirable |
| 81 // min_backoff_seconds: 2 |
| 82 // max_backoff_seconds: 6 |
| 83 // max_doublings: 7 # tops out at 2**(6 - 1) * 2 == 128 sec |
| 84 // |
| 85 // 4. All Mutation implementations must be registered at init() time using |
| 86 // tumble.Register((*MyMutation)(nil)). |
| 87 // |
| 88 // 5. You must remember to add tumbleService to all of your handlers' |
| 89 // contexts with tumble.Use(ctx, tumbleService). This last step is not |
| 90 // necessary if you use all of the default configuration for tumble. |
| 91 // |
| 92 // Optional Setup |
| 93 // |
| 94 // You may choose to add a new cron entry. This prevents work from slipping |
| 95 // through the cracks. If your app has constant tumble throughput and good key |
| 96 // distribution, this is not necessary. |
| 97 // |
| 98 // - description: tumble fire_all_tasks invocation |
| 99 // url: /internal/tumble/fire_all_tasks # NOTE: must match tumble.Config.Fi
reAllTasksURL() |
| 100 // schedule: every 5 minutes # maximium task latency you can tol
erate. |
| 101 package tumble |
OLD | NEW |