| 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 26 matching lines...) Expand all Loading... |
| 37 } | 37 } |
| 38 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I
ndexColumn{{Property: name}}}) | 38 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I
ndexColumn{{Property: name}}}) |
| 39 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I
ndexColumn{{Property: name, Direction: ds.DESCENDING}}}) | 39 ret = append(ret, &ds.IndexDefinition{Kind: kind, SortBy: []ds.I
ndexColumn{{Property: name, Direction: ds.DESCENDING}}}) |
| 40 } | 40 } |
| 41 if serializationDeterministic { | 41 if serializationDeterministic { |
| 42 sort.Sort(ret) | 42 sort.Sort(ret) |
| 43 } | 43 } |
| 44 return ret | 44 return ret |
| 45 } | 45 } |
| 46 | 46 |
| 47 func indexEntriesWithBuiltins(k ds.Key, pm ds.PropertyMap, complexIdxs []*ds.Ind
exDefinition) *memStore { | 47 func indexEntriesWithBuiltins(k *ds.Key, pm ds.PropertyMap, complexIdxs []*ds.In
dexDefinition) *memStore { |
| 48 sip := partiallySerialize(k, pm) | 48 sip := partiallySerialize(k, pm) |
| 49 » return sip.indexEntries(k.Namespace(), append(defaultIndexes(k.Kind(), p
m), complexIdxs...)) | 49 » return sip.indexEntries(k.Namespace(), append(defaultIndexes(k.Last().Ki
nd, pm), complexIdxs...)) |
| 50 } | 50 } |
| 51 | 51 |
| 52 // serializedPvals is all of the serialized DSProperty values in qASC order. | 52 // serializedPvals is all of the serialized DSProperty values in qASC order. |
| 53 type serializedPvals [][]byte | 53 type serializedPvals [][]byte |
| 54 | 54 |
| 55 func (s serializedPvals) Len() int { return len(s) } | 55 func (s serializedPvals) Len() int { return len(s) } |
| 56 func (s serializedPvals) Swap(i, j int) { s[i], s[j] = s[j], s[i] } | 56 func (s serializedPvals) Swap(i, j int) { s[i], s[j] = s[j], s[i] } |
| 57 func (s serializedPvals) Less(i, j int) bool { return bytes.Compare(s[i], s[j])
< 0 } | 57 func (s serializedPvals) Less(i, j int) bool { return bytes.Compare(s[i], s[j])
< 0 } |
| 58 | 58 |
| 59 // prop name -> [<serialized DSProperty>, ...] | 59 // prop name -> [<serialized DSProperty>, ...] |
| (...skipping 11 matching lines...) Expand all Loading... |
| 71 data := serialize.ToBytes(v.ForIndex()) | 71 data := serialize.ToBytes(v.ForIndex()) |
| 72 dataS := string(data) | 72 dataS := string(data) |
| 73 if !dups.Add(dataS) { | 73 if !dups.Add(dataS) { |
| 74 continue | 74 continue |
| 75 } | 75 } |
| 76 ret = append(ret, data) | 76 ret = append(ret, data) |
| 77 } | 77 } |
| 78 return ret | 78 return ret |
| 79 } | 79 } |
| 80 | 80 |
| 81 func partiallySerialize(k ds.Key, pm ds.PropertyMap) (ret serializedIndexablePma
p) { | 81 func partiallySerialize(k *ds.Key, pm ds.PropertyMap) (ret serializedIndexablePm
ap) { |
| 82 ret = make(serializedIndexablePmap, len(pm)+2) | 82 ret = make(serializedIndexablePmap, len(pm)+2) |
| 83 if k == nil { | 83 if k == nil { |
| 84 impossible(fmt.Errorf("key to partiallySerialize is nil")) | 84 impossible(fmt.Errorf("key to partiallySerialize is nil")) |
| 85 } | 85 } |
| 86 ret["__key__"] = [][]byte{serialize.ToBytes(ds.MkProperty(k))} | 86 ret["__key__"] = [][]byte{serialize.ToBytes(ds.MkProperty(k))} |
| 87 for k != nil { | 87 for k != nil { |
| 88 ret["__ancestor__"] = append(ret["__ancestor__"], serialize.ToBy
tes(ds.MkProperty(k))) | 88 ret["__ancestor__"] = append(ret["__ancestor__"], serialize.ToBy
tes(ds.MkProperty(k))) |
| 89 k = k.Parent() | 89 k = k.Parent() |
| 90 } | 90 } |
| 91 for k, vals := range pm { | 91 for k, vals := range pm { |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 } | 282 } |
| 283 | 283 |
| 284 if allEnts := store.GetCollection("ents:" + ns); allEnts != nil { | 284 if allEnts := store.GetCollection("ents:" + ns); allEnts != nil { |
| 285 allEnts.VisitItemsAscend(nil, true, func(i *gkvlite.Item) bool { | 285 allEnts.VisitItemsAscend(nil, true, func(i *gkvlite.Item) bool { |
| 286 pm, err := rpmWoCtx(i.Val, ns) | 286 pm, err := rpmWoCtx(i.Val, ns) |
| 287 memoryCorruption(err) | 287 memoryCorruption(err) |
| 288 | 288 |
| 289 prop, err := serialize.ReadProperty(bytes.NewBuffer(i.Ke
y), serialize.WithoutContext, globalAppID, ns) | 289 prop, err := serialize.ReadProperty(bytes.NewBuffer(i.Ke
y), serialize.WithoutContext, globalAppID, ns) |
| 290 memoryCorruption(err) | 290 memoryCorruption(err) |
| 291 | 291 |
| 292 » » » k := prop.Value().(ds.Key) | 292 » » » k := prop.Value().(*ds.Key) |
| 293 | 293 |
| 294 sip := partiallySerialize(k, pm) | 294 sip := partiallySerialize(k, pm) |
| 295 | 295 |
| 296 mergeIndexes(ns, store, | 296 mergeIndexes(ns, store, |
| 297 newMemStore(), | 297 newMemStore(), |
| 298 sip.indexEntries(ns, normalized)) | 298 sip.indexEntries(ns, normalized)) |
| 299 return true | 299 return true |
| 300 }) | 300 }) |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 func updateIndexes(store *memStore, key ds.Key, oldEnt, newEnt ds.PropertyMap) { | 304 func updateIndexes(store *memStore, key *ds.Key, oldEnt, newEnt ds.PropertyMap)
{ |
| 305 // load all current complex query index definitions. | 305 // load all current complex query index definitions. |
| 306 compIdx := []*ds.IndexDefinition{} | 306 compIdx := []*ds.IndexDefinition{} |
| 307 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool { | 307 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool { |
| 308 compIdx = append(compIdx, i) | 308 compIdx = append(compIdx, i) |
| 309 return true | 309 return true |
| 310 }) | 310 }) |
| 311 | 311 |
| 312 mergeIndexes(key.Namespace(), store, | 312 mergeIndexes(key.Namespace(), store, |
| 313 indexEntriesWithBuiltins(key, oldEnt, compIdx), | 313 indexEntriesWithBuiltins(key, oldEnt, compIdx), |
| 314 indexEntriesWithBuiltins(key, newEnt, compIdx)) | 314 indexEntriesWithBuiltins(key, newEnt, compIdx)) |
| 315 } | 315 } |
| OLD | NEW |