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 "fmt" | 9 "fmt" |
10 "sync" | 10 "sync" |
(...skipping 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 func (d *dataStoreData) Lock() { | 40 func (d *dataStoreData) Lock() { |
41 d.rwlock.Lock() | 41 d.rwlock.Lock() |
42 } | 42 } |
43 | 43 |
44 func (d *dataStoreData) Unlock() { | 44 func (d *dataStoreData) Unlock() { |
45 d.rwlock.Unlock() | 45 d.rwlock.Unlock() |
46 } | 46 } |
47 | 47 |
| 48 func (d *dataStoreData) getQuerySnaps(consistent bool) (idx, head *memStore) { |
| 49 d.rwlock.RLock() |
| 50 defer d.rwlock.RUnlock() |
| 51 head = d.store.Snapshot() |
| 52 if consistent { |
| 53 idx = head |
| 54 } else { |
| 55 idx = d.snap |
| 56 } |
| 57 return |
| 58 } |
| 59 |
| 60 func (d *dataStoreData) takeSnapshot() *memStore { |
| 61 d.rwlock.RLock() |
| 62 defer d.rwlock.RUnlock() |
| 63 return d.store.Snapshot() |
| 64 } |
| 65 |
| 66 func (d *dataStoreData) setSnapshot(snap *memStore) { |
| 67 d.rwlock.Lock() |
| 68 defer d.rwlock.Unlock() |
| 69 d.snap = snap |
| 70 } |
| 71 |
| 72 func (d *dataStoreData) catchupIndexes() { |
| 73 d.rwlock.Lock() |
| 74 defer d.rwlock.Unlock() |
| 75 d.snap = d.store.Snapshot() |
| 76 } |
| 77 |
48 /////////////////////////// indicies(dataStoreData) //////////////////////////// | 78 /////////////////////////// indicies(dataStoreData) //////////////////////////// |
49 | 79 |
50 func groupMetaKey(key ds.Key) []byte { | 80 func groupMetaKey(key ds.Key) []byte { |
51 return keyBytes(ds.WithoutContext, | 81 return keyBytes(ds.WithoutContext, |
52 ds.NewKey("", "", "__entity_group__", "", 1, ds.KeyRoot(key))) | 82 ds.NewKey("", "", "__entity_group__", "", 1, ds.KeyRoot(key))) |
53 } | 83 } |
54 | 84 |
55 func groupIDsKey(key ds.Key) []byte { | 85 func groupIDsKey(key ds.Key) []byte { |
56 return keyBytes(ds.WithoutContext, | 86 return keyBytes(ds.WithoutContext, |
57 ds.NewKey("", "", "__entity_group_ids__", "", 1, ds.KeyRoot(key)
)) | 87 ds.NewKey("", "", "__entity_group_ids__", "", 1, ds.KeyRoot(key)
)) |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 cb(nil, ds.ErrNoSuchEntity) | 188 cb(nil, ds.ErrNoSuchEntity) |
159 continue | 189 continue |
160 } | 190 } |
161 cb(rpmWoCtx(pdata, k.Namespace())) | 191 cb(rpmWoCtx(pdata, k.Namespace())) |
162 } | 192 } |
163 return nil | 193 return nil |
164 } | 194 } |
165 | 195 |
166 func (d *dataStoreData) getMulti(keys []ds.Key, cb ds.GetMultiCB) error { | 196 func (d *dataStoreData) getMulti(keys []ds.Key, cb ds.GetMultiCB) error { |
167 getMultiInner(keys, cb, func() (*memCollection, error) { | 197 getMultiInner(keys, cb, func() (*memCollection, error) { |
168 » » d.rwlock.RLock() | 198 » » s := d.takeSnapshot() |
169 » » s := d.store.Snapshot() | |
170 » » d.rwlock.RUnlock() | |
171 | 199 |
172 return s.GetCollection("ents:" + keys[0].Namespace()), nil | 200 return s.GetCollection("ents:" + keys[0].Namespace()), nil |
173 }) | 201 }) |
174 return nil | 202 return nil |
175 } | 203 } |
176 | 204 |
177 func (d *dataStoreData) delMulti(keys []ds.Key, cb ds.DeleteMultiCB) { | 205 func (d *dataStoreData) delMulti(keys []ds.Key, cb ds.DeleteMultiCB) { |
178 toDel := make([][]byte, 0, len(keys)) | 206 toDel := make([][]byte, 0, len(keys)) |
179 for _, k := range keys { | 207 for _, k := range keys { |
180 toDel = append(toDel, keyBytes(ds.WithoutContext, k)) | 208 toDel = append(toDel, keyBytes(ds.WithoutContext, k)) |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 440 |
413 func rpm(data []byte) (ds.PropertyMap, error) { | 441 func rpm(data []byte) (ds.PropertyMap, error) { |
414 ret := ds.PropertyMap{} | 442 ret := ds.PropertyMap{} |
415 err := ret.Read(bytes.NewBuffer(data), ds.WithContext, "", "") | 443 err := ret.Read(bytes.NewBuffer(data), ds.WithContext, "", "") |
416 return ret, err | 444 return ret, err |
417 } | 445 } |
418 | 446 |
419 type keyitem interface { | 447 type keyitem interface { |
420 Key() ds.Key | 448 Key() ds.Key |
421 } | 449 } |
OLD | NEW |