Skip to content

Commit eb68481

Browse files
authored
Enable new KeyValueCursorBaseContinuation serialization (#3671)
1 parent 805e469 commit eb68481

File tree

5 files changed

+24
-27
lines changed

5 files changed

+24
-27
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/KeyValueCursorBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public abstract static class Builder<T extends Builder<T>> {
281281

282282
protected Builder(@Nonnull Subspace subspace) {
283283
this.subspace = subspace;
284-
this.serializationMode = SerializationMode.TO_OLD;
284+
this.serializationMode = SerializationMode.TO_NEW;
285285
}
286286

287287
/**

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/plans/RecordQueryIndexPlan.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public RecordQueryIndexPlan(@Nonnull final String indexName,
219219
@Nonnull final Optional<? extends MatchCandidate> matchCandidateOptional,
220220
@Nonnull final Type resultType,
221221
@Nonnull final QueryPlanConstraint constraint) {
222-
this(indexName, commonPrimaryKey, scanParameters, indexFetchMethod, fetchIndexRecords, reverse, strictlySorted, matchCandidateOptional, resultType, constraint, KeyValueCursorBase.SerializationMode.TO_OLD);
222+
this(indexName, commonPrimaryKey, scanParameters, indexFetchMethod, fetchIndexRecords, reverse, strictlySorted, matchCandidateOptional, resultType, constraint, KeyValueCursorBase.SerializationMode.TO_NEW);
223223
}
224224

225225
@VisibleForTesting
@@ -834,7 +834,7 @@ public byte[] toBytes() {
834834
if (bytes == null) {
835835
synchronized (this) {
836836
if (bytes == null) {
837-
bytes = KeyValueCursorBase.Continuation.getInnerContinuation(new KeyValueCursorBase.Continuation(KeyValueCursorBase.Continuation.getInnerContinuation(baseContinuation.toBytes()), prefixLength, serializationMode).toBytes());
837+
bytes = new KeyValueCursorBase.Continuation(KeyValueCursorBase.Continuation.getInnerContinuation(baseContinuation.toBytes()), prefixLength, serializationMode).toBytes();
838838
}
839839
}
840840
}

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/ExplainTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ void explainWithContinuationSerializedPlanTest() throws Exception {
135135
final var continuationInfo = resultSet.getStruct(5);
136136
org.junit.jupiter.api.Assertions.assertNotNull(continuationInfo);
137137
final var assertStruct = RelationalStructAssert.assertThat(continuationInfo);
138-
assertStruct.hasValue("EXECUTION_STATE", new byte[]{0, 21, 1, 21, 11});
138+
assertStruct.hasValue("EXECUTION_STATE", new byte[]{10, 5, 0, 21, 1, 21, 11, 17, -84, -51, 115, -104, -35, 66, 0, 94});
139139
assertStruct.hasValue("VERSION", 1);
140140
assertStruct.hasValue("PLAN_HASH_MODE", "VC0");
141141
assertStruct.hasValue("PLAN_HASH", -1635569052);
@@ -167,7 +167,7 @@ void explainWithContinuationSerializedPlanWithDifferentQueryTest() throws Except
167167
final var continuationInfo = resultSet.getStruct(5);
168168
org.junit.jupiter.api.Assertions.assertNotNull(continuationInfo);
169169
final var assertStruct = RelationalStructAssert.assertThat(continuationInfo);
170-
assertStruct.hasValue("EXECUTION_STATE", new byte[]{0, 21, 1, 21, 11});
170+
assertStruct.hasValue("EXECUTION_STATE", new byte[]{10, 5, 0, 21, 1, 21, 11, 17, -84, -51, 115, -104, -35, 66, 0, 94});
171171
assertStruct.hasValue("VERSION", 1);
172172
assertStruct.hasValue("PLAN_HASH_MODE", "VC0");
173173
assertStruct.hasValue("PLAN_HASH", -1635569052);
@@ -199,7 +199,7 @@ void explainExecuteStatementTest() throws Exception {
199199
final var continuationInfo = resultSet.getStruct(5);
200200
org.junit.jupiter.api.Assertions.assertNotNull(continuationInfo);
201201
final var assertStruct = RelationalStructAssert.assertThat(continuationInfo);
202-
assertStruct.hasValue("EXECUTION_STATE", new byte[]{0, 21, 1, 21, 11});
202+
assertStruct.hasValue("EXECUTION_STATE", new byte[]{10, 5, 0, 21, 1, 21, 11, 17, -84, -51, 115, -104, -35, 66, 0, 94});
203203
assertStruct.hasValue("VERSION", 1);
204204
assertStruct.hasValue("PLAN_HASH_MODE", "VC0");
205205
assertStruct.hasValue("PLAN_HASH", -1635569052);

fdb-relational-core/src/test/java/com/apple/foundationdb/relational/recordlayer/query/ForceContinuationQueryTests.java

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
package com.apple.foundationdb.relational.recordlayer.query;
2222

2323
import com.apple.foundationdb.relational.api.Continuation;
24-
import com.apple.foundationdb.relational.api.exceptions.ContextualSQLException;
2524
import com.apple.foundationdb.relational.recordlayer.EmbeddedRelationalExtension;
2625
import com.apple.foundationdb.relational.recordlayer.RelationalConnectionRule;
2726
import com.apple.foundationdb.relational.recordlayer.RelationalStatementRule;
@@ -31,7 +30,6 @@
3130
import org.junit.jupiter.api.Assertions;
3231
import org.junit.jupiter.api.BeforeAll;
3332
import org.junit.jupiter.api.BeforeEach;
34-
import org.junit.jupiter.api.Disabled;
3533
import org.junit.jupiter.api.Order;
3634
import org.junit.jupiter.api.extension.RegisterExtension;
3735
import org.junit.jupiter.params.ParameterizedTest;
@@ -94,26 +92,7 @@ void setup() throws Exception {
9492
statement.execute("delete from t3");
9593
}
9694

97-
@ParameterizedTest
98-
@MethodSource("failedQueries")
99-
void testOldSerializationFails(String sql, long result) throws Exception {
100-
Continuation continuation;
101-
statement.setMaxRows(1);
102-
try (var resultSet = statement.executeQuery(sql)) {
103-
Assertions.assertTrue(resultSet.next());
104-
Assertions.assertEquals(result, resultSet.getLong(1));
105-
continuation = resultSet.getContinuation();
106-
}
107-
// old kvCursorContinuation cause continuation at beginning exception
108-
try (final var preparedStatement = connection.prepareStatement("EXECUTE CONTINUATION ?param")) {
109-
preparedStatement.setMaxRows(1);
110-
preparedStatement.setBytes("param", continuation.serialize());
111-
Assertions.assertThrows(ContextualSQLException.class, preparedStatement::executeQuery);
112-
}
113-
}
114-
11595
// disabled until SerializationMode = TO_NEW
116-
@Disabled
11796
@ParameterizedTest
11897
@MethodSource("failedQueries")
11998
void testNewSerialization(String sql, long result) throws Exception {

yaml-tests/src/test/resources/aggregate-index-tests-count.yamsql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ test_block:
5050
# Cannot run with FORCE_CONTINUATIONS due to: https://github.com/FoundationDB/fdb-record-layer/issues/3206
5151
- maxRows: 0
5252
- result: [{4}]
53+
-
54+
- query: select count(*) from t1
55+
- explain: "AISCAN(MV1 <,> BY_GROUP -> [_0: VALUE:[0]]) | MAP (_ AS _0) | ON EMPTY NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
56+
# https://github.com/FoundationDB/fdb-record-layer/issues/3206 is fixed since !current_version
57+
- maxRows: 1
58+
- initialVersionAtLeast: !current_version
59+
- result: [{4}]
60+
- result: []
61+
- initialVersionLessThan: !current_version
5362
-
5463
- query: select count(*) from t1 group by col2
5564
- explain: "AISCAN(MV2 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) | MAP (_._1 AS _0)"
@@ -60,6 +69,15 @@ test_block:
6069
# Cannot run with FORCE_CONTINUATIONS due to: https://github.com/FoundationDB/fdb-record-layer/issues/3206
6170
- maxRows: 0
6271
- result: [{2}]
72+
-
73+
- query: select count(col1) from t1
74+
- explain: "AISCAN(MV3 <,> BY_GROUP -> [_0: VALUE:[0]]) | MAP (_ AS _0) | ON EMPTY NULL | MAP (coalesce_long(_._0._0, promote(0l AS LONG)) AS _0)"
75+
# https://github.com/FoundationDB/fdb-record-layer/issues/3206 is fixed since !current_version
76+
- maxRows: 1
77+
- initialVersionAtLeast: !current_version
78+
- result: [{2}]
79+
- result: []
80+
- initialVersionLessThan: !current_version
6381
-
6482
- query: select count(col1) from t1 group by col2
6583
- explain: "AISCAN(MV4 <,> BY_GROUP -> [_0: KEY:[0], _1: VALUE:[0]]) | MAP (_._1 AS _0)"

0 commit comments

Comments
 (0)