| 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 "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" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 74 } |
| 75 | 75 |
| 76 func (d *dataStoreData) Lock() { | 76 func (d *dataStoreData) Lock() { |
| 77 d.rwlock.Lock() | 77 d.rwlock.Lock() |
| 78 } | 78 } |
| 79 | 79 |
| 80 func (d *dataStoreData) Unlock() { | 80 func (d *dataStoreData) Unlock() { |
| 81 d.rwlock.Unlock() | 81 d.rwlock.Unlock() |
| 82 } | 82 } |
| 83 | 83 |
| 84 /////////////////////////// indicies(dataStoreData) //////////////////////////// |
| 85 |
| 84 func groupMetaKey(key *datastore.Key) []byte { | 86 func groupMetaKey(key *datastore.Key) []byte { |
| 85 return keyBytes(noNS, newKey("", "__entity_group__", "", 1, rootKey(key)
)) | 87 return keyBytes(noNS, newKey("", "__entity_group__", "", 1, rootKey(key)
)) |
| 86 } | 88 } |
| 87 | 89 |
| 88 func groupIDsKey(key *datastore.Key) []byte { | 90 func groupIDsKey(key *datastore.Key) []byte { |
| 89 return keyBytes(noNS, newKey("", "__entity_group_ids__", "", 1, rootKey(
key))) | 91 return keyBytes(noNS, newKey("", "__entity_group_ids__", "", 1, rootKey(
key))) |
| 90 } | 92 } |
| 91 | 93 |
| 92 func rootIDsKey(kind string) []byte { | 94 func rootIDsKey(kind string) []byte { |
| 93 return keyBytes(noNS, newKey("", "__entity_root_ids__", kind, 0, nil)) | 95 return keyBytes(noNS, newKey("", "__entity_root_ids__", kind, 0, nil)) |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 defer d.rwlock.Unlock() | 184 defer d.rwlock.Unlock() |
| 183 | 185 |
| 184 ents, key, err := d.entsKeyLocked(key) | 186 ents, key, err := d.entsKeyLocked(key) |
| 185 if err != nil { | 187 if err != nil { |
| 186 return nil, err | 188 return nil, err |
| 187 } | 189 } |
| 188 if _, err = incrementLocked(ents, groupMetaKey(key)); err != nil { | 190 if _, err = incrementLocked(ents, groupMetaKey(key)); err != nil { |
| 189 return nil, err | 191 return nil, err |
| 190 } | 192 } |
| 191 | 193 |
| 194 old := ents.Get(keyBytes(noNS, key)) |
| 195 oldPl := (*propertyList)(nil) |
| 196 if old != nil { |
| 197 oldPl = &propertyList{} |
| 198 if err = oldPl.UnmarshalBinary(old); err != nil { |
| 199 return nil, err |
| 200 } |
| 201 } |
| 202 if err = updateIndicies(d.store, key, oldPl, data); err != nil { |
| 203 return nil, err |
| 204 } |
| 205 |
| 192 ents.Set(keyBytes(noNS, key), dataBytes) | 206 ents.Set(keyBytes(noNS, key), dataBytes) |
| 193 | 207 |
| 194 return key, nil | 208 return key, nil |
| 195 } | 209 } |
| 196 | 210 |
| 197 func getInner(ns string, knr goon.KindNameResolver, dst interface{}, getColl fun
c(*datastore.Key) (*memCollection, error)) error { | 211 func getInner(ns string, knr goon.KindNameResolver, dst interface{}, getColl fun
c(*datastore.Key) (*memCollection, error)) error { |
| 198 key := newKeyObj(ns, knr, dst) | 212 key := newKeyObj(ns, knr, dst) |
| 199 if !keyValid(ns, key, allowSpecialKeys) { | 213 if !keyValid(ns, key, allowSpecialKeys) { |
| 200 return datastore.ErrInvalidKey | 214 return datastore.ErrInvalidKey |
| 201 } | 215 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 defer d.rwlock.Unlock() | 253 defer d.rwlock.Unlock() |
| 240 | 254 |
| 241 ents := d.store.GetCollection("ents:" + ns) | 255 ents := d.store.GetCollection("ents:" + ns) |
| 242 if ents == nil { | 256 if ents == nil { |
| 243 return nil | 257 return nil |
| 244 } | 258 } |
| 245 if _, err := incrementLocked(ents, groupMetaKey(key)); err != nil { | 259 if _, err := incrementLocked(ents, groupMetaKey(key)); err != nil { |
| 246 return err | 260 return err |
| 247 } | 261 } |
| 248 | 262 |
| 263 old := ents.Get(keyBuf) |
| 264 oldPl := (*propertyList)(nil) |
| 265 if old != nil { |
| 266 oldPl = &propertyList{} |
| 267 if err := oldPl.UnmarshalBinary(old); err != nil { |
| 268 return err |
| 269 } |
| 270 } |
| 271 if err := updateIndicies(d.store, key, oldPl, nil); err != nil { |
| 272 return err |
| 273 } |
| 274 |
| 249 ents.Delete(keyBuf) | 275 ents.Delete(keyBuf) |
| 250 return nil | 276 return nil |
| 251 } | 277 } |
| 252 | 278 |
| 253 func (d *dataStoreData) canApplyTxn(obj memContextObj) bool { | 279 func (d *dataStoreData) canApplyTxn(obj memContextObj) bool { |
| 254 // TODO(riannucci): implement with Flush/FlushRevert for persistance. | 280 // TODO(riannucci): implement with Flush/FlushRevert for persistance. |
| 255 | 281 |
| 256 txn := obj.(*txnDataStoreData) | 282 txn := obj.(*txnDataStoreData) |
| 257 for rk, muts := range txn.muts { | 283 for rk, muts := range txn.muts { |
| 258 if len(muts) == 0 { // read-only | 284 if len(muts) == 0 { // read-only |
| 259 continue | 285 continue |
| 260 } | 286 } |
| 261 » » k, err := keyFromByteString(withNS, rk) | 287 » » k, err := keyFromByteString(withNS, rk, "") |
| 262 if err != nil { | 288 if err != nil { |
| 263 panic(err) | 289 panic(err) |
| 264 } | 290 } |
| 265 entKey := "ents:" + k.Namespace() | 291 entKey := "ents:" + k.Namespace() |
| 266 mkey := groupMetaKey(k) | 292 mkey := groupMetaKey(k) |
| 267 entsHead := d.store.GetCollection(entKey) | 293 entsHead := d.store.GetCollection(entKey) |
| 268 entsSnap := txn.snap.GetCollection(entKey) | 294 entsSnap := txn.snap.GetCollection(entKey) |
| 269 vHead, err := curVersion(entsHead, mkey) | 295 vHead, err := curVersion(entsHead, mkey) |
| 270 if err != nil { | 296 if err != nil { |
| 271 panic(err) | 297 panic(err) |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 return td.snap.GetCollection("ents:" + ns), nil | 468 return td.snap.GetCollection("ents:" + ns), nil |
| 443 }) | 469 }) |
| 444 } | 470 } |
| 445 | 471 |
| 446 func (td *txnDataStoreData) del(ns string, key *datastore.Key) error { | 472 func (td *txnDataStoreData) del(ns string, key *datastore.Key) error { |
| 447 if !keyValid(ns, key, userKeyOnly) { | 473 if !keyValid(ns, key, userKeyOnly) { |
| 448 return datastore.ErrInvalidKey | 474 return datastore.ErrInvalidKey |
| 449 } | 475 } |
| 450 return td.writeMutation(false, key, nil) | 476 return td.writeMutation(false, key, nil) |
| 451 } | 477 } |
| OLD | NEW |