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

Side by Side Diff: impl/memory/raw_datastore_data.go

Issue 1269113005: A transparent cache for datastore, backed by memcache. (Closed) Base URL: https://github.com/luci/gae.git@add_meta
Patch Set: fix comments Created 5 years, 4 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 | « impl/memory/memcache.go ('k') | impl/prod/memcache.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "bytes" 8 "bytes"
9 "fmt" 9 "fmt"
10 "sync" 10 "sync"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 return keyBytes(ds.WithoutContext, 56 return keyBytes(ds.WithoutContext,
57 ds.NewKey("", "", "__entity_group_ids__", "", 1, ds.KeyRoot(key) )) 57 ds.NewKey("", "", "__entity_group_ids__", "", 1, ds.KeyRoot(key) ))
58 } 58 }
59 59
60 func rootIDsKey(kind string) []byte { 60 func rootIDsKey(kind string) []byte {
61 return keyBytes(ds.WithoutContext, 61 return keyBytes(ds.WithoutContext,
62 ds.NewKey("", "", "__entity_root_ids__", kind, 0, nil)) 62 ds.NewKey("", "", "__entity_root_ids__", kind, 0, nil))
63 } 63 }
64 64
65 func curVersion(ents *memCollection, key []byte) int64 { 65 func curVersion(ents *memCollection, key []byte) int64 {
66 » if v := ents.Get(key); v != nil { 66 » if ents != nil {
67 » » pm, err := rpm(v) 67 » » if v := ents.Get(key); v != nil {
68 » » if err != nil { 68 » » » pm, err := rpm(v)
69 » » » panic(err) // memory corruption 69 » » » if err != nil {
70 » » » » panic(err) // memory corruption
71 » » » }
72 » » » pl, ok := pm["__version__"]
73 » » » if ok && len(pl) > 0 && pl[0].Type() == ds.PTInt {
74 » » » » return pl[0].Value().(int64)
75 » » » }
76 » » » panic(fmt.Errorf("__version__ property missing or wrong: %v", pm))
70 } 77 }
71 pl, ok := pm["__version__"]
72 if ok && len(pl) > 0 && pl[0].Type() == ds.PTInt {
73 return pl[0].Value().(int64)
74 }
75 panic(fmt.Errorf("__version__ property missing or wrong: %v", pm ))
76 } 78 }
77 return 0 79 return 0
78 } 80 }
79 81
80 func incrementLocked(ents *memCollection, key []byte) int64 { 82 func incrementLocked(ents *memCollection, key []byte) int64 {
81 ret := curVersion(ents, key) + 1 83 ret := curVersion(ents, key) + 1
82 buf := &bytes.Buffer{} 84 buf := &bytes.Buffer{}
83 ds.PropertyMap{"__version__": {ds.MkPropertyNI(ret)}}.Write( 85 ds.PropertyMap{"__version__": {ds.MkPropertyNI(ret)}}.Write(
84 buf, ds.WithContext) 86 buf, ds.WithContext)
85 ents.Set(key, buf.Bytes()) 87 ents.Set(key, buf.Bytes())
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 412
411 func rpm(data []byte) (ds.PropertyMap, error) { 413 func rpm(data []byte) (ds.PropertyMap, error) {
412 ret := ds.PropertyMap{} 414 ret := ds.PropertyMap{}
413 err := ret.Read(bytes.NewBuffer(data), ds.WithContext, "", "") 415 err := ret.Read(bytes.NewBuffer(data), ds.WithContext, "", "")
414 return ret, err 416 return ret, err
415 } 417 }
416 418
417 type keyitem interface { 419 type keyitem interface {
418 Key() ds.Key 420 Key() ds.Key
419 } 421 }
OLDNEW
« no previous file with comments | « impl/memory/memcache.go ('k') | impl/prod/memcache.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698