use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class KCVSConfiguration method set.
public <O> void set(String key, O value, O expectedValue, final boolean checkExpectedValue) {
final StaticBuffer column = string2StaticBuffer(key);
final List<Entry> additions;
final List<StaticBuffer> deletions;
if (value != null) {
// Addition
additions = new ArrayList<>(1);
deletions = KeyColumnValueStore.NO_DELETIONS;
StaticBuffer val = object2StaticBuffer(value);
additions.add(StaticArrayEntry.of(column, val));
} else {
// Deletion
additions = KeyColumnValueStore.NO_ADDITIONS;
deletions = new ArrayList<>(1);
deletions.add(column);
}
final StaticBuffer expectedValueBuffer;
if (checkExpectedValue && expectedValue != null) {
expectedValueBuffer = object2StaticBuffer(expectedValue);
} else {
expectedValueBuffer = null;
}
BackendOperation.execute(new BackendOperation.Transactional<Boolean>() {
@Override
public Boolean call(StoreTransaction txh) throws BackendException {
if (checkExpectedValue)
store.acquireLock(rowKey, column, expectedValueBuffer, txh);
store.mutate(rowKey, additions, deletions, txh);
return true;
}
@Override
public String toString() {
return "setConfiguration";
}
}, txProvider, times, maxOperationWaitTime);
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class CQLStoreTest method testGetKeysWithoutUnorderedScan.
@Test
@FeatureFlag(feature = JanusGraphFeature.OrderedScan)
public void testGetKeysWithoutUnorderedScan() throws BackendException, NoSuchFieldException, IllegalAccessException {
// support ordered scan but not unordered scan
Field field = StandardStoreFeatures.class.getDeclaredField("unorderedScan");
field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers");
modifiersField.setAccessible(true);
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
field.set(manager.getFeatures(), false);
Exception ex = assertThrows(PermanentBackendException.class, () -> store.getKeys(new SliceQuery(BufferUtil.zeroBuffer(1), BufferUtil.oneBuffer(4)), tx));
assertEquals("This operation is only allowed when partitioner supports unordered scan", ex.getMessage());
assertDoesNotThrow(() -> store.getKeys(new KeyRangeQuery(BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000), BufferUtil.getLongBuffer(1), BufferUtil.getLongBuffer(1000)), tx));
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class IDPoolTest method testAllocationTimeoutAndRecovery.
@Test
public void testAllocationTimeoutAndRecovery() throws BackendException {
IMocksControl ctrl = EasyMock.createStrictControl();
final int partition = 42;
final int idNamespace = 777;
final Duration timeout = Duration.ofSeconds(1L);
final IDAuthority mockAuthority = ctrl.createMock(IDAuthority.class);
// Sleep for two seconds, then throw a BackendException
// this whole delegate could be deleted if we abstracted StandardIDPool's internal executor and stopwatches
expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andDelegateTo(new IDAuthority() {
@Override
public IDBlock getIDBlock(int partition, int idNamespace, Duration timeout) throws BackendException {
assertThrows(InterruptedException.class, () -> Thread.sleep(2000L));
throw new TemporaryBackendException("slow backend");
}
@Override
public List<KeyRange> getLocalIDPartition() {
throw new IllegalArgumentException();
}
@Override
public void setIDBlockSizer(IDBlockSizer sizer) {
throw new IllegalArgumentException();
}
@Override
public void close() {
throw new IllegalArgumentException();
}
@Override
public String getUniqueID() {
throw new IllegalArgumentException();
}
@Override
public boolean supportsInterruption() {
return true;
}
});
expect(mockAuthority.getIDBlock(partition, idNamespace, timeout)).andReturn(new IDBlock() {
@Override
public long numIds() {
return 2;
}
@Override
public long getId(long index) {
return 200;
}
});
expect(mockAuthority.supportsInterruption()).andStubReturn(true);
ctrl.replay();
StandardIDPool pool = new StandardIDPool(mockAuthority, partition, idNamespace, Integer.MAX_VALUE, timeout, 0.1);
assertThrows(JanusGraphException.class, pool::nextID);
long nextID = pool.nextID();
assertEquals(200, nextID);
ctrl.verify();
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class StandardLogProcessorFrameworkTest method testAddLogProcessor.
@Test
public void testAddLogProcessor() throws BackendException, NoSuchFieldException, IllegalAccessException {
StandardJanusGraph graph = createGraphWithMockedInternals();
StandardLogProcessorFramework logProcessorFramework = new StandardLogProcessorFramework(graph);
logProcessorFramework.addLogProcessor("foo-identifier").addProcessor((tx, txId, changeState) -> {
// no-op processor
}).setStartTimeNow().setProcessorIdentifier("bar-processor").build();
Field processorLogsField = logProcessorFramework.getClass().getDeclaredField("processorLogs");
processorLogsField.setAccessible(true);
Map<String, Log> processorLogs = (Map<String, Log>) processorLogsField.get(logProcessorFramework);
assertNotNull(processorLogs, "processorLogs must not be null or empty after adding a log processor");
assertFalse(processorLogs.isEmpty(), "processorLogs should be non-empty after adding a processor");
}
use of org.janusgraph.diskstorage.BackendException in project janusgraph by JanusGraph.
the class KCVSLog method readSetting.
private long readSetting(String identifier, final StaticBuffer column, long defaultValue) {
final StaticBuffer key = getSettingKey(identifier);
StaticBuffer value = BackendOperation.execute(new BackendOperation.Transactional<StaticBuffer>() {
@Override
public StaticBuffer call(StoreTransaction txh) throws BackendException {
return KCVSUtil.get(store, key, column, txh);
}
@Override
public String toString() {
return "readingLogSetting";
}
}, this, times, maxReadTime);
if (value == null)
return defaultValue;
else {
Preconditions.checkArgument(value.length() == 8);
return value.getLong(0);
}
}
Aggregations