use of com.apple.foundationdb.annotation.SpotBugsSuppressWarnings in project fdb-record-layer by FoundationDB.
the class FDBRecordStore method updateSyntheticIndexes.
@API(API.Status.EXPERIMENTAL)
private <M extends Message> void updateSyntheticIndexes(@Nullable FDBStoredRecord<M> oldRecord, @Nullable FDBStoredRecord<M> newRecord, @Nonnull final List<CompletableFuture<Void>> futures) {
final SyntheticRecordPlanner planner = new SyntheticRecordPlanner(this);
// Index maintainers are not required to be thread-safe, so only do one synthetic record at a time.
final int pipelineSize = 1;
if (oldRecord != null && newRecord != null && oldRecord.getRecordType() == newRecord.getRecordType()) {
// TODO: An important optimization here is determining that no field used in the join condition or
// indexed in the synthetic record is changed, in which case all this can be skipped.
final SyntheticRecordFromStoredRecordPlan plan = planner.fromStoredType(newRecord.getRecordType(), true);
if (plan == null) {
return;
}
final Map<RecordType, Collection<IndexMaintainer>> maintainers = getSyntheticMaintainers(plan.getSyntheticRecordTypes());
final Map<Tuple, FDBSyntheticRecord> oldRecords = new ConcurrentHashMap<>();
CompletableFuture<Void> future = plan.execute(this, oldRecord).forEach(syntheticRecord -> oldRecords.put(syntheticRecord.getPrimaryKey(), syntheticRecord));
// @SpotBugsSuppressWarnings("NP_PARAMETER_MUST_BE_NONNULL_BUT_MARKED_AS_NULLABLE", justification = "https://github.com/spotbugs/spotbugs/issues/552")
@Nonnull final FDBStoredRecord<M> theNewRecord = newRecord;
future = future.thenCompose(v -> plan.execute(this, theNewRecord).forEachAsync(syntheticRecord -> runSyntheticMaintainers(maintainers, oldRecords.remove(syntheticRecord.getPrimaryKey()), syntheticRecord), pipelineSize));
future = future.thenCompose(v -> {
// Any synthetic record that was generated by the plan on the old record but not by the plan on the new record needs to be removed from its indexes.
final List<CompletableFuture<Void>> subFutures = new ArrayList<>();
for (FDBSyntheticRecord oldSyntheticRecord : oldRecords.values()) {
CompletableFuture<Void> subFuture = runSyntheticMaintainers(maintainers, oldSyntheticRecord, null);
if (!MoreAsyncUtil.isCompletedNormally(subFuture)) {
subFutures.add(subFuture);
}
}
if (subFutures.isEmpty()) {
return AsyncUtil.DONE;
} else if (subFutures.size() == 1) {
return subFutures.get(0);
} else {
return AsyncUtil.whenAll(subFutures);
}
});
futures.add(future);
} else {
if (oldRecord != null) {
final SyntheticRecordFromStoredRecordPlan plan = planner.fromStoredType(oldRecord.getRecordType(), true);
if (plan != null) {
final Map<RecordType, Collection<IndexMaintainer>> maintainers = getSyntheticMaintainers(plan.getSyntheticRecordTypes());
futures.add(plan.execute(this, oldRecord).forEachAsync(syntheticRecord -> runSyntheticMaintainers(maintainers, syntheticRecord, null), pipelineSize));
}
}
if (newRecord != null) {
final SyntheticRecordFromStoredRecordPlan plan = planner.fromStoredType(newRecord.getRecordType(), true);
if (plan != null) {
final Map<RecordType, Collection<IndexMaintainer>> maintainers = getSyntheticMaintainers(plan.getSyntheticRecordTypes());
futures.add(plan.execute(this, newRecord).forEachAsync(syntheticRecord -> runSyntheticMaintainers(maintainers, null, syntheticRecord), pipelineSize));
}
}
}
}
use of com.apple.foundationdb.annotation.SpotBugsSuppressWarnings in project fdb-record-layer by FoundationDB.
the class DynamicMessageRecordSerializer method deserialize.
@Nonnull
@Override
@SpotBugsSuppressWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE")
public Message deserialize(@Nonnull final RecordMetaData metaData, @Nonnull final Tuple primaryKey, @Nonnull final byte[] serialized, @Nullable StoreTimer timer) {
final long startTime = System.nanoTime();
try {
final Descriptors.Descriptor unionDescriptor = metaData.getUnionDescriptor();
final DynamicMessage unionMessage = deserializeUnion(unionDescriptor, primaryKey, serialized, metaData.getVersion());
return getUnionField(unionMessage, primaryKey).getRight();
} finally {
if (timer != null) {
timer.recordSinceNanoTime(Events.DESERIALIZE_PROTOBUF_RECORD, startTime);
}
}
}
use of com.apple.foundationdb.annotation.SpotBugsSuppressWarnings in project fdb-record-layer by FoundationDB.
the class Comparisons method compareStartsWith.
@Nullable
@SpotBugsSuppressWarnings("NP_BOOLEAN_RETURN_NULL")
private static Boolean compareStartsWith(@Nullable Object value, @Nullable Object comparand) {
if (value == null || comparand == null) {
return null;
} else if (comparand instanceof String) {
return ((String) value).startsWith((String) comparand);
} else if ((comparand instanceof ByteString) || (comparand instanceof byte[])) {
final byte[] bcomp = (comparand instanceof byte[]) ? (byte[]) comparand : ((ByteString) comparand).toByteArray();
final byte[] bval = (value instanceof byte[]) ? (byte[]) value : ((ByteString) value).toByteArray();
return ((bval.length >= bcomp.length) && Arrays.equals(Arrays.copyOfRange(bval, 0, bcomp.length), bcomp));
} else if (comparand instanceof List<?>) {
return compareListStartsWith(value, (List<?>) comparand);
} else {
throw new RecordCoreException("Illegal comparand value type: " + comparand);
}
}
Aggregations