Search in sources :

Example 16 with RecordCoreArgumentException

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

the class ComposedBitmapIndexCursor method create.

@Nonnull
public static ComposedBitmapIndexCursor create(@Nonnull List<Function<byte[], RecordCursor<IndexEntry>>> cursorFunctions, @Nonnull Composer composer, @Nullable byte[] byteContinuation, @Nullable FDBStoreTimer timer) {
    if (cursorFunctions.size() < 2) {
        throw new RecordCoreArgumentException("not enough child cursors provided to ComposedBitmapIndexCursor").addLogInfo(LogMessageKeys.CHILD_COUNT, cursorFunctions.size());
    }
    final List<MergeCursorState<IndexEntry>> cursorStates = new ArrayList<>(cursorFunctions.size());
    final ComposedBitmapIndexContinuation continuation = ComposedBitmapIndexContinuation.from(byteContinuation, cursorFunctions.size());
    int i = 0;
    for (Function<byte[], RecordCursor<IndexEntry>> cursorFunction : cursorFunctions) {
        cursorStates.add(MergeCursorState.from(cursorFunction, continuation.getContinuation(i)));
        i++;
    }
    return new ComposedBitmapIndexCursor(cursorStates, timer, composer);
}
Also used : MergeCursorState(com.apple.foundationdb.record.provider.foundationdb.cursors.MergeCursorState) RecordCursor(com.apple.foundationdb.record.RecordCursor) ArrayList(java.util.ArrayList) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Nonnull(javax.annotation.Nonnull)

Example 17 with RecordCoreArgumentException

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

the class SplitHelper method saveWithSplit.

/**
 * Save serialized representation using multiple keys if necessary, clearing only as much as needed.
 * @param context write transaction
 * @param subspace subspace to save in
 * @param key key within subspace
 * @param serialized serialized representation
 * @param version the version to store inline with this record
 * @param splitLongRecords <code>true</code> if multiple keys should be used; if <code>false</code>, <code>serialized</code> must fit in a single key
 * @param omitUnsplitSuffix if <code>splitLongRecords</code> is <code>false</code>, then this will omit a suffix added to the end of the key if <code>true</code> for backwards-compatibility reasons
 * @param clearBasedOnPreviousSizeInfo if <code>splitLongRecords</code>, whether to use <code>previousSizeInfo</code> to determine how much to clear
 * @param previousSizeInfo if <code>clearBasedOnPreviousSizeInfo</code>, the {@link FDBStoredSizes} for any old record, or <code>null</code> if there was no old record
 * @param sizeInfo optional size information to populate
 */
public static void saveWithSplit(@Nonnull final FDBRecordContext context, @Nonnull final Subspace subspace, @Nonnull final Tuple key, @Nonnull final byte[] serialized, @Nullable final FDBRecordVersion version, final boolean splitLongRecords, final boolean omitUnsplitSuffix, final boolean clearBasedOnPreviousSizeInfo, @Nullable final FDBStoredSizes previousSizeInfo, @Nullable SizeInfo sizeInfo) {
    if (omitUnsplitSuffix && version != null) {
        throw new RecordCoreArgumentException("Cannot include version in-line using old unsplit record format").addLogInfo(LogMessageKeys.KEY_TUPLE, key).addLogInfo(LogMessageKeys.SUBSPACE, ByteArrayUtil2.loggable(subspace.pack())).addLogInfo(LogMessageKeys.VERSION, version);
    }
    final Transaction tr = context.ensureActive();
    if (serialized.length > SplitHelper.SPLIT_RECORD_SIZE) {
        if (!splitLongRecords) {
            throw new RecordCoreException("Record is too long to be stored in a single value; consider split_long_records").addLogInfo(LogMessageKeys.KEY_TUPLE, key).addLogInfo(LogMessageKeys.SUBSPACE, ByteArrayUtil2.loggable(subspace.pack())).addLogInfo(LogMessageKeys.VALUE_SIZE, serialized.length);
        }
        writeSplitRecord(context, subspace, key, serialized, clearBasedOnPreviousSizeInfo, previousSizeInfo, sizeInfo);
    } else {
        if (splitLongRecords || previousSizeInfo == null || previousSizeInfo.isVersionedInline()) {
            clearPreviousSplitRecord(context, subspace, key, clearBasedOnPreviousSizeInfo, previousSizeInfo);
        }
        final Tuple recordKey;
        if (splitLongRecords || !omitUnsplitSuffix) {
            recordKey = key.add(SplitHelper.UNSPLIT_RECORD);
        } else {
            recordKey = key;
        }
        final byte[] keyBytes = subspace.pack(recordKey);
        tr.set(keyBytes, serialized);
        if (sizeInfo != null) {
            sizeInfo.set(keyBytes, serialized);
            sizeInfo.setSplit(false);
        }
    }
    writeVersion(context, subspace, key, version, sizeInfo);
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) Transaction(com.apple.foundationdb.Transaction) ReadTransaction(com.apple.foundationdb.ReadTransaction) RecordCoreArgumentException(com.apple.foundationdb.record.RecordCoreArgumentException) Tuple(com.apple.foundationdb.tuple.Tuple)

Aggregations

RecordCoreArgumentException (com.apple.foundationdb.record.RecordCoreArgumentException)17 Nonnull (javax.annotation.Nonnull)11 RecordCoreException (com.apple.foundationdb.record.RecordCoreException)4 ComponentWithComparison (com.apple.foundationdb.record.query.expressions.ComponentWithComparison)3 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)3 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)3 Tuple (com.apple.foundationdb.tuple.Tuple)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordCursor (com.apple.foundationdb.record.RecordCursor)2 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)2 Subspace (com.apple.foundationdb.subspace.Subspace)2 KeyValue (com.apple.foundationdb.KeyValue)1 ReadTransaction (com.apple.foundationdb.ReadTransaction)1 Transaction (com.apple.foundationdb.Transaction)1 API (com.apple.foundationdb.annotation.API)1 EndpointType (com.apple.foundationdb.record.EndpointType)1 KeyRange (com.apple.foundationdb.record.KeyRange)1 TupleRange (com.apple.foundationdb.record.TupleRange)1 CompletionExceptionLogHelper (com.apple.foundationdb.record.logging.CompletionExceptionLogHelper)1