public static StaticBuffer pointRange(StaticBuffer point) { return BufferUtil.nextBiggerBuffer(point); }
public static StaticBuffer nextBiggerBufferAllowOverflow(StaticBuffer buffer) { return nextBiggerBuffer(buffer, true); }
public static StaticBuffer nextBiggerBuffer(StaticBuffer buffer) { return nextBiggerBuffer(buffer,false); }
/** * Retrieves the value for the specified column and key under the given transaction * from the store if such exists, otherwise returns NULL * * @param store Store * @param key Key * @param column Column * @param txh Transaction * @return Value for key and column or NULL if such does not exist */ public static StaticBuffer get(KeyColumnValueStore store, StaticBuffer key, StaticBuffer column, StoreTransaction txh) throws BackendException { KeySliceQuery query = new KeySliceQuery(key, column, BufferUtil.nextBiggerBuffer(column)).setLimit(2); List<Entry> result = store.getSlice(query, txh); if (result.size() > 1) log.warn("GET query returned more than 1 result: store {} | key {} | column {}", store.getName(), key, column); if (result.isEmpty()) return null; else return result.get(0).getValueAs(StaticBuffer.STATIC_FACTORY); }
/** * Reads the configuration property for this StoreManager * * @param key Key identifying the configuration property * @return Value stored for the key or null if the configuration property has not (yet) been defined. */ @Override public <O> O get(final String key, final Class<O> dataType) { StaticBuffer column = string2StaticBuffer(key); final KeySliceQuery query = new KeySliceQuery(rowKey,column, BufferUtil.nextBiggerBuffer(column)); StaticBuffer result = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() { @Override public StaticBuffer call(StoreTransaction txh) throws BackendException { List<Entry> entries = store.getSlice(query,txh); if (entries.isEmpty()) return null; return entries.get(0).getValueAs(StaticBuffer.STATIC_FACTORY); } @Override public String toString() { return "getConfiguration"; } }, txProvider, times, maxOperationWaitTime); if (result==null) return null; return staticBuffer2Object(result, dataType); }
log.debug("Extended time window to {}", messageTimeEnd); query = new KeySliceQuery(logKey, BufferUtil.nextBiggerBuffer(lastEntry.getColumn()), BufferUtil.getLongBuffer(times.getTime(messageTimeEnd))); log.debug("Converted extended MessagePuller time window to {}", query); List<Entry> extraEntries = BackendOperation.execute(getOperation(query),KCVSLog.this,times,maxReadTime);
@Test public void testMutateManyWithLockUsesConsistentTx() throws BackendException { final ImmutableList<Entry> adds = ImmutableList.of(StaticArrayEntry.of(DATA_COL, DATA_VAL)); final ImmutableList<StaticBuffer> deletions = ImmutableList.of(); Map<String, Map<StaticBuffer, KCVMutation>> mutations = ImmutableMap.of(STORE_NAME, ImmutableMap.of(DATA_KEY, new KCVMutation(adds, deletions))); final KeyColumn kc = new KeyColumn(LOCK_KEY, LOCK_COL); // Acquire a lock backingLocker.writeLock(kc, consistentTx); // 2. Run mutateMany // 2.1. Check locks & expected values before mutating data backingLocker.checkLocks(consistentTx); StaticBuffer nextBuf = BufferUtil.nextBiggerBuffer(kc.getColumn()); KeySliceQuery expectedValueQuery = new KeySliceQuery(kc.getKey(), kc.getColumn(), nextBuf); expect(backingStore.getSlice(expectedValueQuery, consistentTx)) // expected value read must use strong consistency .andReturn(StaticArrayEntryList.of(StaticArrayEntry.of(LOCK_COL, LOCK_VAL))); // 2.2. Run mutateMany on backing manager to modify data backingManager.mutateMany(mutations, consistentTx); // writes by txs with locks must use strong consistency ctrl.replay(); // Lock acquisition expectStore.acquireLock(LOCK_KEY, LOCK_COL, LOCK_VAL, expectTx); // Mutate expectManager.mutateMany(mutations, expectTx); }
private void checkSingleExpectedValueUnsafe(final KeyColumn kc, final StaticBuffer ev, final ExpectedValueCheckingStore store) throws BackendException { final StaticBuffer nextBuf = BufferUtil.nextBiggerBuffer(kc.getColumn()); KeySliceQuery ksq = new KeySliceQuery(kc.getKey(), kc.getColumn(), nextBuf);
@Test public void testMutateWithLockUsesConsistentTx() throws BackendException { final ImmutableList<Entry> adds = ImmutableList.of(StaticArrayEntry.of(DATA_COL, DATA_VAL)); final ImmutableList<StaticBuffer> deletions = ImmutableList.of(); final KeyColumn kc = new KeyColumn(LOCK_KEY, LOCK_COL); // 1. Acquire a lock backingLocker.writeLock(kc, consistentTx); // 2. Run a mutation // N.B. mutation coordinates do not overlap with the lock, but consistentTx should be used anyway // 2.1. Check locks & expected values before mutating data backingLocker.checkLocks(consistentTx); StaticBuffer nextBuf = BufferUtil.nextBiggerBuffer(kc.getColumn()); KeySliceQuery expectedValueQuery = new KeySliceQuery(kc.getKey(), kc.getColumn(), nextBuf); expect(backingStore.getSlice(expectedValueQuery, consistentTx)) // expected value read must use strong consistency .andReturn(StaticArrayEntryList.of(StaticArrayEntry.of(LOCK_COL, LOCK_VAL))); // 2.2. Mutate data backingStore.mutate(DATA_KEY, adds, deletions, consistentTx); // writes by txs with locks must use strong consistency ctrl.replay(); // 1. Lock acquisition expectStore.acquireLock(LOCK_KEY, LOCK_COL, LOCK_VAL, expectTx); // 2. Mutate expectStore.mutate(DATA_KEY, adds, deletions, expectTx); }
for (int i = 0; i < numKeys; i++) { StaticBuffer key = KeyValueStoreUtil.getBuffer(i); queries.add(new KVQuery(key, BufferUtil.nextBiggerBuffer(key),2));
sliceEnd = IDHandler.getRelationType(type.longId(), getDirID(Direction.IN, rt), type.isInvisibleType()); assert sliceStart.compareTo(sliceEnd)<0; sliceEnd = BufferUtil.nextBiggerBuffer(sliceEnd); } else { DirectionID dirID = getDirID(dir, rt); sliceStart = colStart.getStaticBuffer(); sliceEnd = colEnd.getStaticBuffer(); if (!interval.startInclusive()) sliceStart = BufferUtil.nextBiggerBuffer(sliceStart); if (interval.endInclusive()) sliceEnd = BufferUtil.nextBiggerBuffer(sliceEnd); break; sliceEnd = colStart.getStaticBufferFlipBytes(keyStartPos,colStart.getPosition()); sliceStart = colEnd.getStaticBufferFlipBytes(keyStartPos,colEnd.getPosition()); if (interval.startInclusive()) sliceEnd = BufferUtil.nextBiggerBuffer(sliceEnd); if (!interval.endInclusive()) sliceStart = BufferUtil.nextBiggerBuffer(sliceStart); break; throw new AssertionError(type.getSortOrder().toString()); sliceEnd = BufferUtil.nextBiggerBuffer(sliceStart);