Search in sources :

Example 6 with RecordStoreState

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);
    }
}
Also used : RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) RecordQueryPlanner(com.apple.foundationdb.record.query.plan.RecordQueryPlanner) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) RecordStoreState(com.apple.foundationdb.record.RecordStoreState)

Example 7 with RecordStoreState

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));
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordQueryPlanner(com.apple.foundationdb.record.query.plan.RecordQueryPlanner) RecordStoreState(com.apple.foundationdb.record.RecordStoreState)

Example 8 with RecordStoreState

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));
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) RecordQueryPlanner(com.apple.foundationdb.record.query.plan.RecordQueryPlanner) RecordStoreState(com.apple.foundationdb.record.RecordStoreState) CascadesPlanner(com.apple.foundationdb.record.query.plan.temp.CascadesPlanner)

Example 9 with RecordStoreState

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();
    }
}
Also used : RecordStoreState(com.apple.foundationdb.record.RecordStoreState) MutableRecordStoreState(com.apple.foundationdb.record.MutableRecordStoreState) Nonnull(javax.annotation.Nonnull)

Example 10 with RecordStoreState

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());
}
Also used : RecordMetaDataProto(com.apple.foundationdb.record.RecordMetaDataProto) RecordStoreState(com.apple.foundationdb.record.RecordStoreState)

Aggregations

RecordStoreState (com.apple.foundationdb.record.RecordStoreState)10 RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)3 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)3 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)3 RecordQueryPlanner (com.apple.foundationdb.record.query.plan.RecordQueryPlanner)3 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)3 EvaluationContext (com.apple.foundationdb.record.EvaluationContext)2 IsolationLevel (com.apple.foundationdb.record.IsolationLevel)2 MutableRecordStoreState (com.apple.foundationdb.record.MutableRecordStoreState)2 RecordCursor (com.apple.foundationdb.record.RecordCursor)2 RecordCursorResult (com.apple.foundationdb.record.RecordCursorResult)2 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)2 TupleRange (com.apple.foundationdb.record.TupleRange)2 KeyValueLogMessage (com.apple.foundationdb.record.logging.KeyValueLogMessage)2 LogMessageKeys (com.apple.foundationdb.record.logging.LogMessageKeys)2 Index (com.apple.foundationdb.record.metadata.Index)2 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)2 FDBRecordStore (com.apple.foundationdb.record.provider.foundationdb.FDBRecordStore)2 FDBStoreTimer (com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer)2 Query (com.apple.foundationdb.record.query.expressions.Query)2