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 "sort" | 10 "sort" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 } | 217 } |
218 }) | 218 }) |
219 default: | 219 default: |
220 impossible(fmt.Errorf("both values from gkvCollide were
nil?")) | 220 impossible(fmt.Errorf("both values from gkvCollide were
nil?")) |
221 } | 221 } |
222 // TODO(riannucci): remove entries from idxColl and remove index
collections | 222 // TODO(riannucci): remove entries from idxColl and remove index
collections |
223 // when there are no index entries for that index any more. | 223 // when there are no index entries for that index any more. |
224 }) | 224 }) |
225 } | 225 } |
226 | 226 |
227 func addIndexes(store *memStore, aid, ns string, compIdx []*ds.IndexDefinition)
{ | 227 func addIndexes(store *memStore, aid string, compIdx []*ds.IndexDefinition) { |
228 normalized := make([]*ds.IndexDefinition, len(compIdx)) | 228 normalized := make([]*ds.IndexDefinition, len(compIdx)) |
229 idxColl := store.SetCollection("idx", nil) | 229 idxColl := store.SetCollection("idx", nil) |
230 for i, idx := range compIdx { | 230 for i, idx := range compIdx { |
231 normalized[i] = idx.Normalize() | 231 normalized[i] = idx.Normalize() |
232 idxColl.Set(serialize.ToBytes(*normalized[i].PrepForIdxTable()),
[]byte{}) | 232 idxColl.Set(serialize.ToBytes(*normalized[i].PrepForIdxTable()),
[]byte{}) |
233 } | 233 } |
234 | 234 |
235 » if allEnts := store.GetCollection("ents:" + ns); allEnts != nil { | 235 » for _, ns := range namespaces(store) { |
236 » » allEnts.VisitItemsAscend(nil, true, func(i *gkvlite.Item) bool { | 236 » » if allEnts := store.GetCollection("ents:" + ns); allEnts != nil
{ |
237 » » » pm, err := rpm(i.Val) | 237 » » » allEnts.VisitItemsAscend(nil, true, func(i *gkvlite.Item
) bool { |
238 » » » memoryCorruption(err) | 238 » » » » pm, err := rpm(i.Val) |
| 239 » » » » memoryCorruption(err) |
239 | 240 |
240 » » » prop, err := serialize.ReadProperty(bytes.NewBuffer(i.Ke
y), serialize.WithoutContext, aid, ns) | 241 » » » » prop, err := serialize.ReadProperty(bytes.NewBuf
fer(i.Key), serialize.WithoutContext, aid, ns) |
241 » » » memoryCorruption(err) | 242 » » » » memoryCorruption(err) |
242 | 243 |
243 » » » k := prop.Value().(*ds.Key) | 244 » » » » k := prop.Value().(*ds.Key) |
244 | 245 |
245 » » » sip := serialize.PropertyMapPartially(k, pm) | 246 » » » » sip := serialize.PropertyMapPartially(k, pm) |
246 | 247 |
247 » » » mergeIndexes(ns, store, | 248 » » » » mergeIndexes(ns, store, |
248 » » » » newMemStore(), | 249 » » » » » newMemStore(), |
249 » » » » indexEntries(sip, ns, normalized)) | 250 » » » » » indexEntries(sip, ns, normalized)) |
250 » » » return true | 251 » » » » return true |
251 » » }) | 252 » » » }) |
| 253 » » } |
252 } | 254 } |
253 } | 255 } |
254 | 256 |
255 func updateIndexes(store *memStore, key *ds.Key, oldEnt, newEnt ds.PropertyMap)
{ | 257 func updateIndexes(store *memStore, key *ds.Key, oldEnt, newEnt ds.PropertyMap)
{ |
256 // load all current complex query index definitions. | 258 // load all current complex query index definitions. |
257 compIdx := []*ds.IndexDefinition{} | 259 compIdx := []*ds.IndexDefinition{} |
258 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool { | 260 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool { |
259 compIdx = append(compIdx, i) | 261 compIdx = append(compIdx, i) |
260 return true | 262 return true |
261 }) | 263 }) |
262 | 264 |
263 mergeIndexes(key.Namespace(), store, | 265 mergeIndexes(key.Namespace(), store, |
264 indexEntriesWithBuiltins(key, oldEnt, compIdx), | 266 indexEntriesWithBuiltins(key, oldEnt, compIdx), |
265 indexEntriesWithBuiltins(key, newEnt, compIdx)) | 267 indexEntriesWithBuiltins(key, newEnt, compIdx)) |
266 } | 268 } |
OLD | NEW |