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 "bytes" | 8 "bytes" |
9 "errors" | 9 "errors" |
10 "fmt" | 10 "fmt" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 return pl[0].Value().(int64) | 74 return pl[0].Value().(int64) |
75 } | 75 } |
76 panic(fmt.Errorf("__version__ property missing or wrong: %v", pm
)) | 76 panic(fmt.Errorf("__version__ property missing or wrong: %v", pm
)) |
77 } | 77 } |
78 return 0 | 78 return 0 |
79 } | 79 } |
80 | 80 |
81 func incrementLocked(ents *memCollection, key []byte) int64 { | 81 func incrementLocked(ents *memCollection, key []byte) int64 { |
82 ret := curVersion(ents, key) + 1 | 82 ret := curVersion(ents, key) + 1 |
83 buf := &bytes.Buffer{} | 83 buf := &bytes.Buffer{} |
84 » rds.WritePropertyMap( | 84 » rds.PropertyMap{"__version__": {rds.MkPropertyNI(ret)}}.Write( |
85 » » buf, rds.PropertyMap{"__version__": {rds.MkPropertyNI(ret)}}, rd
s.WithContext) | 85 » » buf, rds.WithContext) |
86 ents.Set(key, buf.Bytes()) | 86 ents.Set(key, buf.Bytes()) |
87 return ret | 87 return ret |
88 } | 88 } |
89 | 89 |
90 func (d *dataStoreData) entsKeyLocked(key rds.Key) (*memCollection, rds.Key) { | 90 func (d *dataStoreData) entsKeyLocked(key rds.Key) (*memCollection, rds.Key) { |
91 coll := "ents:" + key.Namespace() | 91 coll := "ents:" + key.Namespace() |
92 ents := d.store.GetCollection(coll) | 92 ents := d.store.GetCollection(coll) |
93 if ents == nil { | 93 if ents == nil { |
94 ents = d.store.SetCollection(coll, nil) | 94 ents = d.store.SetCollection(coll, nil) |
95 } | 95 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 pmaps[i] = pm | 137 pmaps[i] = pm |
138 } | 138 } |
139 return pmaps, lme.Get() | 139 return pmaps, lme.Get() |
140 } | 140 } |
141 | 141 |
142 func (d *dataStoreData) putMultiInner(keys []rds.Key, data []rds.PropertyMap) ([
]rds.Key, error) { | 142 func (d *dataStoreData) putMultiInner(keys []rds.Key, data []rds.PropertyMap) ([
]rds.Key, error) { |
143 retKeys := make([]rds.Key, len(keys)) | 143 retKeys := make([]rds.Key, len(keys)) |
144 lme := gae.LazyMultiError{Size: len(keys)} | 144 lme := gae.LazyMultiError{Size: len(keys)} |
145 for i, k := range keys { | 145 for i, k := range keys { |
146 buf := &bytes.Buffer{} | 146 buf := &bytes.Buffer{} |
147 » » rds.WritePropertyMap(buf, data[i], rds.WithoutContext) | 147 » » data[i].Write(buf, rds.WithoutContext) |
148 dataBytes := buf.Bytes() | 148 dataBytes := buf.Bytes() |
149 | 149 |
150 rKey, err := func() (ret rds.Key, err error) { | 150 rKey, err := func() (ret rds.Key, err error) { |
151 d.rwlock.Lock() | 151 d.rwlock.Lock() |
152 defer d.rwlock.Unlock() | 152 defer d.rwlock.Unlock() |
153 | 153 |
154 ents, ret := d.entsKeyLocked(k) | 154 ents, ret := d.entsKeyLocked(k) |
155 incrementLocked(ents, groupMetaKey(ret)) | 155 incrementLocked(ents, groupMetaKey(ret)) |
156 | 156 |
157 old := ents.Get(keyBytes(rds.WithoutContext, ret)) | 157 old := ents.Get(keyBytes(rds.WithoutContext, ret)) |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 return lme.Get() | 472 return lme.Get() |
473 } | 473 } |
474 | 474 |
475 func keyBytes(ctx rds.KeyContext, key rds.Key) []byte { | 475 func keyBytes(ctx rds.KeyContext, key rds.Key) []byte { |
476 buf := &bytes.Buffer{} | 476 buf := &bytes.Buffer{} |
477 rds.WriteKey(buf, ctx, key) | 477 rds.WriteKey(buf, ctx, key) |
478 return buf.Bytes() | 478 return buf.Bytes() |
479 } | 479 } |
480 | 480 |
481 func rpmWoCtx(data []byte, ns string) (rds.PropertyMap, error) { | 481 func rpmWoCtx(data []byte, ns string) (rds.PropertyMap, error) { |
482 » return rds.ReadPropertyMap(bytes.NewBuffer(data), rds.WithoutContext, gl
obalAppID, ns) | 482 » ret := rds.PropertyMap{} |
| 483 » err := ret.Read(bytes.NewBuffer(data), rds.WithoutContext, globalAppID,
ns) |
| 484 » return ret, err |
483 } | 485 } |
484 | 486 |
485 func rpm(data []byte) (rds.PropertyMap, error) { | 487 func rpm(data []byte) (rds.PropertyMap, error) { |
486 » return rds.ReadPropertyMap(bytes.NewBuffer(data), rds.WithContext, "", "
") | 488 » ret := rds.PropertyMap{} |
| 489 » err := ret.Read(bytes.NewBuffer(data), rds.WithContext, "", "") |
| 490 » return ret, err |
487 } | 491 } |
488 | 492 |
489 func multiValid(keys []rds.Key, plss []rds.PropertyLoadSaver, ns string, potenti
alKey, allowSpecial bool) error { | 493 func multiValid(keys []rds.Key, plss []rds.PropertyLoadSaver, ns string, potenti
alKey, allowSpecial bool) error { |
490 vfn := func(k rds.Key) bool { | 494 vfn := func(k rds.Key) bool { |
491 return !rds.KeyIncomplete(k) && rds.KeyValid(k, ns, allowSpecial
) | 495 return !rds.KeyIncomplete(k) && rds.KeyValid(k, ns, allowSpecial
) |
492 } | 496 } |
493 if potentialKey { | 497 if potentialKey { |
494 vfn = func(k rds.Key) bool { | 498 vfn = func(k rds.Key) bool { |
495 // adds an id to k if it's incomplete. | 499 // adds an id to k if it's incomplete. |
496 if rds.KeyIncomplete(k) { | 500 if rds.KeyIncomplete(k) { |
(...skipping 10 matching lines...) Expand all Loading... |
507 return errors.New("gae: key and dst slices have different length
") | 511 return errors.New("gae: key and dst slices have different length
") |
508 } | 512 } |
509 lme := gae.LazyMultiError{Size: len(keys)} | 513 lme := gae.LazyMultiError{Size: len(keys)} |
510 for i, k := range keys { | 514 for i, k := range keys { |
511 if !vfn(k) { | 515 if !vfn(k) { |
512 lme.Assign(i, rds.ErrInvalidKey) | 516 lme.Assign(i, rds.ErrInvalidKey) |
513 } | 517 } |
514 } | 518 } |
515 return lme.Get() | 519 return lme.Get() |
516 } | 520 } |
OLD | NEW |