use of com.apple.foundationdb.record.RecordStoreState in project fdb-record-layer by FoundationDB.
the class FDBRestrictedIndexQueryTest method queryWithWriteOnly.
/**
* Verify that plans do not use write-only indexes.
* Verify that re-marking the index as readable makes the planner use the index again.
* TODO: Abstract out common code in queryWithWriteOnly, queryWithDisabled, queryAggregateWithWriteOnly and queryAggregateWithDisabled (https://github.com/FoundationDB/fdb-record-layer/issues/4)
*/
@DualPlannerTest
void queryWithWriteOnly() throws Exception {
RecordQuery query = RecordQuery.newBuilder().setRecordType("MySimpleRecord").setFilter(Query.field("num_value_3_indexed").greaterThanOrEquals(5)).build();
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
recordStore.deleteAllRecords();
recordStore.markIndexWriteOnly("MySimpleRecord$num_value_3_indexed").join();
recordStore.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1066).setNumValue3Indexed(6).build());
recordStore.saveRecord(TestRecords1Proto.MySimpleRecord.newBuilder().setRecNo(1766).setNumValue3Indexed(4).build());
RecordQueryPlanner planner = new RecordQueryPlanner(recordStore.getRecordMetaData(), recordStore.getRecordStoreState(), recordStore.getTimer());
// Scan(<,>) | [MySimpleRecord] | num_value_3_indexed GREATER_THAN_OR_EQUALS 5
RecordQueryPlan plan = planner.plan(query);
assertThat(plan, hasNoDescendant(indexScan(indexName(containsString("num_value_3_indexed")))));
assertEquals(-625770219, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(2115232442, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(703683667, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
List<TestRecords1Proto.MySimpleRecord> results = recordStore.executeQuery(plan).map(rec -> TestRecords1Proto.MySimpleRecord.newBuilder().mergeFrom(rec.getRecord()).build()).asList().get();
assertEquals(1, results.size());
assertEquals(1066, results.get(0).getRecNo());
assertEquals(6, results.get(0).getNumValue3Indexed());
TestHelpers.assertDiscardedExactly(1, context);
context.commit();
}
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context);
recordStore.uncheckedMarkIndexReadable("MySimpleRecord$num_value_3_indexed").join();
clearStoreCounter(context);
// Override state to read the write-only index.
RecordQueryPlanner planner = new RecordQueryPlanner(recordStore.getRecordMetaData(), new RecordStoreState(null, null), recordStore.getTimer());
// Index(MySimpleRecord$num_value_3_indexed [[5],>)
RecordQueryPlan plan = planner.plan(query);
assertThat(plan, indexScan(allOf(indexName("MySimpleRecord$num_value_3_indexed"), bounds(hasTupleString("[[5],>")))));
assertEquals(1008857208, plan.planHash(PlanHashable.PlanHashKind.LEGACY));
assertEquals(-2059042342, plan.planHash(PlanHashable.PlanHashKind.FOR_CONTINUATION));
assertEquals(-1347749581, plan.planHash(PlanHashable.PlanHashKind.STRUCTURAL_WITHOUT_LITERALS));
List<TestRecords1Proto.MySimpleRecord> results = recordStore.executeQuery(plan).map(rec -> TestRecords1Proto.MySimpleRecord.newBuilder().mergeFrom(rec.getRecord()).build()).asList().get();
assertEquals(1, results.size());
assertEquals(1066, results.get(0).getRecNo());
assertEquals(6, results.get(0).getNumValue3Indexed());
TestHelpers.assertDiscardedNone(context);
}
}
use of com.apple.foundationdb.record.RecordStoreState in project fdb-record-layer by FoundationDB.
the class QueryPlanMaxCardinalityTest method setup.
protected void setup(@Nullable RecordMetaDataHook hook) {
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
if (hook != null) {
hook.apply(builder);
}
metaData = builder.getRecordMetaData();
planner = new RecordQueryPlanner(metaData, new RecordStoreState(null, null));
}
use of com.apple.foundationdb.record.RecordStoreState in project fdb-record-layer by FoundationDB.
the class QueryPlanFullySortedTest method setup.
protected void setup(@Nullable RecordMetaDataHook hook) {
RecordMetaDataBuilder builder = RecordMetaData.newBuilder().setRecords(TestRecords1Proto.getDescriptor());
if (hook != null) {
hook.apply(builder);
}
metaData = builder.getRecordMetaData();
planner = useRewritePlanner ? new CascadesPlanner(metaData, new RecordStoreState(null, null)) : new RecordQueryPlanner(metaData, new RecordStoreState(null, null));
}
use of com.apple.foundationdb.record.RecordStoreState in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method getAllIndexStates.
/**
* Gets a map from {@link Index} to {@link IndexState} for all the indexes in the meta-data.
* This method will not perform any queries to the underlying database and instead satisfies the answer based on the
* in-memory cache of store state. However, if another operation in a different transaction
* happens concurrently that changes the index's state, operations using the same {@link FDBRecordContext}
* as this record store will fail to commit due to conflicts.
* @return a map of all the index states.
*/
@Nonnull
public Map<Index, IndexState> getAllIndexStates() {
final RecordStoreState localRecordStoreState = getRecordStoreState();
localRecordStoreState.beginRead();
try {
addStoreStateReadConflict();
return getRecordMetaData().getAllIndexes().stream().collect(Collectors.toMap(Function.identity(), localRecordStoreState::getState));
} finally {
localRecordStoreState.endRead();
}
}
use of com.apple.foundationdb.record.RecordStoreState in project fdb-record-layer by FoundationDB.
the class BoundRecordQuery method equals.
@Override
public boolean equals(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof BoundRecordQuery)) {
return false;
}
final BoundRecordQuery other = (BoundRecordQuery) o;
if (!getRecordQuery().equals(other.getRecordQuery())) {
return false;
}
if (!getParameters().equals(other.getParameters())) {
return false;
}
final RecordStoreState otherRecordStoreState = other.getRecordStoreState();
final RecordMetaDataProto.DataStoreInfo storeHeader = recordStoreState.getStoreHeader();
final RecordMetaDataProto.DataStoreInfo otherStoreHeader = otherRecordStoreState.getStoreHeader();
if (storeHeader.getMetaDataversion() != otherStoreHeader.getMetaDataversion()) {
return false;
}
if (storeHeader.getUserVersion() != otherStoreHeader.getUserVersion()) {
return false;
}
if (!this.recordStoreState.compatibleWith(otherRecordStoreState)) {
return false;
}
return parameterRelationshipGraph.equals(other.getParameterRelationshipGraph());
}
Aggregations