本文整理了Java中com.apple.foundationdb.KeyValue.getKey()
方法的一些代码示例,展示了KeyValue.getKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。KeyValue.getKey()
方法的具体详情如下:
包路径:com.apple.foundationdb.KeyValue
类名称:KeyValue
方法名:getKey
暂无
代码示例来源:origin: FoundationDB/fdb-record-layer
public void set(@Nonnull final KeyValue keyValue) {
set(keyValue.getKey(), keyValue.getValue());
}
代码示例来源:origin: FoundationDB/fdb-record-layer
public void countKeyValue(@Nonnull final FDBStoreTimer.Count key,
@Nonnull final FDBStoreTimer.Count keyBytes,
@Nonnull final FDBStoreTimer.Count valueBytes,
@Nonnull final byte[] k, @Nonnull final byte[] v) {
final FDBStoreTimer timer = getTimer();
if (timer != null) {
timer.increment(key);
timer.increment(keyBytes, k.length);
timer.increment(valueBytes, v.length);
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
public void add(@Nonnull final KeyValue keyValue) {
add(keyValue.getKey(), keyValue.getValue());
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private void insertAfter(@Nonnull Transaction tr, @Nonnull byte[] subspaceKey, @Nonnull byte[] keyBytes,
@Nullable KeyValue kvAfter, @Nonnull Map.Entry<K,V> entry) {
if (kvAfter == null) {
insertAlone(tr, keyBytes, entry);
} else {
K afterKey = serializer.deserializeKey(kvAfter.getKey(), subspaceKey.length);
List<Map.Entry<K, V>> afterEntryList = serializer.deserializeEntries(afterKey, kvAfter.getValue());
if (afterEntryList.size() >= bunchSize) {
// The next list of entries is too large. Write to a separate KV pair.
insertAlone(tr, keyBytes, entry);
} else {
// Bunch this entry with the next one.
List<Map.Entry<K,V>> newEntryList = new ArrayList<>(afterEntryList.size() + 1);
newEntryList.add(entry);
newEntryList.addAll(afterEntryList);
writeEntryList(tr, subspaceKey, keyBytes, kvAfter.getKey(), keyBytes, newEntryList, null, true, false);
}
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private CompletableFuture<AllocationWindow> initialWindow() {
return currentCounter().thenApply(counter ->
counter.map(kv -> AllocationWindow.startingFrom(counterSubspace.unpack(kv.getKey()).getLong(0)))
.orElse(AllocationWindow.startingFrom(0))
);
}
代码示例来源:origin: FoundationDB/fdb-record-layer
public static Tuple unpackKey(@Nonnull Subspace subspace, @Nonnull KeyValue kv) {
try {
return subspace.unpack(kv.getKey());
} catch (IllegalArgumentException e) {
throw new RecordCoreArgumentException("unable to unpack key", e)
.addLogInfo(LogMessageKeys.KEY, ByteArrayUtil2.loggable(kv.getKey()))
.addLogInfo(LogMessageKeys.SUBSPACE, ByteArrayUtil2.loggable(subspace.getKey()));
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
protected String toDebugString(ReadTransactionContext tc) {
return tc.read(tr -> {
StringBuilder str = new StringBuilder();
for (int level = 0; level < nlevels; ++level) {
if (level > 0) {
str.setLength(str.length() - 2);
str.append("\n");
}
str.append("L").append(level).append(": ");
for (KeyValue kv : tr.getRange(subspace.range(Tuple.from(level)))) {
byte[] key = subspace.unpack(kv.getKey()).getBytes(1);
long count = decodeLong(kv.getValue());
str.append("'").append(ByteArrayUtil2.loggable(key)).append("': ").append(count).append(", ");
}
}
return str.toString();
});
}
代码示例来源:origin: FoundationDB/fdb-record-layer
@Nonnull
public CompletableFuture<String> rep(@Nonnull ReadTransactionContext tc) {
return tc.readAsync(tr -> {
StringBuilder sb = new StringBuilder();
AsyncIterable<KeyValue> iterable = tr.getRange(subspace.range());
return iterable.asList().thenApply((List<KeyValue> list) -> {
for (KeyValue kv : list) {
byte[] key = subspace.unpack(kv.getKey()).getBytes(0);
byte[] value = kv.getValue();
sb.append(ByteArrayUtil.printable(key));
sb.append(" -> ");
sb.append(ByteArrayUtil.printable(value));
sb.append('\n');
}
return sb.toString();
});
});
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private Long extractKey(Subspace allocationSubspace, KeyValue kv) {
return allocationSubspace.unpack(kv.getKey()).getLong(0);
}
代码示例来源:origin: FoundationDB/fdb-record-layer
protected boolean append(@Nonnull RecordCursorResult<KeyValue> resultWithKv) {
KeyValue kv = resultWithKv.get();
if (nextPrefix == null) {
continuation = resultWithKv.getContinuation();
return appendFirst(kv);
} else if (ByteArrayUtil.startsWith(kv.getKey(), nextPrefix)) {
continuation = resultWithKv.getContinuation();
return appendNext(kv);
} else {
if (reverse && nextIndex != UNSPLIT_RECORD && nextIndex != START_SPLIT_RECORD && nextIndex != RECORD_VERSION) {
throw new FoundSplitWithoutStartException(nextIndex, true);
}
pending = resultWithKv;
return true;
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
@Nonnull
private List<Pair<Tuple, Integer>> scanTokenizerVersions(@Nonnull FDBRecordStore store, @Nonnull Index index) throws ExecutionException, InterruptedException {
final Subspace tokenizerVersionSubspace = store.indexSecondarySubspace(index).subspace(TextIndexMaintainer.TOKENIZER_VERSION_SUBSPACE_TUPLE);
return recordStore.ensureContextActive().getRange(tokenizerVersionSubspace.range()).asList().get().stream()
.map(kv -> Pair.of(tokenizerVersionSubspace.unpack(kv.getKey()), (int)Tuple.fromBytes(kv.getValue()).getLong(0)))
.collect(Collectors.toList());
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private void verifyBoundaryKeys(@Nonnull List<Tuple> boundaryKeys) throws ExecutionException, InterruptedException {
try (Transaction tr = db.createTransaction()) {
map.verifyIntegrity(tr, bmSubspace).get();
List<KeyValue> rangeKVs = tr.getRange(bmSubspace.range()).asList().get();
List<Tuple> actualBoundaryKeys = rangeKVs.stream()
.map(KeyValue::getKey)
.map(bmSubspace::unpack)
.collect(Collectors.toList());
List<Map.Entry<Tuple,Tuple>> entryList = rangeKVs.stream()
.flatMap(kv -> serializer.deserializeEntries(bmSubspace.unpack(kv.getKey()), kv.getValue()).stream())
.collect(Collectors.toList());
System.out.println(entryList);
assertEquals(boundaryKeys, actualBoundaryKeys);
tr.cancel();
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
@Test
public void insertSingleKey() {
List<Tuple> testTuples = Stream.of(1066L, 1776L, 1415L, 800L).map(Tuple::from).collect(Collectors.toList());
Tuple value = Tuple.from(1415L);
db.run(tr -> {
Tuple minSoFar = null;
for (int i = 0; i < testTuples.size(); i++) {
Tuple key = testTuples.get(i);
minSoFar = (minSoFar == null || key.compareTo(minSoFar) < 0) ? key : minSoFar;
map.put(tr, bmSubspace, key, value).join();
for (int j = 0; j < testTuples.size(); j++) {
assertEquals(j <= i, map.containsKey(tr, bmSubspace, testTuples.get(j)).join());
}
List<KeyValue> rangeKVs = tr.getRange(bmSubspace.range()).asList().join();
assertEquals(1, rangeKVs.size());
assertArrayEquals(bmSubspace.pack(minSoFar), rangeKVs.get(0).getKey());
List<Map.Entry<Tuple,Tuple>> entryList = testTuples.subList(0, i + 1).stream()
.sorted()
.map(t -> new AbstractMap.SimpleImmutableEntry<>(t, value))
.collect(Collectors.toList());
assertArrayEquals(serializer.serializeEntries(entryList), rangeKVs.get(0).getValue());
}
return null;
});
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private CompletableFuture<byte[]> computeInternal(@Nonnull FDBRecordContext context,
@Nullable byte[] continuation,
@Nonnull MessageDigest messageDigest) {
final RecordCursor<KeyValue> cursor = KeyValueCursor.Builder.withSubspace(mappingSubspace)
.setScanProperties(new ScanProperties(ExecuteProperties.newBuilder().setReturnedRowLimit(transactionRowLimit).setIsolationLevel(IsolationLevel.SNAPSHOT).build()))
.setContext(context)
.setContinuation(continuation)
.build();
return AsyncUtil.whileTrue(() ->
cursor.onHasNext().thenApply(hasNext -> {
if (hasNext) {
KeyValue kv = cursor.next();
String key = mappingSubspace.unpack(kv.getKey()).getString(0);
ResolverResult value = resolver.deserializeValue(kv.getValue());
messageDigest.update(Tuple.from(key, value.getValue(), value.getMetadata()).pack());
}
return hasNext;
}), context.getExecutor()
).thenApply(ignore -> cursor.getContinuation());
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
public AsyncIterable<byte[]> getRange(ReadTransaction tr, byte[] beginKey, byte[] endKey) {
checkKey(beginKey);
return AsyncUtil.mapIterable(tr.getRange(subspace.pack(Tuple.from(0, beginKey)),
subspace.pack(Tuple.from(0, endKey))),
keyValue -> {
Tuple t = subspace.unpack(keyValue.getKey());
return t.getBytes(1);
});
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private CompletableFuture<byte[]> getPreviousKey(TransactionContext tc, int level, byte[] key) {
byte[] k = subspace.pack(Tuple.from(level, key));
CompletableFuture<byte[]> kf = tc.run(tr ->
tr.snapshot()
.getRange(KeySelector.lastLessThan(k), KeySelector.firstGreaterOrEqual(k), 1)
.asList()
.thenApply(kvs -> {
byte[] prevk = kvs.get(0).getKey();
// If another key were inserted after between this and the target key,
// it wouldn't be the one we should increment any more.
// But do not conflict when key itself is incremented.
byte[] exclusiveBegin = ByteArrayUtil.join(prevk, ZERO_ARRAY);
tr.addReadConflictRange(exclusiveBegin, k);
// Do conflict if key is removed entirely.
tr.addReadConflictKey(subspace.pack(Tuple.from(0, subspace.unpack(prevk).getBytes(1))));
return prevk;
}));
return kf.thenApply(prevk -> subspace.unpack(prevk).getBytes(1));
}
代码示例来源:origin: FoundationDB/fdb-record-layer
@Nonnull
private void addConvertRecordVersions(@Nonnull List<CompletableFuture<Void>> work) {
if (useOldVersionFormat()) {
throw new RecordCoreException("attempted to convert record versions when still using older format");
}
final Subspace legacyVersionSubspace = getSubspace().subspace(Tuple.from(RECORD_VERSION_KEY));
// Read all of the keys in the old record version location. For each
// record, copy its version to the new location within the primary record
// subspace. Then once they are all copied, delete the old subspace.
KeyValueCursor kvCursor = KeyValueCursor.Builder.withSubspace(legacyVersionSubspace)
.setContext(getRecordContext())
.setScanProperties(ScanProperties.FORWARD_SCAN)
.build();
CompletableFuture<Void> workFuture = kvCursor.forEach(kv -> {
final Tuple primaryKey = legacyVersionSubspace.unpack(kv.getKey());
final FDBRecordVersion version = FDBRecordVersion.fromBytes(kv.getValue(), false);
final byte[] newKeyBytes = getSubspace().pack(recordVersionKey(primaryKey));
final byte[] newValueBytes = SplitHelper.packVersion(version);
ensureContextActive().set(newKeyBytes, newValueBytes);
}).thenAccept(ignore -> ensureContextActive().clear(legacyVersionSubspace.range()));
work.add(workFuture);
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private <M extends Message> void validateUsingOlderVersionFormat(@Nonnull List<FDBStoredRecord<M>> storedRecords) {
// Make sure all of the records have versions in the old keyspace
final Subspace legacyVersionSubspace = recordStore.getSubspace().subspace(Tuple.from(FDBRecordStore.RECORD_VERSION_KEY));
RecordCursor<Pair<Tuple, FDBRecordVersion>> versionKeyPairs = KeyValueCursor.Builder.withSubspace(legacyVersionSubspace)
.setContext(recordStore.getRecordContext())
.setScanProperties(ScanProperties.FORWARD_SCAN)
.build()
.map(kv -> Pair.of(legacyVersionSubspace.unpack(kv.getKey()), FDBRecordVersion.fromBytes(kv.getValue())));
for (FDBStoredRecord<M> storedRecord : storedRecords) {
assertThat(versionKeyPairs.hasNext(), is(true));
Pair<Tuple, FDBRecordVersion> versionPair = versionKeyPairs.next();
assertEquals(storedRecord.getPrimaryKey(), versionPair.getLeft());
assertEquals(storedRecord.getVersion(), versionPair.getRight());
}
assertThat(versionKeyPairs.hasNext(), is(false));
// Validate that no value in the record subspace begins with the type code for versionstamps
final Subspace recordsSubspace = recordStore.recordsSubspace();
KeyValueCursor.Builder.withSubspace(recordsSubspace)
.setContext(recordStore.getRecordContext())
.setScanProperties(ScanProperties.FORWARD_SCAN)
.build()
.forEach(kv -> assertNotEquals(kv.getValue()[0], VERSIONSTAMP_CODE))
.join();
}
代码示例来源:origin: FoundationDB/fdb-record-layer
private void checkIncreasing() {
List<KeyValue> kvs = db.readAsync(tr -> tr.getRange(rsSubspace.range()).asList()).join();
byte[] last = null;
for (KeyValue kv : kvs) {
byte[] key = rsSubspace.unpack(kv.getKey()).getBytes(0);
assertTrue(compareUnsigned(key, kv.getValue()) < 0, "Key " + printable(key) + " is not less than value " + printable(kv.getValue()));
if (last != null) {
assertTrue(compareUnsigned(last, key) <= 0, "Last value " + printable(last) + " is after key " + printable(key));
}
last = kv.getValue();
}
}
代码示例来源:origin: FoundationDB/fdb-record-layer
@Test
public void inclusiveNull() {
fdb.run(context -> {
KeyValueCursor cursor = KeyValueCursor.Builder.withSubspace(subspace)
.setContext(context)
.setLow(Tuple.from(4), EndpointType.RANGE_INCLUSIVE)
.setHigh((Tuple) null, EndpointType.RANGE_INCLUSIVE)
.setContinuation(null)
.setScanProperties(ScanProperties.FORWARD_SCAN)
.build();
for (int j = 0; j < 5; j++) {
KeyValue kv = cursor.next();
assertArrayEquals(subspace.pack(Tuple.from(4, j)), kv.getKey());
assertArrayEquals(Tuple.from(4, j).pack(), kv.getValue());
}
assertThat(cursor.hasNext(), is(false));
return null;
});
}
内容来源于网络,如有侵权,请联系作者删除!