public static <T, R> R doWithExclusiveLock(File file, Function<T, ? extends R> code, Supplier<T> target) { final long timeoutAt = System.currentTimeMillis() + timeoutMS; boolean warnedOnFailure = false; try (final FileChannel channel = FileChannel.open(file.toPath(), StandardOpenOption.WRITE)) { while (System.currentTimeMillis() < timeoutAt) { try { FileLock fileLock = channel.tryLock(); if (fileLock != null) { return code.apply(target.get()); } } catch (IOException | OverlappingFileLockException e) { // failed to acquire the lock, wait until other operation completes if (!warnedOnFailure) { LOG.debug("Failed to acquire a lock on the table store file. Retrying"); warnedOnFailure = true; } } Jvm.pause(50L); } } catch (IOException e) { throw new IllegalStateException("Couldn't perform operation with file lock", e); } throw new IllegalStateException("Unable to claim exclusive lock on file " + file); }
@After public void checkMappedFiles() { System.gc(); Jvm.pause(50); MappedFile.checkMappedFiles(); }
@After public void checkMappedFiles() { System.gc(); Jvm.pause(50); MappedFile.checkMappedFiles(); } }
@Override public void writeMarshallable(@NotNull WireOut wire) { ValueOut valueOut = wire.getValueOut(); for (int i = 0; i < NUMBER_OF_LONGS; i++) valueOut.int64(i); Jvm.pause(writePauseMs); } }
boolean fileFound = false; for (int i = 0; i < 20; i++) { Jvm.pause(10); if ((fileFound = ( currentCycle <= directoryListing.getMaxCreatedCycle() &&
private void moveToSpecifiedPosition(final ChronicleQueue ic, final ExcerptTailer tailer, final boolean isFirstIteration) { if (isSet(startIndex) && isFirstIteration) { if (startIndex < ic.firstIndex()) { throw new IllegalArgumentException(String.format("startIndex %d is less than first index %d", startIndex, ic.firstIndex())); } messageSink.accept("Waiting for startIndex " + startIndex); for (; ; ) { if (tailer.moveToIndex(startIndex)) break; Jvm.pause(100); } } if (isSet(maxHistoryRecords) && isFirstIteration) { tailer.toEnd(); tailer.moveToIndex(Math.max(ic.firstIndex(), tailer.index() - maxHistoryRecords)); } else if (tailInputSource && isFirstIteration) { tailer.toEnd(); } }
while (!thread.isInterrupted()) { appender.pretouch(); Jvm.pause(10); Jvm.pause(250); // give the reader time to start long next = System.nanoTime(); long end = (long) (next + runtime * 1e9); Jvm.pause(50); System.out.println("read histogram: " + readTime.toMicrosFormat()); IOTools.deleteDirWithFiles(path, 2); Jvm.pause(1000);
long delay = 10000 - time0; if (delay > 0) Jvm.pause(delay);
@Override public Throwable call() { try (final ChronicleQueue queue = queue()) { final ExcerptAppender appender = queue.acquireAppender(); Jvm.pause(random.nextInt(DELAY_WRITER_RANDOM_MS)); final long startTime = System.nanoTime(); int loopIteration = 0; while (true) { final int value = write(appender); while (System.nanoTime() < (startTime + (loopIteration * SLEEP_PER_WRITE_NANOS))) { // spin } loopIteration++; if (value >= expectedNumberOfMessages) { return null; } } } catch (Throwable e) { exception = e; return e; } }
public StartAndMonitor(ChronicleQueue queue, String name, int writePauseMs, int sleepBetweenMillis) { final SlowToSerialiseAndDeserialise object = new SlowToSerialiseAndDeserialise(writePauseMs); Thread thread = new Thread(() -> { try { while (running.get()) { long loopStart = System.nanoTime(); final ExcerptAppender appender = queue.acquireAppender(); // System.out.println("about to open"); try (final DocumentContext ctx = appender.writingDocument()) { // System.out.println("about to write"); ctx.wire().getValueOut().marshallable(object); // System.out.println("about to close"); } // System.out.println("closed"); long timeTaken = System.nanoTime() - loopStart; histo.sampleNanos(timeTaken); Jvm.pause(sleepBetweenMillis); } } catch (Throwable t) { t.printStackTrace(); } }, name); thread.start(); } }
@Override public Throwable call() throws Exception { ChronicleQueue queue0 = null; try (ChronicleQueue queue = queueBuilder(path).build()) { queue0 = queue; ExcerptAppender appender = queue.acquireAppender(); System.out.println("Starting pretoucher"); while (!Thread.currentThread().isInterrupted() && !queue.isClosed()) { Jvm.pause(50); appender.pretouch(); } } catch (Throwable e) { if (queue0 != null && queue0.isClosed()) return null; exception = e; return e; } return null; } }
long millis = System.currentTimeMillis() % 1000; if (millis > 1 && millis < 999) { Jvm.pause(999 - millis);
System.out.println("documentContext.isPresent=" + present + (present ? ",index=" + Long.toHexString(index) : ", no index")); Jvm.pause(50); ((SingleChronicleQueueExcerpts.StoreAppender) wqueue.acquireAppender()) .writeEndOfCycleIfRequired(); Jvm.pause(200); wqueue.acquireAppender().writeText("hello world"); f.get();
int lastTailerCycle = -1; int lastQueueCycle = -1; Jvm.pause(random.nextInt(DELAY_READER_RANDOM_MS)); while (lastRead != expectedNumberOfMessages - 1) { try (DocumentContext dc = tailer.readingDocument()) {
@Test public void test() { File dir = getTmpDir(); try (final ChronicleQueue queue = SingleChronicleQueueBuilder.builder(dir, wireType) .testBlockSize() .build()) { final ExcerptTailer tailer = queue.createTailer(); assertFalse(tailer.readDocument(r -> r.read(TestKey.test).int32())); final ExcerptAppender appender = queue.acquireAppender(); appender.writeDocument(w -> w.write(TestKey.test).int32(1)); Jvm.pause(100); assertTrue(tailer.readDocument(r -> r.read(TestKey.test).int32())); } }
return; Jvm.pause(1);
void doPauseMS(long delayMS) { long start = System.nanoTime(); pausing.set(true); Jvm.pause(delayMS); pausing.set(false); long time = System.nanoTime() - start; timePaused += time; countPaused++; }
@Nullable private Bytes getFileContentsFromDisk(@NotNull Path path, Bytes using) { for (int i = 1; i <= 5; i++) { try { return getFileContentsFromDisk0(path, using); } catch (IOException e) { pause(i * i * 2); } } return null; }
@Override public void close() { root.notifyClosing(); Jvm.pause(50); // ensure that the event loop get shutdown first @Nullable EventLoop view = root().findView(EventLoop.class); Closeable.closeQuietly(view); root.close(); }