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));
}
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.");
}
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));
}
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]);
}
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;
}
Aggregations