Search in sources :

Example 61 with Transaction

use of com.apple.foundationdb.Transaction in project fdb-record-layer by FoundationDB.

the class BunchedMapTest method concurrentLegalUpdates.

@Test
public void concurrentLegalUpdates() throws ExecutionException, InterruptedException {
    final Tuple value = Tuple.from((Object) null);
    // From initial database, essentially any two updates will cause each one
    // to get its own key.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(1066L), value).join();
        map.put(tr2, bmSubspace, Tuple.from(1415L), value).join();
    }, true, Arrays.asList(Tuple.from(1066L), Tuple.from(1415L)));
    try (Transaction tr = db.createTransaction()) {
        tr.clear(bmSubspace.range());
        tr.commit().get();
    }
    final List<Tuple> tuples = LongStream.range(100L, 115L).boxed().map(Tuple::from).collect(Collectors.toList());
    db.run(tr -> {
        tuples.forEach(t -> map.put(tr, bmSubspace, t, value).join());
        return null;
    });
    // Case 1: Transaction reads the same key as another, but it
    // doesn't actually need the part that is different.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(116L), value).join();
        assertEquals(value, map.get(tr2, bmSubspace, Tuple.from(112L)).join().get());
    }, true, Arrays.asList(Tuple.from(100L), Tuple.from(110L)));
    // Case 2: Transaction reads the same key in a way while
    // another transaction writes the same value into the key.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(105L), value).join();
        assertEquals(value, map.get(tr2, bmSubspace, Tuple.from(105L)).join().get());
    }, true, Arrays.asList(Tuple.from(100L), Tuple.from(110L)));
    // Case 3: Transaction ranges read will overlap
    runWithTwoTrs((tr1, tr2) -> {
        // As the first one is full, the logic chooses to put (109L, null)
        // as the first key of the second set of things.
        map.put(tr1, bmSubspace, Tuple.from(109L, null), value).join();
        // As the split is in the middle, it will choose to put
        // (107L, null) in the first group of transactions.
        map.put(tr2, bmSubspace, Tuple.from(107L, null), value).join();
    }, true, Arrays.asList(Tuple.from(100L), Tuple.from(105L), Tuple.from(109L, null)));
    try (Transaction tr = db.createTransaction()) {
        map.verifyIntegrity(tr, bmSubspace).get();
        // Fill up the (100L,) to (105L,) range.
        LongStream.range(0L, 5L).boxed().map(l -> Tuple.from(104L, l)).forEach(t -> map.put(tr, bmSubspace, t, value).join());
        tr.commit().get();
    }
    // Case 4: Read a value that is rewritten to the same value when appending
    // to the beginning.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(104L, 100L), value).join();
        assertEquals(value, map.get(tr2, bmSubspace, Tuple.from(107L)).join().get());
    }, true, Arrays.asList(Tuple.from(100L), Tuple.from(104L, 100L), Tuple.from(109L, null)));
    try (Transaction tr = db.createTransaction()) {
        // Fill up (104L, 100L) to (109, null).
        LongStream.range(101L, 104L).boxed().map(l -> Tuple.from(104L, l)).forEach(t -> map.put(tr, bmSubspace, t, value).join());
        tr.commit().get();
    }
    // Case 5: Two things going in the middle of two filled ranges.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(104L, 42L), value).join();
        map.put(tr2, bmSubspace, Tuple.from(104L, 43L), value).join();
    }, true, Arrays.asList(Tuple.from(100L), Tuple.from(104L, 42L), Tuple.from(104L, 43L), Tuple.from(104L, 100L), Tuple.from(109L, null)));
    // Case 6: Two keys before all filled ranges.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(42L), value).join();
        map.put(tr2, bmSubspace, Tuple.from(43L), value).join();
    }, true, Arrays.asList(Tuple.from(42L), Tuple.from(43L), Tuple.from(100L), Tuple.from(104L, 42L), Tuple.from(104L, 43L), Tuple.from(104L, 100L), Tuple.from(109L, null)));
    try (Transaction tr = db.createTransaction()) {
        // Fill up the last range.
        LongStream.range(117L, 120L).boxed().map(Tuple::from).forEach(t -> map.put(tr, bmSubspace, t, value).join());
        tr.commit().get();
    }
    // Case 7: Two keys after filled ranges.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(120L), value).join();
        map.put(tr2, bmSubspace, Tuple.from(121L), value).join();
    }, true, Arrays.asList(Tuple.from(42L), Tuple.from(43L), Tuple.from(100L), Tuple.from(104L, 42L), Tuple.from(104L, 43L), Tuple.from(104L, 100L), Tuple.from(109L, null), Tuple.from(120L), Tuple.from(121L)));
    // Case 8: Adding to a full range while simultaneously adding something after the range.
    runWithTwoTrs((tr1, tr2) -> {
        map.put(tr1, bmSubspace, Tuple.from(102L, 0L), value).join();
        map.put(tr2, bmSubspace, Tuple.from(104L, 41L), value).join();
    }, true, Arrays.asList(Tuple.from(42L), Tuple.from(43L), Tuple.from(100L), Tuple.from(104L), Tuple.from(104L, 41L), Tuple.from(104L, 43L), Tuple.from(104L, 100L), Tuple.from(109L, null), Tuple.from(120L), Tuple.from(121L)));
    // Compact the data to a minimal number of keys.
    try (Transaction tr = db.createTransaction()) {
        assertNull(map.compact(tr, bmSubspace, 0, null).get());
        map.verifyIntegrity(tr, bmSubspace).get();
        tr.commit().get();
    }
    verifyBoundaryKeys(Arrays.asList(Tuple.from(42L), Tuple.from(104L, 2L), Tuple.from(105L), Tuple.from(113L)));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) FDB(com.apple.foundationdb.FDB) Arrays(java.util.Arrays) FDBTestBase(com.apple.foundationdb.FDBTestBase) Random(java.util.Random) Disabled(org.junit.jupiter.api.Disabled) Subspace(com.apple.foundationdb.subspace.Subspace) MutationType(com.apple.foundationdb.MutationType) AfterAll(org.junit.jupiter.api.AfterAll) Transaction(com.apple.foundationdb.Transaction) Tuple(com.apple.foundationdb.tuple.Tuple) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) FDBError(com.apple.foundationdb.FDBError) BeforeAll(org.junit.jupiter.api.BeforeAll) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) Tag(org.junit.jupiter.api.Tag) ByteArrayUtil(com.apple.foundationdb.tuple.ByteArrayUtil) KeyValue(com.apple.foundationdb.KeyValue) DirectoryLayer(com.apple.foundationdb.directory.DirectoryLayer) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.fail(org.junit.jupiter.api.Assertions.fail) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) AsyncIterator(com.apple.foundationdb.async.AsyncIterator) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CompletableFuture(java.util.concurrent.CompletableFuture) Database(com.apple.foundationdb.Database) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) LoggableException(com.apple.foundationdb.util.LoggableException) BiConsumer(java.util.function.BiConsumer) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) LongStream(java.util.stream.LongStream) Versionstamp(com.apple.foundationdb.tuple.Versionstamp) Tags(com.apple.test.Tags) ExecutionException(java.util.concurrent.ExecutionException) Assertions.assertArrayEquals(org.junit.jupiter.api.Assertions.assertArrayEquals) AtomicLong(java.util.concurrent.atomic.AtomicLong) AbstractMap(java.util.AbstractMap) PathUtil(com.apple.foundationdb.directory.PathUtil) TreeMap(java.util.TreeMap) FDBException(com.apple.foundationdb.FDBException) KeySelector(com.apple.foundationdb.KeySelector) Comparator(java.util.Comparator) Collections(java.util.Collections) Transaction(com.apple.foundationdb.Transaction) Tuple(com.apple.foundationdb.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Example 62 with Transaction

use of com.apple.foundationdb.Transaction in project fdb-record-layer by FoundationDB.

the class FDBRecordStore method repairRecordKeyIfNecessary.

private void repairRecordKeyIfNecessary(@Nonnull FDBRecordContext context, @Nonnull Subspace recordSubspace, @Nonnull KeyValue keyValue, final boolean isDryRun) {
    final RecordMetaData metaData = metaDataProvider.getRecordMetaData();
    final Tuple recordKey = recordSubspace.unpack(keyValue.getKey());
    // Ignore version key
    if (metaData.isStoreRecordVersions() && isMaybeVersion(recordKey)) {
        return;
    }
    final Message protoRecord = serializer.deserialize(metaData, recordKey, keyValue.getValue(), getTimer());
    final RecordType recordType = metaData.getRecordTypeForDescriptor(protoRecord.getDescriptorForType());
    final KeyExpression primaryKeyExpression = recordType.getPrimaryKey();
    if (recordKey.size() == primaryKeyExpression.getColumnSize()) {
        context.increment(FDBStoreTimer.Counts.REPAIR_RECORD_KEY);
        final Tuple newPrimaryKey = recordKey.add(SplitHelper.UNSPLIT_RECORD);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(KeyValueLogMessage.of("Repairing primary key", LogMessageKeys.RECORD_TYPE, recordType.getName(), subspaceProvider.logKey(), subspaceProvider.toString(context), "dry_run", isDryRun, "orig_primary_key", recordKey, "new_primary_key", newPrimaryKey));
        }
        if (!isDryRun) {
            final Transaction tr = context.ensureActive();
            tr.clear(keyValue.getKey());
            tr.set(recordSubspace.pack(newPrimaryKey), keyValue.getValue());
        }
    } else if (recordKey.size() == primaryKeyExpression.getColumnSize() + 1) {
        Object suffix = recordKey.get(recordKey.size() - 1);
        if (!(suffix instanceof Long) || !(((Long) suffix) == SplitHelper.UNSPLIT_RECORD)) {
            context.increment(FDBStoreTimer.Counts.INVALID_SPLIT_SUFFIX);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug(KeyValueLogMessage.of("Invalid split suffix", subspaceProvider.logKey(), subspaceProvider.toString(context), LogMessageKeys.RECORD_TYPE, recordType.getName(), LogMessageKeys.PRIMARY_KEY, recordKey));
            }
        }
    } else {
        context.increment(FDBStoreTimer.Counts.INVALID_KEY_LENGTH);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug(KeyValueLogMessage.of("Invalid key length", subspaceProvider.logKey(), subspaceProvider.toString(context), LogMessageKeys.RECORD_TYPE, recordType.getName(), LogMessageKeys.PRIMARY_KEY, recordKey));
        }
    }
}
Also used : RecordMetaData(com.apple.foundationdb.record.RecordMetaData) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Message(com.google.protobuf.Message) SyntheticRecordType(com.apple.foundationdb.record.metadata.SyntheticRecordType) RecordType(com.apple.foundationdb.record.metadata.RecordType) Transaction(com.apple.foundationdb.Transaction) ReadTransaction(com.apple.foundationdb.ReadTransaction) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) EmptyKeyExpression(com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression) AtomicLong(java.util.concurrent.atomic.AtomicLong) Tuple(com.apple.foundationdb.tuple.Tuple)

Example 63 with Transaction

use of com.apple.foundationdb.Transaction in project fdb-record-layer by FoundationDB.

the class FDBReverseDirectoryCache method putToSubspace.

private CompletableFuture<Void> putToSubspace(@Nonnull FDBRecordContext context, @Nonnull Subspace reverseCacheSubspace, @Nonnull ScopedValue<String> scopedPathString, @Nonnull Long pathValue) {
    String pathString = scopedPathString.getData();
    Transaction transaction = context.ensureActive();
    return transaction.snapshot().get(reverseCacheSubspace.pack(pathValue)).thenApply(valueBytes -> {
        if (valueBytes != null) {
            String readValue = Tuple.fromBytes(valueBytes).getString(0);
            if (!readValue.equals(pathString)) {
                throw new RecordCoreException("Provided value for path key does not match existing value in reverse directory layer cache").addLogInfo(LogMessageKeys.RESOLVER, scopedPathString.getScope()).addLogInfo(LogMessageKeys.RESOLVER_PATH, pathString).addLogInfo(LogMessageKeys.RESOLVER_KEY, pathValue).addLogInfo(LogMessageKeys.CACHED_KEY, readValue);
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Put unnecessary, found path '" + readValue + "'' in reverse lookup for value '" + pathValue + "'");
            }
            persistentCacheHitCount.incrementAndGet();
            logStatsToStoreTimer(context, FDBStoreTimer.Counts.REVERSE_DIR_PERSISTENT_CACHE_HIT_COUNT);
        } else {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Adding '" + pathValue + "' to reverse lookup with key " + pathString);
            }
            // Take care NOT to place the value in our cache. We don't own the calling context/transaction
            // so it is possible it could fail/rollback leaving our cache inconsistent.
            transaction.set(reverseCacheSubspace.pack(pathValue), Tuple.from(pathString).pack());
            persistentCacheMissCount.incrementAndGet();
            logStatsToStoreTimer(context, FDBStoreTimer.Counts.REVERSE_DIR_PERSISTENT_CACHE_MISS_COUNT);
        }
        return null;
    });
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) Transaction(com.apple.foundationdb.Transaction)

Example 64 with Transaction

use of com.apple.foundationdb.Transaction in project fdb-record-layer by FoundationDB.

the class FDBRecordStore method uncheckedMarkIndexReadable.

/**
 * Marks the index with the given name as readable without checking to see if it is
 * ready. This is dangerous to do if one has not first verified that the
 * index is ready to be readable as it can cause half-built indexes to be
 * used within queries and can thus produce inconsistent results.
 * @param indexName the name of the index to mark readable
 * @return a future that will contain <code>true</code> if the store was modified
 * and <code>false</code> otherwise
 */
@Nonnull
public CompletableFuture<Boolean> uncheckedMarkIndexReadable(@Nonnull String indexName) {
    if (recordStoreStateRef.get() == null) {
        return preloadRecordStoreStateAsync().thenCompose(vignore -> uncheckedMarkIndexReadable(indexName));
    }
    addIndexStateReadConflict(indexName);
    beginRecordStoreStateWrite();
    boolean haveFuture = false;
    try {
        Transaction tr = ensureContextActive();
        byte[] indexKey = indexStateSubspace().pack(indexName);
        CompletableFuture<Boolean> future = tr.get(indexKey).thenApply(previous -> {
            if (previous != null) {
                updateIndexState(indexName, indexKey, IndexState.READABLE);
                return true;
            } else {
                return false;
            }
        }).whenComplete((b, t) -> endRecordStoreStateWrite()).thenApply(this::addRemoveReplacedIndexesCommitCheckIfChanged);
        haveFuture = true;
        return future;
    } finally {
        if (!haveFuture) {
            endRecordStoreStateWrite();
        }
    }
}
Also used : LogMessageKeys(com.apple.foundationdb.record.logging.LogMessageKeys) UnaryOperator(java.util.function.UnaryOperator) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) RecordSerializer(com.apple.foundationdb.record.provider.common.RecordSerializer) Subspace(com.apple.foundationdb.subspace.Subspace) MutationType(com.apple.foundationdb.MutationType) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) Map(java.util.Map) RecordIndexUniquenessViolation(com.apple.foundationdb.record.RecordIndexUniquenessViolation) QueryToKeyMatcher(com.apple.foundationdb.record.query.QueryToKeyMatcher) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Query(com.apple.foundationdb.record.query.expressions.Query) KeyExpression(com.apple.foundationdb.record.metadata.expressions.KeyExpression) Set(java.util.Set) TupleRange(com.apple.foundationdb.record.TupleRange) KeySpacePath(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpacePath) ByteOrder(java.nio.ByteOrder) SyntheticRecordType(com.apple.foundationdb.record.metadata.SyntheticRecordType) RecordMetaDataProvider(com.apple.foundationdb.record.RecordMetaDataProvider) RecordStoreState(com.apple.foundationdb.record.RecordStoreState) TupleHelpers(com.apple.foundationdb.tuple.TupleHelpers) API(com.apple.foundationdb.annotation.API) FunctionNames(com.apple.foundationdb.record.FunctionNames) RecordMetaData(com.apple.foundationdb.record.RecordMetaData) IndexAggregateFunction(com.apple.foundationdb.record.metadata.IndexAggregateFunction) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) RecordQuery(com.apple.foundationdb.record.query.RecordQuery) RangeSet(com.apple.foundationdb.async.RangeSet) RecordQueryPlan(com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan) Supplier(java.util.function.Supplier) FormerIndex(com.apple.foundationdb.record.metadata.FormerIndex) ArrayList(java.util.ArrayList) ByteScanLimiter(com.apple.foundationdb.record.ByteScanLimiter) ParameterRelationshipGraph(com.apple.foundationdb.record.query.ParameterRelationshipGraph) LoggableException(com.apple.foundationdb.util.LoggableException) CloseableAsyncIterator(com.apple.foundationdb.async.CloseableAsyncIterator) IndexRecordFunction(com.apple.foundationdb.record.metadata.IndexRecordFunction) Nullable(javax.annotation.Nullable) ByteArrayUtil2(com.apple.foundationdb.tuple.ByteArrayUtil2) IsolationLevel(com.apple.foundationdb.record.IsolationLevel) CursorLimitManager(com.apple.foundationdb.record.cursors.CursorLimitManager) ExecuteState(com.apple.foundationdb.record.ExecuteState) AtomicLong(java.util.concurrent.atomic.AtomicLong) RecordType(com.apple.foundationdb.record.metadata.RecordType) Index(com.apple.foundationdb.record.metadata.Index) DynamicMessageRecordSerializer(com.apple.foundationdb.record.provider.common.DynamicMessageRecordSerializer) SyntheticRecordPlanner(com.apple.foundationdb.record.query.plan.synthetic.SyntheticRecordPlanner) IndexEntry(com.apple.foundationdb.record.IndexEntry) LoggerFactory(org.slf4j.LoggerFactory) RecordCoreStorageException(com.apple.foundationdb.record.RecordCoreStorageException) ByteBuffer(java.nio.ByteBuffer) RecordQueryPlanner(com.apple.foundationdb.record.query.plan.RecordQueryPlanner) Transaction(com.apple.foundationdb.Transaction) Tuple(com.apple.foundationdb.tuple.Tuple) Range(com.apple.foundationdb.Range) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) PipelineOperation(com.apple.foundationdb.record.PipelineOperation) RecordMetaDataProto(com.apple.foundationdb.record.RecordMetaDataProto) ByteArrayUtil(com.apple.foundationdb.tuple.ByteArrayUtil) KeyValue(com.apple.foundationdb.KeyValue) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IndexQueryabilityFilter(com.apple.foundationdb.record.query.IndexQueryabilityFilter) AndComponent(com.apple.foundationdb.record.query.expressions.AndComponent) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Collectors(java.util.stream.Collectors) ByteString(com.google.protobuf.ByteString) List(java.util.List) EvaluationContext(com.apple.foundationdb.record.EvaluationContext) AggregateFunctionNotSupportedException(com.apple.foundationdb.record.AggregateFunctionNotSupportedException) RecordTypeKeyComparison(com.apple.foundationdb.record.query.expressions.RecordTypeKeyComparison) IndexTypes(com.apple.foundationdb.record.metadata.IndexTypes) Optional(java.util.Optional) MutableRecordStoreState(com.apple.foundationdb.record.MutableRecordStoreState) RecordTypeOrBuilder(com.apple.foundationdb.record.metadata.RecordTypeOrBuilder) SyntheticRecordFromStoredRecordPlan(com.apple.foundationdb.record.query.plan.synthetic.SyntheticRecordFromStoredRecordPlan) SpotBugsSuppressWarnings(com.apple.foundationdb.annotation.SpotBugsSuppressWarnings) Descriptors(com.google.protobuf.Descriptors) AsyncIterator(com.apple.foundationdb.async.AsyncIterator) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Function(java.util.function.Function) CursorStreamingMode(com.apple.foundationdb.record.CursorStreamingMode) Key(com.apple.foundationdb.record.metadata.Key) ExecuteProperties(com.apple.foundationdb.record.ExecuteProperties) EndpointType(com.apple.foundationdb.record.EndpointType) ScanProperties(com.apple.foundationdb.record.ScanProperties) Suppliers(com.google.common.base.Suppliers) LinkedList(java.util.LinkedList) Nonnull(javax.annotation.Nonnull) EmptyKeyExpression(com.apple.foundationdb.record.metadata.expressions.EmptyKeyExpression) MoreAsyncUtil(com.apple.foundationdb.async.MoreAsyncUtil) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) IndexState(com.apple.foundationdb.record.IndexState) StoreRecordFunction(com.apple.foundationdb.record.metadata.StoreRecordFunction) ReadTransaction(com.apple.foundationdb.ReadTransaction) AsyncIterable(com.apple.foundationdb.async.AsyncIterable) FDBRecordStoreStateCache(com.apple.foundationdb.record.provider.foundationdb.storestate.FDBRecordStoreStateCache) Message(com.google.protobuf.Message) RecordCursor(com.apple.foundationdb.record.RecordCursor) QueryComponent(com.apple.foundationdb.record.query.expressions.QueryComponent) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Collections(java.util.Collections) Transaction(com.apple.foundationdb.Transaction) ReadTransaction(com.apple.foundationdb.ReadTransaction) Nonnull(javax.annotation.Nonnull)

Example 65 with Transaction

use of com.apple.foundationdb.Transaction in project fdb-record-layer by FoundationDB.

the class FDBRecordStore method vacuumReadableIndexesBuildData.

public void vacuumReadableIndexesBuildData() {
    Transaction tr = ensureContextActive();
    // also adds state to read conflicts
    Map<Index, IndexState> indexStates = getAllIndexStates();
    for (Map.Entry<Index, IndexState> entry : indexStates.entrySet()) {
        if (entry.getValue().equals(IndexState.READABLE)) {
            clearReadableIndexBuildData(tr, entry.getKey());
        }
    }
}
Also used : Transaction(com.apple.foundationdb.Transaction) ReadTransaction(com.apple.foundationdb.ReadTransaction) FormerIndex(com.apple.foundationdb.record.metadata.FormerIndex) Index(com.apple.foundationdb.record.metadata.Index) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) IndexState(com.apple.foundationdb.record.IndexState)

Aggregations

Transaction (com.apple.foundationdb.Transaction)84 ReadTransaction (com.apple.foundationdb.ReadTransaction)34 Tuple (com.apple.foundationdb.tuple.Tuple)34 Test (org.junit.jupiter.api.Test)33 Nonnull (javax.annotation.Nonnull)28 ArrayList (java.util.ArrayList)26 List (java.util.List)26 CompletableFuture (java.util.concurrent.CompletableFuture)26 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)22 Subspace (com.apple.foundationdb.subspace.Subspace)21 Collectors (java.util.stream.Collectors)19 Nullable (javax.annotation.Nullable)19 KeyValue (com.apple.foundationdb.KeyValue)18 Map (java.util.Map)18 KeyValueLogMessage (com.apple.foundationdb.record.logging.KeyValueLogMessage)17 Range (com.apple.foundationdb.Range)16 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)16 AtomicReference (java.util.concurrent.atomic.AtomicReference)16 Collections (java.util.Collections)15 RecordCursor (com.apple.foundationdb.record.RecordCursor)14