use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class BackendTransaction method edgeStoreMultiQuery.
public Map<StaticBuffer, EntryList> edgeStoreMultiQuery(final List<StaticBuffer> keys, final SliceQuery query) {
if (storeFeatures.hasMultiQuery()) {
return executeRead(new Callable<Map<StaticBuffer, EntryList>>() {
@Override
public Map<StaticBuffer, EntryList> call() throws Exception {
return cacheEnabled ? edgeStore.getSlice(keys, query, storeTx) : edgeStore.getSliceNoCache(keys, query, storeTx);
}
@Override
public String toString() {
return "MultiEdgeStoreQuery";
}
});
} else {
final Map<StaticBuffer, EntryList> results = new HashMap<>(keys.size());
if (threadPool == null || keys.size() < MIN_TASKS_TO_PARALLELIZE) {
for (StaticBuffer key : keys) {
results.put(key, edgeStoreQuery(new KeySliceQuery(key, query)));
}
} else {
final CountDownLatch doneSignal = new CountDownLatch(keys.size());
final AtomicInteger failureCount = new AtomicInteger(0);
EntryList[] resultArray = new EntryList[keys.size()];
for (int i = 0; i < keys.size(); i++) {
threadPool.execute(new SliceQueryRunner(new KeySliceQuery(keys.get(i), query), doneSignal, failureCount, resultArray, i));
}
try {
doneSignal.await();
} catch (InterruptedException e) {
throw new JanusGraphException("Interrupted while waiting for multi-query to complete", e);
}
if (failureCount.get() > 0) {
throw new JanusGraphException("Could not successfully complete multi-query. " + failureCount.get() + " individual queries failed.");
}
for (int i = 0; i < keys.size(); i++) {
assert resultArray[i] != null;
results.put(keys.get(i), resultArray[i]);
}
}
return results;
}
}
use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class KCVSConfiguration method close.
@Override
public void close() {
try {
store.close();
txProvider.close();
IOUtils.closeQuietly(serializer);
} catch (BackendException e) {
throw new JanusGraphException("Could not close configuration store", e);
}
}
use of org.janusgraph.core.JanusGraphException 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 {
try {
Thread.sleep(2000L);
} catch (InterruptedException e) {
fail();
}
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);
try {
pool.nextID();
fail();
} catch (JanusGraphException ignored) {
}
long nextID = pool.nextID();
assertEquals(200, nextID);
ctrl.verify();
}
use of org.janusgraph.core.JanusGraphException in project janusgraph by JanusGraph.
the class JanusGraphIndexTest method testIndexing.
private void testIndexing(Cardinality cardinality) {
if (supportsCollections()) {
PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
PropertyKey intProperty = mgmt.makePropertyKey("age").dataType(Integer.class).cardinality(cardinality).make();
PropertyKey longProperty = mgmt.makePropertyKey("long").dataType(Long.class).cardinality(cardinality).make();
PropertyKey uuidProperty = mgmt.makePropertyKey("uuid").dataType(UUID.class).cardinality(cardinality).make();
PropertyKey geopointProperty = mgmt.makePropertyKey("geopoint").dataType(Geoshape.class).cardinality(cardinality).make();
mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).addKey(intProperty).addKey(longProperty).addKey(uuidProperty).addKey(geopointProperty).buildMixedIndex(INDEX);
finishSchema();
testCollection(cardinality, "name", "Totoro", "Hiro");
testCollection(cardinality, "age", 1, 2);
testCollection(cardinality, "long", 1L, 2L);
testCollection(cardinality, "geopoint", Geoshape.point(1.0, 1.0), Geoshape.point(2.0, 2.0));
String backend = readConfig.get(INDEX_BACKEND, INDEX);
// https://issues.apache.org/jira/browse/SOLR-11264
if (!"solr".equals(backend)) {
testCollection(cardinality, "uuid", UUID.randomUUID(), UUID.randomUUID());
}
} else {
try {
PropertyKey stringProperty = mgmt.makePropertyKey("name").dataType(String.class).cardinality(cardinality).make();
// This should throw an exception
mgmt.buildIndex("collectionIndex", Vertex.class).addKey(stringProperty, getStringMapping()).buildMixedIndex(INDEX);
Assert.fail("Should have thrown an exception");
} catch (JanusGraphException ignored) {
}
}
}
Aggregations