OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package memory | 5 package memory |
6 | 6 |
7 import ( | 7 import ( |
8 "errors" | 8 "errors" |
9 "fmt" | 9 "fmt" |
10 "net/http" | 10 "net/http" |
11 "sync" | 11 "sync" |
12 "sync/atomic" | 12 "sync/atomic" |
13 | 13 |
14 "golang.org/x/net/context" | 14 "golang.org/x/net/context" |
15 | 15 |
16 » rds "github.com/luci/gae/service/rawdatastore" | 16 » ds "github.com/luci/gae/service/datastore" |
17 tq "github.com/luci/gae/service/taskqueue" | 17 tq "github.com/luci/gae/service/taskqueue" |
18 "github.com/luci/luci-go/common/clock" | 18 "github.com/luci/luci-go/common/clock" |
19 ) | 19 ) |
20 | 20 |
21 var ( | 21 var ( |
22 currentNamespace = http.CanonicalHeaderKey("X-AppEngine-Current-Namespac
e") | 22 currentNamespace = http.CanonicalHeaderKey("X-AppEngine-Current-Namespac
e") |
23 defaultNamespace = http.CanonicalHeaderKey("X-AppEngine-Default-Namespac
e") | 23 defaultNamespace = http.CanonicalHeaderKey("X-AppEngine-Default-Namespac
e") |
24 ) | 24 ) |
25 | 25 |
26 //////////////////////////////// taskQueueData ///////////////////////////////// | 26 //////////////////////////////// taskQueueData ///////////////////////////////// |
(...skipping 22 matching lines...) Expand all Loading... |
49 func (t *taskQueueData) applyTxn(c context.Context, obj memContextObj) { | 49 func (t *taskQueueData) applyTxn(c context.Context, obj memContextObj) { |
50 txn := obj.(*txnTaskQueueData) | 50 txn := obj.(*txnTaskQueueData) |
51 for qn, tasks := range txn.anony { | 51 for qn, tasks := range txn.anony { |
52 for _, tsk := range tasks { | 52 for _, tsk := range tasks { |
53 tsk.Name = mkName(c, tsk.Name, t.named[qn]) | 53 tsk.Name = mkName(c, tsk.Name, t.named[qn]) |
54 t.named[qn][tsk.Name] = tsk | 54 t.named[qn][tsk.Name] = tsk |
55 } | 55 } |
56 } | 56 } |
57 txn.anony = nil | 57 txn.anony = nil |
58 } | 58 } |
59 func (t *taskQueueData) mkTxn(*rds.TransactionOptions) memContextObj { | 59 func (t *taskQueueData) mkTxn(*ds.TransactionOptions) memContextObj { |
60 return &txnTaskQueueData{ | 60 return &txnTaskQueueData{ |
61 parent: t, | 61 parent: t, |
62 anony: tq.AnonymousQueueData{}, | 62 anony: tq.AnonymousQueueData{}, |
63 } | 63 } |
64 } | 64 } |
65 | 65 |
66 func (t *taskQueueData) GetTransactionTasks() tq.AnonymousQueueData { | 66 func (t *taskQueueData) GetTransactionTasks() tq.AnonymousQueueData { |
67 return nil | 67 return nil |
68 } | 68 } |
69 | 69 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 closed int32 | 183 closed int32 |
184 anony tq.AnonymousQueueData | 184 anony tq.AnonymousQueueData |
185 parent *taskQueueData | 185 parent *taskQueueData |
186 } | 186 } |
187 | 187 |
188 var ( | 188 var ( |
189 _ = memContextObj((*txnTaskQueueData)(nil)) | 189 _ = memContextObj((*txnTaskQueueData)(nil)) |
190 _ = tq.Testable((*txnTaskQueueData)(nil)) | 190 _ = tq.Testable((*txnTaskQueueData)(nil)) |
191 ) | 191 ) |
192 | 192 |
193 func (t *txnTaskQueueData) canApplyTxn(obj memContextObj) bool { return
false } | 193 func (t *txnTaskQueueData) canApplyTxn(obj memContextObj) bool { return
false } |
194 func (t *txnTaskQueueData) applyTxn(context.Context, memContextObj) { panic(
"impossible") } | 194 func (t *txnTaskQueueData) applyTxn(context.Context, memContextObj) { panic("
impossible") } |
195 func (t *txnTaskQueueData) mkTxn(*rds.TransactionOptions) memContextObj { panic(
"impossible") } | 195 func (t *txnTaskQueueData) mkTxn(*ds.TransactionOptions) memContextObj { panic("
impossible") } |
196 | 196 |
197 func (t *txnTaskQueueData) endTxn() { | 197 func (t *txnTaskQueueData) endTxn() { |
198 if atomic.LoadInt32(&t.closed) == 1 { | 198 if atomic.LoadInt32(&t.closed) == 1 { |
199 panic("cannot end transaction twice") | 199 panic("cannot end transaction twice") |
200 } | 200 } |
201 atomic.StoreInt32(&t.closed, 1) | 201 atomic.StoreInt32(&t.closed, 1) |
202 } | 202 } |
203 | 203 |
204 func (t *txnTaskQueueData) run(f func() error) error { | 204 func (t *txnTaskQueueData) run(f func() error) error { |
205 // Slightly different from the SDK... datastore and taskqueue each imple
ment | 205 // Slightly different from the SDK... datastore and taskqueue each imple
ment |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 return t.parent.GetTombstonedTasks() | 250 return t.parent.GetTombstonedTasks() |
251 } | 251 } |
252 | 252 |
253 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData { | 253 func (t *txnTaskQueueData) GetScheduledTasks() tq.QueueData { |
254 return t.parent.GetScheduledTasks() | 254 return t.parent.GetScheduledTasks() |
255 } | 255 } |
256 | 256 |
257 func (t *txnTaskQueueData) CreateQueue(queueName string) { | 257 func (t *txnTaskQueueData) CreateQueue(queueName string) { |
258 t.parent.CreateQueue(queueName) | 258 t.parent.CreateQueue(queueName) |
259 } | 259 } |
OLD | NEW |