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

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

Issue 2353063004: Add "MkKeyContext" KeyContext generation function. (Closed)
Patch Set: Created 4 years, 3 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 | « filter/txnBuf/txnbuf_test.go ('k') | impl/memory/datastore_index.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 LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be 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 "strings" 10 "strings"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 func (d *dataStoreData) namespaces() []string { 169 func (d *dataStoreData) namespaces() []string {
170 d.rwlock.Lock() 170 d.rwlock.Lock()
171 defer d.rwlock.Unlock() 171 defer d.rwlock.Unlock()
172 172
173 return namespaces(d.head) 173 return namespaces(d.head)
174 } 174 }
175 175
176 /////////////////////////// indexes(dataStoreData) //////////////////////////// 176 /////////////////////////// indexes(dataStoreData) ////////////////////////////
177 177
178 func groupMetaKey(key *ds.Key) []byte { 178 func groupMetaKey(key *ds.Key) []byte {
179 » return keyBytes(ds.KeyContext{}.NewKey("__entity_group__", "", 1, key.Ro ot())) 179 » return keyBytes(ds.MkKeyContext("", "").NewKey("__entity_group__", "", 1 , key.Root()))
180 } 180 }
181 181
182 func groupIDsKey(key *ds.Key) []byte { 182 func groupIDsKey(key *ds.Key) []byte {
183 » return keyBytes(ds.KeyContext{}.NewKey("__entity_group_ids__", "", 1, ke y.Root())) 183 » return keyBytes(ds.MkKeyContext("", "").NewKey("__entity_group_ids__", " ", 1, key.Root()))
184 } 184 }
185 185
186 func rootIDsKey(kind string) []byte { 186 func rootIDsKey(kind string) []byte {
187 » return keyBytes(ds.KeyContext{}.NewKey("__entity_root_ids__", kind, 0, n il)) 187 » return keyBytes(ds.MkKeyContext("", "").NewKey("__entity_root_ids__", ki nd, 0, nil))
188 } 188 }
189 189
190 func curVersion(ents memCollection, key []byte) int64 { 190 func curVersion(ents memCollection, key []byte) int64 {
191 if ents != nil { 191 if ents != nil {
192 if v := ents.Get(key); v != nil { 192 if v := ents.Get(key); v != nil {
193 pm, err := rpm(v) 193 pm, err := rpm(v)
194 memoryCorruption(err) 194 memoryCorruption(err)
195 195
196 pl := pm.Slice("__version__") 196 pl := pm.Slice("__version__")
197 if len(pl) > 0 && pl[0].Type() == ds.PTInt { 197 if len(pl) > 0 && pl[0].Type() == ds.PTInt {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 } 405 }
406 406
407 func (d *dataStoreData) canApplyTxn(obj memContextObj) bool { 407 func (d *dataStoreData) canApplyTxn(obj memContextObj) bool {
408 // TODO(riannucci): implement with Flush/FlushRevert for persistance. 408 // TODO(riannucci): implement with Flush/FlushRevert for persistance.
409 409
410 txn := obj.(*txnDataStoreData) 410 txn := obj.(*txnDataStoreData)
411 for rk, muts := range txn.muts { 411 for rk, muts := range txn.muts {
412 if len(muts) == 0 { // read-only 412 if len(muts) == 0 { // read-only
413 continue 413 continue
414 } 414 }
415 » » prop, err := serialize.ReadProperty(bytes.NewBufferString(rk), s erialize.WithContext, ds.KeyContext{}) 415 » » prop, err := serialize.ReadProperty(bytes.NewBufferString(rk), s erialize.WithContext, ds.MkKeyContext("", ""))
416 memoryCorruption(err) 416 memoryCorruption(err)
417 417
418 k := prop.Value().(*ds.Key) 418 k := prop.Value().(*ds.Key)
419 419
420 entKey := "ents:" + k.Namespace() 420 entKey := "ents:" + k.Namespace()
421 mkey := groupMetaKey(k) 421 mkey := groupMetaKey(k)
422 entsHead := d.head.GetCollection(entKey) 422 entsHead := d.head.GetCollection(entKey)
423 entsSnap := txn.snap.GetCollection(entKey) 423 entsSnap := txn.snap.GetCollection(entKey)
424 vHead := curVersion(entsHead, mkey) 424 vHead := curVersion(entsHead, mkey)
425 vSnap := curVersion(entsSnap, mkey) 425 vSnap := curVersion(entsSnap, mkey)
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 596 }
597 return nil 597 return nil
598 } 598 }
599 599
600 func keyBytes(key *ds.Key) []byte { 600 func keyBytes(key *ds.Key) []byte {
601 return serialize.ToBytes(ds.MkProperty(key)) 601 return serialize.ToBytes(ds.MkProperty(key))
602 } 602 }
603 603
604 func rpm(data []byte) (ds.PropertyMap, error) { 604 func rpm(data []byte) (ds.PropertyMap, error) {
605 return serialize.ReadPropertyMap(bytes.NewBuffer(data), 605 return serialize.ReadPropertyMap(bytes.NewBuffer(data),
606 » » serialize.WithContext, ds.KeyContext{}) 606 » » serialize.WithContext, ds.MkKeyContext("", ""))
607 } 607 }
608 608
609 func namespaces(store memStore) []string { 609 func namespaces(store memStore) []string {
610 var namespaces []string 610 var namespaces []string
611 for _, c := range store.GetCollectionNames() { 611 for _, c := range store.GetCollectionNames() {
612 ns, has := trimPrefix(c, "ents:") 612 ns, has := trimPrefix(c, "ents:")
613 if !has { 613 if !has {
614 if len(namespaces) > 0 { 614 if len(namespaces) > 0 {
615 break 615 break
616 } 616 }
617 continue 617 continue
618 } 618 }
619 namespaces = append(namespaces, ns) 619 namespaces = append(namespaces, ns)
620 } 620 }
621 return namespaces 621 return namespaces
622 } 622 }
623 623
624 func trimPrefix(v, p string) (string, bool) { 624 func trimPrefix(v, p string) (string, bool) {
625 if strings.HasPrefix(v, p) { 625 if strings.HasPrefix(v, p) {
626 return v[len(p):], true 626 return v[len(p):], true
627 } 627 }
628 return v, false 628 return v, false
629 } 629 }
OLDNEW
« no previous file with comments | « filter/txnBuf/txnbuf_test.go ('k') | impl/memory/datastore_index.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698