| 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 "sync" | 9 "sync" |
| 10 | 10 |
| 11 "github.com/luci/gae/service/datastore/serialize" | 11 "github.com/luci/gae/service/datastore/serialize" |
| 12 "github.com/luci/gkvlite" | 12 "github.com/luci/gkvlite" |
| 13 ) | 13 ) |
| 14 | 14 |
| 15 type iterDefinition struct { | 15 type iterDefinition struct { |
| 16 // The collection to iterate over | 16 // The collection to iterate over |
| 17 » c *memCollection | 17 » c memCollection |
| 18 | 18 |
| 19 // The prefix to always assert for every row. A nil prefix matches every
row. | 19 // The prefix to always assert for every row. A nil prefix matches every
row. |
| 20 prefix []byte | 20 prefix []byte |
| 21 | 21 |
| 22 // prefixLen is the number of prefix bytes that the caller cares about.
It | 22 // prefixLen is the number of prefix bytes that the caller cares about.
It |
| 23 // may be <= len(prefix). When doing a multiIterator, this number will b
e used | 23 // may be <= len(prefix). When doing a multiIterator, this number will b
e used |
| 24 // to determine the amount of suffix to transfer accross iterators. This
is | 24 // to determine the amount of suffix to transfer accross iterators. This
is |
| 25 // used specifically when using builtin indexes to service ancestor quer
ies. | 25 // used specifically when using builtin indexes to service ancestor quer
ies. |
| 26 // The builtin index represents the ancestor key with prefix bytes, but
in a | 26 // The builtin index represents the ancestor key with prefix bytes, but
in a |
| 27 // multiIterator context, it wants the entire key to be included in the | 27 // multiIterator context, it wants the entire key to be included in the |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 112 } |
| 113 | 113 |
| 114 type iterator struct { | 114 type iterator struct { |
| 115 stopper sync.Once | 115 stopper sync.Once |
| 116 | 116 |
| 117 stopped bool | 117 stopped bool |
| 118 ch chan<- *cmd | 118 ch chan<- *cmd |
| 119 } | 119 } |
| 120 | 120 |
| 121 func (def *iterDefinition) mkIter() *iterator { | 121 func (def *iterDefinition) mkIter() *iterator { |
| 122 if !def.c.IsReadOnly() { |
| 123 panic("attempting to make an iterator with r/w collection") |
| 124 } |
| 125 |
| 122 cmdChan := make(chan *cmd) | 126 cmdChan := make(chan *cmd) |
| 123 ret := &iterator{ | 127 ret := &iterator{ |
| 124 ch: cmdChan, | 128 ch: cmdChan, |
| 125 } | 129 } |
| 126 | 130 |
| 127 prefix := def.prefix | 131 prefix := def.prefix |
| 128 collection := def.c | 132 collection := def.c |
| 129 | 133 |
| 130 // convert the suffixes from the iterDefinition into full rows for the | 134 // convert the suffixes from the iterDefinition into full rows for the |
| 131 // underlying storage. | 135 // underlying storage. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 t.ch <- &cmd{targ, func(i *gkvlite.Item) { | 211 t.ch <- &cmd{targ, func(i *gkvlite.Item) { |
| 208 defer close(waiter) | 212 defer close(waiter) |
| 209 | 213 |
| 210 if i == nil { | 214 if i == nil { |
| 211 t.stop() | 215 t.stop() |
| 212 } | 216 } |
| 213 cb(i) | 217 cb(i) |
| 214 }} | 218 }} |
| 215 <-waiter | 219 <-waiter |
| 216 } | 220 } |
| OLD | NEW |