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

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

Issue 1369353003: Make impl/memory have an AppID. (Closed) Base URL: https://github.com/luci/gae.git@fix_consistent
Patch Set: Created 5 years, 2 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
OLDNEW
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
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, ns string, compIdx []*ds.IndexDefinition) { 227 func addIndexes(store *memStore, aid, ns 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 if allEnts := store.GetCollection("ents:" + ns); allEnts != nil {
236 allEnts.VisitItemsAscend(nil, true, func(i *gkvlite.Item) bool { 236 allEnts.VisitItemsAscend(nil, true, func(i *gkvlite.Item) bool {
237 » » » pm, err := rpmWoCtx(i.Val, ns) 237 » » » pm, err := rpm(i.Val)
238 memoryCorruption(err) 238 memoryCorruption(err)
239 239
240 » » » prop, err := serialize.ReadProperty(bytes.NewBuffer(i.Ke y), serialize.WithoutContext, globalAppID, ns) 240 » » » prop, err := serialize.ReadProperty(bytes.NewBuffer(i.Ke y), serialize.WithoutContext, aid, ns)
241 memoryCorruption(err) 241 memoryCorruption(err)
242 242
243 k := prop.Value().(*ds.Key) 243 k := prop.Value().(*ds.Key)
244 244
245 sip := serialize.PropertyMapPartially(k, pm) 245 sip := serialize.PropertyMapPartially(k, pm)
246 246
247 mergeIndexes(ns, store, 247 mergeIndexes(ns, store,
248 newMemStore(), 248 newMemStore(),
249 indexEntries(sip, ns, normalized)) 249 indexEntries(sip, ns, normalized))
250 return true 250 return true
251 }) 251 })
252 } 252 }
253 } 253 }
254 254
255 func updateIndexes(store *memStore, key *ds.Key, oldEnt, newEnt ds.PropertyMap) { 255 func updateIndexes(store *memStore, key *ds.Key, oldEnt, newEnt ds.PropertyMap) {
256 // load all current complex query index definitions. 256 // load all current complex query index definitions.
257 compIdx := []*ds.IndexDefinition{} 257 compIdx := []*ds.IndexDefinition{}
258 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool { 258 walkCompIdxs(store, nil, func(i *ds.IndexDefinition) bool {
259 compIdx = append(compIdx, i) 259 compIdx = append(compIdx, i)
260 return true 260 return true
261 }) 261 })
262 262
263 mergeIndexes(key.Namespace(), store, 263 mergeIndexes(key.Namespace(), store,
264 indexEntriesWithBuiltins(key, oldEnt, compIdx), 264 indexEntriesWithBuiltins(key, oldEnt, compIdx),
265 indexEntriesWithBuiltins(key, newEnt, compIdx)) 265 indexEntriesWithBuiltins(key, newEnt, compIdx))
266 } 266 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698