use of com.carrotsearch.hppc.LongHashSet in project janusgraph by JanusGraph.
the class IDAuthorityTest method testMultiIDAcquisition.
@ParameterizedTest
@MethodSource("configs")
public void testMultiIDAcquisition(WriteConfiguration baseConfig) throws Throwable {
setUp(baseConfig);
boolean localStore = Arrays.stream(manager).noneMatch(m -> m.getFeatures().isDistributed());
// On local mode ids acquired sequentially
if (localStore) {
return;
}
final int numPartitions = MAX_NUM_PARTITIONS;
final int numAcquisitionsPerThreadPartition = 100;
final IDBlockSizer blockSizer = new InnerIDBlockSizer();
for (int i = 0; i < CONCURRENCY; i++) idAuthorities[i].setIDBlockSizer(blockSizer);
final List<ConcurrentLinkedQueue<IDBlock>> ids = new ArrayList<>(numPartitions);
for (int i = 0; i < numPartitions; i++) {
ids.add(new ConcurrentLinkedQueue<>());
}
final int maxIterations = numAcquisitionsPerThreadPartition * numPartitions * 2;
final Collection<Future<?>> futures = new ArrayList<>(CONCURRENCY);
ExecutorService es = Executors.newFixedThreadPool(CONCURRENCY);
final Set<String> uniqueIds = new HashSet<>(CONCURRENCY);
for (int i = 0; i < CONCURRENCY; i++) {
final IDAuthority idAuthority = idAuthorities[i];
final IDStressor stressRunnable = new IDStressor(numAcquisitionsPerThreadPartition, numPartitions, maxIterations, idAuthority, ids);
uniqueIds.add(idAuthority.getUniqueID());
futures.add(es.submit(stressRunnable));
}
// If this fails, it's likely to be a bug in the test rather than the
// IDAuthority (the latter is technically possible, just less likely)
assertEquals(CONCURRENCY, uniqueIds.size());
for (Future<?> f : futures) {
try {
f.get();
} catch (ExecutionException e) {
throw e.getCause();
}
}
for (int i = 0; i < numPartitions; i++) {
ConcurrentLinkedQueue<IDBlock> list = ids.get(i);
assertEquals(numAcquisitionsPerThreadPartition * CONCURRENCY, list.size());
LongSet idSet = new LongHashSet((int) blockSize * list.size());
for (IDBlock block : list) checkBlock(block, idSet);
}
es.shutdownNow();
}
use of com.carrotsearch.hppc.LongHashSet in project janusgraph by JanusGraph.
the class VertexIDAssignerTest method testCustomIdAssignment.
private void testCustomIdAssignment(VertexIDAssigner idAssigner, CustomIdStrategy idStrategy, int numPartitionsBits) {
LongSet vertexIds = new LongHashSet();
final long maxCount = idAssigner.getIDManager().getVertexCountBound();
long count = 1;
for (int trial = 0; trial < 10; trial++) {
final JanusGraph graph = getInMemoryGraph(true, true, numPartitionsBits);
int numVertices = 1000;
final List<JanusGraphVertex> vertices = new ArrayList<>(numVertices);
try {
for (int i = 0; i < numVertices; i++, count++) {
final long userVertexId;
switch(idStrategy) {
case LOW:
userVertexId = count;
break;
case HIGH:
userVertexId = maxCount - count;
break;
default:
throw new RuntimeException("Unsupported custom id strategy: " + idStrategy);
}
final long id = idAssigner.getIDManager().toVertexId(userVertexId);
JanusGraphVertex next = graph.addVertex(T.id, id, "user_id", userVertexId);
vertices.add(next);
}
// Verify that ids are set, unique and consistent with user id basis
for (JanusGraphVertex v : vertices) {
assertTrue(v.hasId());
long id = v.longId();
assertTrue(id > 0 && id < Long.MAX_VALUE);
assertTrue(vertexIds.add(id));
assertEquals((long) v.value("user_id"), idAssigner.getIDManager().fromVertexId(id));
}
} finally {
graph.tx().rollback();
graph.close();
}
}
}
use of com.carrotsearch.hppc.LongHashSet in project janusgraph by JanusGraph.
the class VertexIDAssignerTest method testIDAssignment.
@ParameterizedTest
@MethodSource("configs")
public void testIDAssignment(VertexIDAssigner idAssigner, long maxIDAssignments, int numPartitionsBits) {
LongSet vertexIds = new LongHashSet();
LongSet relationIds = new LongHashSet();
int totalRelations = 0;
int totalVertices = 0;
for (int trial = 0; trial < 10; trial++) {
for (boolean flush : new boolean[] { true, false }) {
final JanusGraph graph = getInMemoryGraph(false, false, numPartitionsBits);
int numVertices = 1000;
final List<JanusGraphVertex> vertices = new ArrayList<>(numVertices);
final List<InternalRelation> relations = new ArrayList<>();
JanusGraphVertex old = null;
totalRelations += 2 * numVertices;
totalVertices += numVertices;
try {
for (int i = 0; i < numVertices; i++) {
JanusGraphVertex next = graph.addVertex();
InternalRelation edge = null;
if (old != null) {
edge = (InternalRelation) old.addEdge("knows", next);
}
InternalRelation property = (InternalRelation) next.property("age", 25);
if (flush) {
idAssigner.assignID((InternalVertex) next, next.vertexLabel());
idAssigner.assignID(property);
if (edge != null)
idAssigner.assignID(edge);
}
relations.add(property);
if (edge != null)
relations.add(edge);
vertices.add(next);
old = next;
}
if (!flush)
idAssigner.assignIDs(relations);
// Check if we should have exhausted the id pools
if (totalRelations > maxIDAssignments || totalVertices > maxIDAssignments)
fail();
// Verify that ids are set and unique
for (JanusGraphVertex v : vertices) {
assertTrue(v.hasId());
long id = v.longId();
assertTrue(id > 0 && id < Long.MAX_VALUE);
assertTrue(vertexIds.add(id));
}
for (InternalRelation r : relations) {
assertTrue(r.hasId());
long id = r.longId();
assertTrue(id > 0 && id < Long.MAX_VALUE);
assertTrue(relationIds.add(id));
}
} catch (IDPoolExhaustedException e) {
// Since the id assignment process is randomized, we divide by 3/2 to account for minor variations
assertTrue(totalRelations >= maxIDAssignments / 3 * 2 || totalVertices >= maxIDAssignments / 3 * 2, "Max Avail: " + maxIDAssignments + " vs. [" + totalVertices + "," + totalRelations + "]");
} finally {
graph.tx().rollback();
graph.close();
}
}
}
}
use of com.carrotsearch.hppc.LongHashSet in project cassandra by apache.
the class DynamicTokenTreeBuilder method add.
public void add(Long token, long keyPosition) {
LongSet found = tokens.get(token);
if (found == null)
tokens.put(token, (found = new LongHashSet(2)));
found.add(keyPosition);
}
use of com.carrotsearch.hppc.LongHashSet in project cassandra by apache.
the class TokenTreeTest method generateTree.
private static TokenTree generateTree(final long minToken, final long maxToken, boolean isStatic) throws IOException {
final SortedMap<Long, LongSet> toks = new TreeMap<Long, LongSet>() {
{
for (long i = minToken; i <= maxToken; i++) {
LongSet offsetSet = new LongHashSet();
offsetSet.add(i);
put(i, offsetSet);
}
}
};
final TokenTreeBuilder builder = isStatic ? new StaticTokenTreeBuilder(new FakeCombinedTerm(toks)) : new DynamicTokenTreeBuilder(toks);
builder.finish();
final File treeFile = FileUtils.createTempFile("token-tree-get-test", "tt");
treeFile.deleteOnExit();
try (SequentialWriter writer = new SequentialWriter(treeFile, DEFAULT_OPT)) {
builder.write(writer);
writer.sync();
}
RandomAccessReader reader = null;
try {
reader = RandomAccessReader.open(treeFile);
return new TokenTree(new MappedBuffer(reader));
} finally {
FileUtils.closeQuietly(reader);
}
}
Aggregations