Search in sources :

Example 6 with IDPoolExhaustedException

use of org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException in project janusgraph by JanusGraph.

the class IDPoolTest method testPoolExhaustion1.

@Test
public void testPoolExhaustion1() {
    MockIDAuthority idAuthority = new MockIDAuthority(200);
    int idUpper = 10000;
    StandardIDPool pool = new StandardIDPool(idAuthority, 0, 1, idUpper, Duration.ofMillis(2000), 0.2);
    for (int i = 1; i < idUpper * 2; i++) {
        try {
            long id = pool.nextID();
            assertTrue(id < idUpper);
        } catch (IDPoolExhaustedException e) {
            assertEquals(idUpper, i);
            break;
        }
    }
}
Also used : StandardIDPool(org.janusgraph.graphdb.database.idassigner.StandardIDPool) IDPoolExhaustedException(org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException) Test(org.junit.Test)

Example 7 with IDPoolExhaustedException

use of org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException in project janusgraph by JanusGraph.

the class MockIDAuthority method getIDBlock.

@Override
public IDBlock getIDBlock(final int partition, final int idNamespace, Duration timeout) throws BackendException {
    // Delay artificially
    if (delayAcquisitionMS > 0) {
        try {
            Thread.sleep(delayAcquisitionMS);
        } catch (InterruptedException e) {
            throw new TemporaryBackendException(e);
        }
    }
    Preconditions.checkArgument(partition >= 0);
    Preconditions.checkArgument(idNamespace >= 0);
    Long p = (((long) partition) << Integer.SIZE) + ((long) idNamespace);
    long size = blockSizer.getBlockSize(idNamespace);
    AtomicLong id = ids.get(p);
    if (id == null) {
        ids.putIfAbsent(p, new AtomicLong(1));
        id = ids.get(p);
        Preconditions.checkNotNull(id);
    }
    long lowerBound = id.getAndAdd(size);
    if (lowerBound >= blockSizeLimit) {
        throw new IDPoolExhaustedException("Reached partition limit: " + blockSizeLimit);
    }
    return new MockIDBlock(lowerBound, Math.min(size, blockSizeLimit - lowerBound));
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) IDPoolExhaustedException(org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException)

Example 8 with IDPoolExhaustedException

use of org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException in project janusgraph by JanusGraph.

the class VertexIDAssignerTest method testIDAssignment.

@Test
public void testIDAssignment() {
    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);
            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("Max Avail: " + maxIDAssignments + " vs. [" + totalVertices + "," + totalRelations + "]", totalRelations >= maxIDAssignments / 3 * 2 || totalVertices >= maxIDAssignments / 3 * 2);
            } finally {
                graph.tx().rollback();
                graph.close();
            }
        }
    }
}
Also used : LongHashSet(com.carrotsearch.hppc.LongHashSet) LongSet(com.carrotsearch.hppc.LongSet) JanusGraph(org.janusgraph.core.JanusGraph) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) ArrayList(java.util.ArrayList) IDPoolExhaustedException(org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException) InternalRelation(org.janusgraph.graphdb.internal.InternalRelation) Test(org.junit.Test)

Aggregations

IDPoolExhaustedException (org.janusgraph.graphdb.database.idassigner.IDPoolExhaustedException)8 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 StandardIDPool (org.janusgraph.graphdb.database.idassigner.StandardIDPool)2 LongHashSet (com.carrotsearch.hppc.LongHashSet)1 LongSet (com.carrotsearch.hppc.LongSet)1 Joiner (com.google.common.base.Joiner)1 Preconditions (com.google.common.base.Preconditions)1 Duration (java.time.Duration)1 Instant (java.time.Instant)1 Collections (java.util.Collections)1 List (java.util.List)1 Random (java.util.Random)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 JanusGraph (org.janusgraph.core.JanusGraph)1 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)1 JanusGraphVertexProperty (org.janusgraph.core.JanusGraphVertexProperty)1 org.janusgraph.diskstorage (org.janusgraph.diskstorage)1 Configuration (org.janusgraph.diskstorage.configuration.Configuration)1 KeyColumnValueStore (org.janusgraph.diskstorage.keycolumnvalue.KeyColumnValueStore)1