use of org.neo4j.time.Stopwatch in project neo4j by neo4j.
the class CrashGenerationCleaner method clean.
// === Methods about the execution and threading ===
public void clean(CleanupJob.Executor executor) {
monitor.cleanupStarted();
assert unstableGeneration > stableGeneration : unexpectedGenerations();
assert unstableGeneration - stableGeneration > 1 : unexpectedGenerations();
Stopwatch startTime = Stopwatch.start();
long pagesToClean = highTreeNodeId - lowTreeNodeId;
int threads = NUMBER_OF_WORKERS;
long batchSize = batchSize(pagesToClean, threads);
AtomicLong nextId = new AtomicLong(lowTreeNodeId);
AtomicBoolean stopFlag = new AtomicBoolean();
LongAdder cleanedPointers = new LongAdder();
LongAdder numberOfTreeNodes = new LongAdder();
List<CleanupJob.JobResult<?>> jobResults = new ArrayList<>();
for (int i = 0; i < threads; i++) {
Callable<?> cleanerTask = cleaner(nextId, batchSize, numberOfTreeNodes, cleanedPointers, stopFlag, pageCacheTracer);
CleanupJob.JobResult<?> jobHandle = executor.submit("Recovery clean up of '" + treeName + "'", cleanerTask);
jobResults.add(jobHandle);
}
awaitAll(jobResults);
monitor.cleanupFinished(pagesToClean, numberOfTreeNodes.sum(), cleanedPointers.sum(), startTime.elapsed(MILLISECONDS));
}
use of org.neo4j.time.Stopwatch in project neo4j by neo4j.
the class Bootloader method stop.
int stop() {
BootloaderOsAbstraction os = ctx.os();
Long pid = os.getPidIfRunning();
if (pid == null) {
ctx.out.println("Neo4j is not running.");
return EXIT_CODE_OK;
}
ctx.out.print("Stopping Neo4j.");
int timeout = ctx.getEnv(ENV_NEO4J_SHUTDOWN_TIMEOUT, DEFAULT_NEO4J_SHUTDOWN_TIMEOUT, INT);
Stopwatch stopwatch = Stopwatch.start();
os.stop(pid);
int printCount = 0;
do {
if (os.getPidIfRunning() == null) {
ctx.out.println(" stopped.");
return EXIT_CODE_OK;
}
if (stopwatch.hasTimedOut(printCount, SECONDS)) {
printCount++;
ctx.out.print(".");
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
break;
}
} while (!stopwatch.hasTimedOut(timeout, SECONDS));
ctx.out.println(" failed to stop.");
ctx.out.printf("Neo4j%s took more than %d seconds to stop.%n", pidIfKnown(pid), stopwatch.elapsed(SECONDS));
ctx.out.printf("Please see %s for details.%n", ctx.config().get(GraphDatabaseSettings.store_user_log_path));
return EXIT_CODE_RUNNING;
}
use of org.neo4j.time.Stopwatch in project neo4j by neo4j.
the class WindowsBootloaderOs method uninstallService.
@Override
void uninstallService() throws BootFailureException {
issueServiceCommand("DS", behaviour().blocking());
Stopwatch stopwatch = Stopwatch.start();
while (serviceInstalled() && !stopwatch.hasTimedOut(Bootloader.DEFAULT_NEO4J_SHUTDOWN_TIMEOUT, TimeUnit.SECONDS)) {
try {
Thread.sleep(300);
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
break;
}
}
}
use of org.neo4j.time.Stopwatch in project neo4j by neo4j.
the class SchemaImpl method awaitIndexesOnline.
private boolean awaitIndexesOnline(Iterable<IndexDescriptor> indexes, Function<IndexDescriptor, String> describe, long duration, TimeUnit unit, boolean bubbleNotFound) {
Stopwatch startTime = Stopwatch.start();
do {
boolean allOnline = true;
SchemaRead schemaRead = transaction.schemaRead();
for (IndexDescriptor index : indexes) {
if (index == IndexDescriptor.NO_INDEX) {
allOnline = false;
break;
}
try {
InternalIndexState indexState = schemaRead.indexGetState(index);
if (indexState == InternalIndexState.POPULATING) {
allOnline = false;
break;
}
if (indexState == InternalIndexState.FAILED) {
String cause = schemaRead.indexGetFailure(index);
String message = "Index " + describe.apply(index) + " entered a " + indexState + " state. Please see database logs.";
message = IndexPopulationFailure.appendCauseOfFailure(message, cause);
throw new IllegalStateException(message);
}
} catch (IndexNotFoundKernelException e) {
if (bubbleNotFound) {
throw newIndexNotFoundException(descriptorToDefinition(transaction.tokenRead(), index), e);
}
// Weird that the index vanished, but we'll just wait and see if it comes back until we time out.
allOnline = false;
break;
}
}
if (allOnline) {
return false;
}
sleepIgnoreInterrupt();
} while (!startTime.hasTimedOut(duration, unit));
return true;
}
use of org.neo4j.time.Stopwatch in project neo4j by neo4j.
the class RelationshipChainChecker method checkDirection.
private void checkDirection(LongRange nodeIdRange, ScanDirection direction) throws Exception {
RelationshipStore relationshipStore = context.neoStores.getRelationshipStore();
long highId = relationshipStore.getHighId();
AtomicBoolean end = new AtomicBoolean();
int numberOfThreads = numberOfChainCheckers + 1;
ThrowingRunnable[] workers = new ThrowingRunnable[numberOfThreads];
ProgressListener localProgress = progress.threadLocalReporter();
ArrayBlockingQueue<BatchedRelationshipRecords>[] threadQueues = new ArrayBlockingQueue[numberOfChainCheckers];
BatchedRelationshipRecords[] threadBatches = new BatchedRelationshipRecords[numberOfChainCheckers];
for (int i = 0; i < numberOfChainCheckers; i++) {
threadQueues[i] = new ArrayBlockingQueue<>(20);
threadBatches[i] = new BatchedRelationshipRecords();
workers[i] = relationshipVsRelationshipChecker(nodeIdRange, direction, relationshipStore, threadQueues[i], end, i);
}
// Record reader
workers[workers.length - 1] = () -> {
RelationshipRecord relationship = relationshipStore.newRecord();
try (var cursorContext = new CursorContext(context.pageCacheTracer.createPageCursorTracer(RELATIONSHIP_CONSISTENCY_CHECKER_TAG));
var cursor = relationshipStore.openPageCursorForReadingWithPrefetching(0, cursorContext)) {
int recordsPerPage = relationshipStore.getRecordsPerPage();
long id = direction.startingId(highId);
while (id >= 0 && id < highId && !context.isCancelled()) {
for (int i = 0; i < recordsPerPage && id >= 0 && id < highId; i++, id = direction.nextId(id)) {
relationshipStore.getRecordByCursor(id, relationship, FORCE, cursor);
localProgress.add(1);
if (relationship.inUse()) {
queueRelationshipCheck(threadQueues, threadBatches, relationship);
}
}
}
processLastRelationshipChecks(threadQueues, threadBatches, end);
localProgress.done();
}
};
Stopwatch stopwatch = Stopwatch.start();
cacheAccess.clearCache();
context.execution.runAll(getClass().getSimpleName() + "-" + direction.name(), workers);
detectSingleRelationshipChainInconsistencies(nodeIdRange);
context.paddedDebug("%s %s took %s", this, direction, duration(stopwatch.elapsed(TimeUnit.MILLISECONDS)));
}
Aggregations