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

Unified Diff: impl/memory/datastore_query.go

Issue 1365743002: Refactor serialization helpers from impl/memory -> service/datastore/serialize (Closed) Base URL: https://github.com/luci/gae.git@estimate_size
Patch Set: fix comments Created 5 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | impl/memory/datastore_query_execution.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/datastore_query.go
diff --git a/impl/memory/datastore_query.go b/impl/memory/datastore_query.go
index ba19717682a206b16e3c35d5eea9019543722307..ed49a79820546cfda2b50916961a24563b302a4d 100644
--- a/impl/memory/datastore_query.go
+++ b/impl/memory/datastore_query.go
@@ -168,10 +168,10 @@ func reduce(fq *ds.FinalizedQuery, ns string, isTxn bool) (*reducedQuery, error)
if ret.suffixFormat[0].Descending {
hi, lo := []byte(nil), []byte(nil)
if len(startD) > 0 {
- lo = increment(invert(startD))
+ lo = increment(serialize.Invert(startD))
}
if len(endD) > 0 {
- hi = increment(invert(endD))
+ hi = increment(serialize.Invert(endD))
}
endD, startD = lo, hi
}
@@ -245,3 +245,25 @@ func reduce(fq *ds.FinalizedQuery, ns string, isTxn bool) (*reducedQuery, error)
return ret, nil
}
+
+func increment(bstr []byte) []byte {
+ ret, overflow := serialize.Increment(bstr)
+ if overflow {
+ // This byte string was ALL 0xFF's. The only safe incrementation to do here
+ // would be to add a new byte to the beginning of bstr with the value 0x01,
+ // and a byte to the beginning OF ALL OTHER []byte's which bstr may be
+ // compared with. This is obviously impossible to do here, so panic. If we
+ // hit this, then we would need to add a spare 0 byte before every index
+ // column.
+ //
+ // Another way to think about this is that we just accumulated a 'carry' bit,
+ // and the new value has overflowed this representation.
+ //
+ // Fortunately, the first byte of a serialized index column entry is a
+ // PropertyType byte, and the only valid values that we'll be incrementing
+ // are never equal to 0xFF, since they have the high bit set (so either they're
+ // 0x8*, or 0x7*, depending on if it's inverted).
+ impossible(fmt.Errorf("incrementing %v would require more sigfigs", bstr))
+ }
+ return ret
+}
« no previous file with comments | « impl/memory/datastore_index_test.go ('k') | impl/memory/datastore_query_execution.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698