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

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

Issue 1302813003: impl/memory: Implement Queries (Closed) Base URL: https://github.com/luci/gae.git@add_multi_iterator
Patch Set: inequalities work now Created 5 years, 4 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 "runtime" 9 "runtime"
10 "sync" 10 "sync"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 // memStore is a gkvlite.Store which will panic for anything which might 62 // memStore is a gkvlite.Store which will panic for anything which might
63 // otherwise return an error. 63 // otherwise return an error.
64 // 64 //
65 // This is reasonable for in-memory Store objects, since the only errors that 65 // This is reasonable for in-memory Store objects, since the only errors that
66 // should occur happen with file IO on the underlying file (which of course 66 // should occur happen with file IO on the underlying file (which of course
67 // doesn't exist). 67 // doesn't exist).
68 type memStore gkvlite.Store 68 type memStore gkvlite.Store
69 69
70 func newMemStore() *memStore { 70 func newMemStore() *memStore {
71 ret, err := gkvlite.NewStore(nil) 71 ret, err := gkvlite.NewStore(nil)
72 » if err != nil { 72 » memoryCorruption(err)
73 » » panic(err)
74 » }
75 return (*memStore)(ret) 73 return (*memStore)(ret)
76 } 74 }
77 75
78 func (ms *memStore) Snapshot() *memStore { 76 func (ms *memStore) Snapshot() *memStore {
79 ret := (*memStore)((*gkvlite.Store)(ms).Snapshot()) 77 ret := (*memStore)((*gkvlite.Store)(ms).Snapshot())
80 runtime.SetFinalizer((*gkvlite.Store)(ret), func(s *gkvlite.Store) { 78 runtime.SetFinalizer((*gkvlite.Store)(ret), func(s *gkvlite.Store) {
81 go s.Close() 79 go s.Close()
82 }) 80 })
83 return ret 81 return ret
84 } 82 }
(...skipping 13 matching lines...) Expand all
98 // memCollection is a gkvlite.Collection which will panic for anything which 96 // memCollection is a gkvlite.Collection which will panic for anything which
99 // might otherwise return an error. 97 // might otherwise return an error.
100 // 98 //
101 // This is reasonable for in-memory Store objects, since the only errors that 99 // This is reasonable for in-memory Store objects, since the only errors that
102 // should occur happen with file IO on the underlying file (which of course 100 // should occur happen with file IO on the underlying file (which of course
103 // doesn't exist. 101 // doesn't exist.
104 type memCollection gkvlite.Collection 102 type memCollection gkvlite.Collection
105 103
106 func (mc *memCollection) Get(k []byte) []byte { 104 func (mc *memCollection) Get(k []byte) []byte {
107 ret, err := (*gkvlite.Collection)(mc).Get(k) 105 ret, err := (*gkvlite.Collection)(mc).Get(k)
108 » if err != nil { 106 » memoryCorruption(err)
109 » » panic(err)
110 » }
111 return ret 107 return ret
112 } 108 }
113 109
114 func (mc *memCollection) MinItem(withValue bool) *gkvlite.Item { 110 func (mc *memCollection) MinItem(withValue bool) *gkvlite.Item {
115 ret, err := (*gkvlite.Collection)(mc).MinItem(withValue) 111 ret, err := (*gkvlite.Collection)(mc).MinItem(withValue)
116 » if err != nil { 112 » memoryCorruption(err)
117 » » panic(err)
118 » }
119 return ret 113 return ret
120 } 114 }
121 115
122 func (mc *memCollection) Set(k, v []byte) { 116 func (mc *memCollection) Set(k, v []byte) {
123 » if err := (*gkvlite.Collection)(mc).Set(k, v); err != nil { 117 » err := (*gkvlite.Collection)(mc).Set(k, v)
124 » » panic(err) 118 » memoryCorruption(err)
125 » }
126 } 119 }
127 120
128 func (mc *memCollection) Delete(k []byte) bool { 121 func (mc *memCollection) Delete(k []byte) bool {
129 ret, err := (*gkvlite.Collection)(mc).Delete(k) 122 ret, err := (*gkvlite.Collection)(mc).Delete(k)
130 » if err != nil { 123 » memoryCorruption(err)
131 » » panic(err)
132 » }
133 return ret 124 return ret
134 } 125 }
135 126
136 func (mc *memCollection) VisitItemsAscend(target []byte, withValue bool, visitor gkvlite.ItemVisitor) { 127 func (mc *memCollection) VisitItemsAscend(target []byte, withValue bool, visitor gkvlite.ItemVisitor) {
137 » if err := (*gkvlite.Collection)(mc).VisitItemsAscend(target, withValue, visitor); err != nil { 128 » err := (*gkvlite.Collection)(mc).VisitItemsAscend(target, withValue, vis itor)
138 » » panic(err) 129 » memoryCorruption(err)
139 » }
140 } 130 }
141 131
142 func (mc *memCollection) GetTotals() (numItems, numBytes uint64) { 132 func (mc *memCollection) GetTotals() (numItems, numBytes uint64) {
143 numItems, numBytes, err := (*gkvlite.Collection)(mc).GetTotals() 133 numItems, numBytes, err := (*gkvlite.Collection)(mc).GetTotals()
144 » if err != nil { 134 » memoryCorruption(err)
145 » » panic(err)
146 » }
147 return 135 return
148 } 136 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698