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

Side by Side Diff: go/src/infra/gae/libs/wrapper/memory/datastore_data.go

Issue 1154213012: Add context-aware "time" library wrapper. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Added coverage files. Created 5 years, 6 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
OLDNEW
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 "infra/gae/libs/wrapper" 9 "infra/gae/libs/wrapper"
10 goon_internal "infra/gae/libs/wrapper/memory/internal/goon" 10 goon_internal "infra/gae/libs/wrapper/memory/internal/goon"
11 "math/rand"
12 "sync" 11 "sync"
13 "sync/atomic" 12 "sync/atomic"
14 13
15 "github.com/mjibson/goon" 14 "github.com/mjibson/goon"
16 15
17 "appengine/datastore" 16 "appengine/datastore"
18 pb "appengine_internal/datastore" 17 pb "appengine_internal/datastore"
18 "golang.org/x/net/context"
19 ) 19 )
20 20
21 ////////////////////////////////// knrKeeper /////////////////////////////////// 21 ////////////////////////////////// knrKeeper ///////////////////////////////////
22 22
23 type knrKeeper struct { 23 type knrKeeper struct {
24 knrLock sync.Mutex 24 knrLock sync.Mutex
25 knrFunc goon.KindNameResolver 25 knrFunc goon.KindNameResolver
26 } 26 }
27 27
28 var _ = wrapper.DSKindSetter((*knrKeeper)(nil)) 28 var _ = wrapper.DSKindSetter((*knrKeeper)(nil))
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 if err != nil { 300 if err != nil {
301 panic(err) 301 panic(err)
302 } 302 }
303 if vHead != vSnap { 303 if vHead != vSnap {
304 return false 304 return false
305 } 305 }
306 } 306 }
307 return true 307 return true
308 } 308 }
309 309
310 func (d *dataStoreData) applyTxn(r *rand.Rand, obj memContextObj) { 310 func (d *dataStoreData) applyTxn(c context.Context, obj memContextObj) {
311 txn := obj.(*txnDataStoreData) 311 txn := obj.(*txnDataStoreData)
312 for _, muts := range txn.muts { 312 for _, muts := range txn.muts {
313 if len(muts) == 0 { // read-only 313 if len(muts) == 0 { // read-only
314 continue 314 continue
315 } 315 }
316 for _, m := range muts { 316 for _, m := range muts {
317 err := error(nil) 317 err := error(nil)
318 if m.data == nil { 318 if m.data == nil {
319 err = d.del(m.key.Namespace(), m.key) 319 err = d.del(m.key.Namespace(), m.key)
320 } else { 320 } else {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 377
378 const xgEGLimit = 25 378 const xgEGLimit = 25
379 379
380 func (*txnDataStoreData) canApplyTxn(memContextObj) bool { return false } 380 func (*txnDataStoreData) canApplyTxn(memContextObj) bool { return false }
381 func (td *txnDataStoreData) endTxn() { 381 func (td *txnDataStoreData) endTxn() {
382 if atomic.LoadInt32(&td.closed) == 1 { 382 if atomic.LoadInt32(&td.closed) == 1 {
383 panic("cannot end transaction twice") 383 panic("cannot end transaction twice")
384 } 384 }
385 atomic.StoreInt32(&td.closed, 1) 385 atomic.StoreInt32(&td.closed, 1)
386 } 386 }
387 func (*txnDataStoreData) applyTxn(*rand.Rand, memContextObj) { 387 func (*txnDataStoreData) applyTxn(context.Context, memContextObj) {
388 panic("txnDataStoreData cannot apply transactions") 388 panic("txnDataStoreData cannot apply transactions")
389 } 389 }
390 func (*txnDataStoreData) mkTxn(*datastore.TransactionOptions) (memContextObj, er ror) { 390 func (*txnDataStoreData) mkTxn(*datastore.TransactionOptions) (memContextObj, er ror) {
391 return nil, errors.New("datastore: nested transactions are not supported ") 391 return nil, errors.New("datastore: nested transactions are not supported ")
392 } 392 }
393 393
394 func (td *txnDataStoreData) IsBroken() error { 394 func (td *txnDataStoreData) IsBroken() error {
395 // Slightly different from the SDK... datastore and taskqueue each imple ment 395 // Slightly different from the SDK... datastore and taskqueue each imple ment
396 // this here, where in the SDK only datastore.transaction.Call does. 396 // this here, where in the SDK only datastore.transaction.Call does.
397 if atomic.LoadInt32(&td.closed) == 1 { 397 if atomic.LoadInt32(&td.closed) == 1 {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 return td.snap.GetCollection("ents:" + ns), nil 468 return td.snap.GetCollection("ents:" + ns), nil
469 }) 469 })
470 } 470 }
471 471
472 func (td *txnDataStoreData) del(ns string, key *datastore.Key) error { 472 func (td *txnDataStoreData) del(ns string, key *datastore.Key) error {
473 if !keyValid(ns, key, userKeyOnly) { 473 if !keyValid(ns, key, userKeyOnly) {
474 return datastore.ErrInvalidKey 474 return datastore.ErrInvalidKey
475 } 475 }
476 return td.writeMutation(false, key, nil) 476 return td.writeMutation(false, key, nil)
477 } 477 }
OLDNEW
« no previous file with comments | « go/src/infra/gae/libs/wrapper/memory/context.go ('k') | go/src/infra/gae/libs/wrapper/memory/memcache.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698