Search in sources :

Example 1 with TimestampProvider

use of org.janusgraph.diskstorage.util.time.TimestampProvider in project janusgraph by JanusGraph.

the class LocalLockMediatorTest method testLockExpiration.

@Test
public void testLockExpiration() {
    TimestampProvider times = TimestampProviders.MICRO;
    LocalLockMediator<ExpectedValueCheckingTransaction> llm = new LocalLockMediator<>(LOCK_NAMESPACE, times);
    assertTrue(llm.lock(kc, mockTx1, Instant.EPOCH));
    assertTrue(llm.lock(kc, mockTx2, Instant.MAX));
    llm = new LocalLockMediator<>(LOCK_NAMESPACE, times);
    assertTrue(llm.lock(kc, mockTx1, Instant.MAX));
    assertFalse(llm.lock(kc, mockTx2, Instant.MAX));
}
Also used : TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) ExpectedValueCheckingTransaction(org.janusgraph.diskstorage.locking.consistentkey.ExpectedValueCheckingTransaction) Test(org.junit.jupiter.api.Test)

Example 2 with TimestampProvider

use of org.janusgraph.diskstorage.util.time.TimestampProvider in project janusgraph by JanusGraph.

the class ManagementUtil method awaitIndexUpdate.

private static void awaitIndexUpdate(JanusGraph g, String indexName, String relationTypeName, long time, TemporalUnit unit) {
    Preconditions.checkArgument(g != null && g.isOpen(), "Need to provide valid, open graph instance");
    Preconditions.checkArgument(time > 0 && unit != null, "Need to provide valid time interval");
    Preconditions.checkArgument(StringUtils.isNotBlank(indexName), "Need to provide an index name");
    StandardJanusGraph graph = (StandardJanusGraph) g;
    TimestampProvider times = graph.getConfiguration().getTimestampProvider();
    Instant end = times.getTime().plus(Duration.of(time, unit));
    boolean isStable = false;
    while (times.getTime().isBefore(end)) {
        JanusGraphManagement management = graph.openManagement();
        try {
            if (StringUtils.isNotBlank(relationTypeName)) {
                RelationTypeIndex idx = management.getRelationIndex(management.getRelationType(relationTypeName), indexName);
                Preconditions.checkNotNull(idx, "Index could not be found: %s @ %s", indexName, relationTypeName);
                isStable = idx.getIndexStatus().isStable();
            } else {
                JanusGraphIndex idx = management.getGraphIndex(indexName);
                Preconditions.checkNotNull(idx, "Index could not be found: %s", indexName);
                isStable = true;
                for (PropertyKey key : idx.getFieldKeys()) {
                    if (!idx.getIndexStatus(key).isStable())
                        isStable = false;
                }
            }
        } finally {
            management.rollback();
        }
        if (isStable)
            break;
        try {
            times.sleepFor(Duration.ofMillis(500));
        } catch (InterruptedException ignored) {
        }
    }
    if (!isStable)
        throw new JanusGraphException("Index did not stabilize within the given amount of time. For sufficiently long " + "wait periods this is most likely caused by a failed/incorrectly shut down JanusGraph instance or a lingering transaction.");
}
Also used : JanusGraphManagement(org.janusgraph.core.schema.JanusGraphManagement) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) Instant(java.time.Instant) JanusGraphException(org.janusgraph.core.JanusGraphException) JanusGraphIndex(org.janusgraph.core.schema.JanusGraphIndex) RelationTypeIndex(org.janusgraph.core.schema.RelationTypeIndex) PropertyKey(org.janusgraph.core.PropertyKey) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph)

Example 3 with TimestampProvider

use of org.janusgraph.diskstorage.util.time.TimestampProvider in project janusgraph by JanusGraph.

the class Backend method buildStoreIndexScanJob.

private StandardScanner.Builder buildStoreIndexScanJob(String storeName) {
    TimestampProvider provider = configuration.get(TIMESTAMP_PROVIDER);
    ModifiableConfiguration jobConfig = buildJobConfiguration();
    jobConfig.set(JOB_START_TIME, provider.getTime().toEpochMilli());
    return scanner.build().setStoreName(storeName).setTimestampProvider(provider).setJobConfiguration(jobConfig).setGraphConfiguration(configuration).setNumProcessingThreads(1).setWorkBlockSize(this.configuration.get(PAGE_SIZE));
}
Also used : TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) ModifiableConfiguration(org.janusgraph.diskstorage.configuration.ModifiableConfiguration)

Example 4 with TimestampProvider

use of org.janusgraph.diskstorage.util.time.TimestampProvider in project janusgraph by JanusGraph.

the class JanusGraphIndexTest method testIndexReplay.

@Tag(TestCategory.BRITTLE_TESTS)
@Test
public void testIndexReplay() throws Exception {
    final TimestampProvider times = graph.getConfiguration().getTimestampProvider();
    final Instant startTime = times.getTime();
    clopen(option(SYSTEM_LOG_TRANSACTIONS), true, option(KCVSLog.LOG_READ_LAG_TIME, TRANSACTION_LOG), Duration.ofMillis(50), option(LOG_READ_INTERVAL, TRANSACTION_LOG), Duration.ofMillis(250), option(MAX_COMMIT_TIME), Duration.ofSeconds(1), option(STORAGE_WRITE_WAITTIME), Duration.ofMillis(300), option(TestMockIndexProvider.INDEX_BACKEND_PROXY, INDEX), readConfig.get(INDEX_BACKEND, INDEX), option(INDEX_BACKEND, INDEX), TestMockIndexProvider.class.getName(), option(TestMockIndexProvider.INDEX_MOCK_FAILADD, INDEX), true);
    final PropertyKey name = mgmt.makePropertyKey("name").dataType(String.class).make();
    final PropertyKey age = mgmt.makePropertyKey("age").dataType(Integer.class).make();
    mgmt.buildIndex("mi", Vertex.class).addKey(name, getTextMapping()).addKey(age).buildMixedIndex(INDEX);
    finishSchema();
    final Vertex[] vs = new JanusGraphVertex[4];
    vs[0] = tx.addVertex("name", "Big Boy Bobson", "age", 55);
    newTx();
    vs[1] = tx.addVertex("name", "Long Little Lewis", "age", 35);
    vs[2] = tx.addVertex("name", "Tall Long Tiger", "age", 75);
    vs[3] = tx.addVertex("name", "Long John Don", "age", 15);
    newTx();
    vs[2] = getV(tx, vs[2]);
    vs[2].remove();
    vs[3] = getV(tx, vs[3]);
    vs[3].property(VertexProperty.Cardinality.single, "name", "Bad Boy Badsy");
    vs[3].property("age").remove();
    newTx();
    vs[0] = getV(tx, vs[0]);
    vs[0].property(VertexProperty.Cardinality.single, "age", 66);
    newTx();
    clopen();
    // Just to make sure nothing has been persisted to index
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mi");
    /*
        Transaction Recovery
         */
    final TransactionRecovery recovery = JanusGraphFactory.startTransactionRecovery(graph, startTime);
    // wait
    Thread.sleep(12000L);
    recovery.shutdown();
    final long[] recoveryStats = ((StandardTransactionLogProcessor) recovery).getStatistics();
    clopen();
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy"), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "long"), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    // JanusGraphVertex v = Iterables.getOnlyElement(tx.query().has("name",Text.CONTAINS,"long").vertices());
    // System.out.println(v.getProperty("age"));
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "long").interval("age", 30, 40), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("age", 75), ElementCategory.VERTEX, 0, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().has("name", Text.CONTAINS, "boy").interval("age", 60, 70), ElementCategory.VERTEX, 1, new boolean[] { true, true }, "mi");
    evaluateQuery(tx.query().interval("age", 0, 100), ElementCategory.VERTEX, 2, new boolean[] { true, true }, "mi");
    // schema transaction was successful
    assertEquals(1, recoveryStats[0]);
    // all 4 index transaction had provoked errors in the indexing backend
    assertEquals(4, recoveryStats[1]);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TransactionRecovery(org.janusgraph.core.log.TransactionRecovery) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) Instant(java.time.Instant) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) StandardTransactionLogProcessor(org.janusgraph.graphdb.log.StandardTransactionLogProcessor) PropertyKey(org.janusgraph.core.PropertyKey) RepeatedIfExceptionsTest(io.github.artsok.RepeatedIfExceptionsTest) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 5 with TimestampProvider

use of org.janusgraph.diskstorage.util.time.TimestampProvider in project janusgraph by JanusGraph.

the class StandardLogProcessorFrameworkTest method createGraphWithMockedInternals.

private StandardJanusGraph createGraphWithMockedInternals() throws BackendException {
    StandardJanusGraph mockGraph = mock(StandardJanusGraph.class);
    Backend mockBackend = mock(Backend.class);
    KCVSLog mockKCVSLog = mock(KCVSLog.class);
    GraphDatabaseConfiguration gdbConfig = mock(GraphDatabaseConfiguration.class);
    TimestampProvider tsProvider = mock(TimestampProvider.class);
    Serializer mockSerializer = mock(Serializer.class);
    when(mockGraph.getConfiguration()).thenReturn(gdbConfig);
    when(mockGraph.isOpen()).thenReturn(true);
    when(mockGraph.getDataSerializer()).thenReturn(mockSerializer);
    when(mockGraph.getBackend()).thenReturn(mockBackend);
    when(mockBackend.getUserLog(anyString())).thenReturn(mockKCVSLog);
    when(gdbConfig.getTimestampProvider()).thenReturn(tsProvider);
    mockKCVSLog.registerReaders(mock(ReadMarker.class), new LinkedList<>());
    return mockGraph;
}
Also used : Backend(org.janusgraph.diskstorage.Backend) TimestampProvider(org.janusgraph.diskstorage.util.time.TimestampProvider) KCVSLog(org.janusgraph.diskstorage.log.kcvs.KCVSLog) ReadMarker(org.janusgraph.diskstorage.log.ReadMarker) GraphDatabaseConfiguration(org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Serializer(org.janusgraph.graphdb.database.serialize.Serializer)

Aggregations

TimestampProvider (org.janusgraph.diskstorage.util.time.TimestampProvider)7 PropertyKey (org.janusgraph.core.PropertyKey)4 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)4 Instant (java.time.Instant)3 GraphDatabaseConfiguration (org.janusgraph.graphdb.configuration.GraphDatabaseConfiguration)3 Serializer (org.janusgraph.graphdb.database.serialize.Serializer)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 RelationType (org.janusgraph.core.RelationType)2 EdgeSerializer (org.janusgraph.graphdb.database.EdgeSerializer)2 Test (org.junit.jupiter.api.Test)2 Preconditions (com.google.common.base.Preconditions)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Iterators (com.google.common.collect.Iterators)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 RepeatedIfExceptionsTest (io.github.artsok.RepeatedIfExceptionsTest)1 File (java.io.File)1 Path (java.nio.file.Path)1