Index full sortkey field in secondary index
Using the sort key of the last element for pagination only works as long as every sort key is unique. This is true for the general definition of this field in the Change object, which includes the unique change ID at the end of the hex string. Previously, we were incorrectly truncating the change ID off, resulting in many changes in the same sort key bucket and thus broken pagination. Having two different definitions of sort key in the same running server makes it a bit ugly to handle SortKeyPredicates, since the definition of min/max value is now schema dependent, but at least we can keep the same field name. Don't @Deprecate the new SORTKEY field. We were originally hoping to remove this field and depend only on the UPDATED field (with the change ID as tiebreaker), but as long as this field is used for pagination, we have to keep it around. This is because we can't be sure a secondary index will be able to express a query like "(field X, field Y) > (N, M)" to allow us to restart a query in the middle of an UPDATED bucket. We may still decide to scrap the current pagination system but that will probably not happen until we kill the SQL index code. Change-Id: Icb760dbacd01939e5e4936ef87165b6dddcacdc0
This commit is contained in:
@@ -125,8 +125,32 @@ public class ChangeField {
|
||||
}
|
||||
};
|
||||
|
||||
/** Sort key field, duplicates {@link #UPDATED}. */
|
||||
@Deprecated
|
||||
public static long legacyParseSortKey(String sortKey) {
|
||||
if ("z".equals(sortKey)) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
return Long.parseLong(sortKey.substring(0, 8), 16);
|
||||
}
|
||||
|
||||
/** Legacy sort key field. */
|
||||
@Deprecated
|
||||
public static final FieldDef<ChangeData, Long> LEGACY_SORTKEY =
|
||||
new FieldDef.Single<ChangeData, Long>(
|
||||
"sortkey", FieldType.LONG, true) {
|
||||
@Override
|
||||
public Long get(ChangeData input, FillArgs args)
|
||||
throws OrmException {
|
||||
return legacyParseSortKey(input.change(args.db).getSortKey());
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Sort key field.
|
||||
* <p>
|
||||
* Redundant with {@link #UPDATED} and {@link #LEGACY_ID}, but secondary index
|
||||
* implementations may not be able to search over tuples of values.
|
||||
*/
|
||||
public static final FieldDef<ChangeData, Long> SORTKEY =
|
||||
new FieldDef.Single<ChangeData, Long>(
|
||||
"sortkey", FieldType.LONG, true) {
|
||||
|
Reference in New Issue
Block a user