@Override public Statistics statistics() { return createStatistics(durations.stream().mapToLong(Duration::toNanos).summaryStatistics()); }
@Override public void cancelExecution(GroupName groupName) { try { theLock.lock(); threadGroups.stream() .filter(thg -> thg.getName().contains(groupName.asString())) .forEach(thg -> { List<Thread> tlist = getThreadList(thg); for (Thread t : tlist) { killThread(t); } threadGroups.remove(thg); }); } finally { theLock.unlock(); } }
private void onError(Map<byte[], RegionRequest> actionsByRegion, int tries, Throwable t, ServerName serverName) { Throwable error = translateException(t); logException(tries, () -> actionsByRegion.values().stream(), error, serverName); actionsByRegion.forEach( (rn, regionReq) -> conn.getLocator().updateCachedLocationOnError(regionReq.loc, error)); if (error instanceof DoNotRetryIOException || tries >= maxAttempts) { failAll(actionsByRegion.values().stream().flatMap(r -> r.actions.stream()), tries, error, serverName); return; } List<Action> copiedActions = actionsByRegion.values().stream().flatMap(r -> r.actions.stream()) .collect(Collectors.toList()); addError(copiedActions, error, serverName); tryResubmit(copiedActions.stream(), tries); }
queue.addAll(conflated.stream() .filter(ev -> !(ev instanceof DescriptionEvent)) .collect(Collectors.toList()));
conn.getLocator().updateCachedLocationOnError(regionReq.loc, error); if (error instanceof DoNotRetryIOException || tries >= maxAttempts) { failAll(regionReq.actions.stream(), tries, error, serverName); return;
tryResubmit(locateFailed.stream(), tries);
if (remainingNs <= 0) { failAll(actionsByServer.values().stream().flatMap(m -> m.actionsByRegion.values().stream()) .flatMap(r -> r.actions.stream()), tries); return;
private void onError(Map<byte[], RegionRequest> actionsByRegion, int tries, Throwable t, ServerName serverName) { Throwable error = translateException(t); logException(tries, () -> actionsByRegion.values().stream(), error, serverName); actionsByRegion .forEach((rn, regionReq) -> conn.getLocator().updateCachedLocation(regionReq.loc, error)); if (error instanceof DoNotRetryIOException || tries >= maxAttempts) { failAll(actionsByRegion.values().stream().flatMap(r -> r.actions.stream()), tries, error, serverName); return; } List<Action> copiedActions = actionsByRegion.values().stream().flatMap(r -> r.actions.stream()) .collect(Collectors.toList()); addError(copiedActions, error, serverName); tryResubmit(copiedActions.stream(), tries); }
conn.getLocator().updateCachedLocation(regionReq.loc, error); if (error instanceof DoNotRetryIOException || tries >= maxAttempts) { failAll(regionReq.actions.stream(), tries, error, serverName); return;
tryResubmit(locateFailed.stream(), tries);
if (remainingNs <= 0) { failAll(actionsByServer.values().stream().flatMap(m -> m.actionsByRegion.values().stream()) .flatMap(r -> r.actions.stream()), tries); return;
@Override public void close() { log.debug("Closing: " + toString()); tailers.stream().filter(Objects::nonNull).forEach(ChronicleLogTailer::close); tailers.clear(); partitions.stream().filter(Objects::nonNull).forEach(ChronicleQueue::close); partitions.clear(); closed = true; }
@Override public Statistics statistics() { return createStatistics(durations.stream().mapToLong(Duration::toNanos).summaryStatistics()); }
@VisibleForTesting List<Pair<T, CompletableFuture<Void>>> getEventQueueForKey(String key) { List<Pair<T, CompletableFuture<Void>>> retVal = null; synchronized (lock) { if (workers.containsKey(key)) { retVal = workers.get(key).stream().map(x -> new ImmutablePair<>(x.getEvent(), x.getResult())).collect(Collectors.toList()); } } return retVal; }
private boolean tryRemoveFromQueue(JobId jobId) { return jobQueue.stream() .filter(queuedJob -> queuedJob.getId().equals(jobId)) .findFirst() .map(this::tryRemove) .orElse(false); }
@Override public void run() { while(true) { final ConcurrentLinkedQueue<String> stringsToLog = new ConcurrentLinkedQueue<>(); synchronized (logsToFile) { if (logsToFile.isEmpty()) { try { logsToFile.wait(); } catch (InterruptedException e) { return; } if (logsToFile.isEmpty()) { continue; } } stringsToLog.addAll(logsToFile); logsToFile.clear(); } stringsToLog.stream().forEach(logginFile::println); logginFile.flush(); } } }
@Override public void close() { log.debug("Closing appender: " + name); tailers.stream().filter(Objects::nonNull).forEach(tailer -> { try { tailer.close(); } catch (Exception e) { log.error("Failed to close tailer: " + tailer); } }); tailers.clear(); if (producer != null) { producer.close(); producer = null; } closed = true; } }
private void onError(Map<byte[], RegionRequest> actionsByRegion, int tries, Throwable t, ServerName serverName) { Throwable error = translateException(t); logException(tries, () -> actionsByRegion.values().stream(), error, serverName); actionsByRegion .forEach((rn, regionReq) -> conn.getLocator().updateCachedLocation(regionReq.loc, error)); if (error instanceof DoNotRetryIOException || tries >= maxAttempts) { failAll(actionsByRegion.values().stream().flatMap(r -> r.actions.stream()), tries, error, serverName); return; } List<Action> copiedActions = actionsByRegion.values().stream().flatMap(r -> r.actions.stream()) .collect(Collectors.toList()); addError(copiedActions, error, serverName); tryResubmit(copiedActions.stream(), tries); }
@Test public void putIfAbsentTestConcurrent() throws Exception { getDefaultRuntime(); PutIfAbsentMap<String, String> stringMap = getRuntime().getObjectsView().build() .setStreamName("stringMap") .setType(PutIfAbsentMap.class) .open(); ConcurrentLinkedQueue<Boolean> resultList = new ConcurrentLinkedQueue<>(); scheduleConcurrently(PARAMETERS.NUM_ITERATIONS_LOW, x -> { resultList.add(stringMap.putIfAbsent("a", Integer.toString(x))); }); executeScheduled(PARAMETERS.CONCURRENCY_SOME, PARAMETERS.TIMEOUT_LONG); long trueCount = resultList.stream() .filter(x -> x) .count(); assertThat(trueCount) .isEqualTo(1); }
static void runTestTransactionContextIsPassedBack(MiniRaftCluster cluster) throws Throwable { // tests that the TrxContext set by the StateMachine in Leader is passed back to the SM int numTrx = 100; final RaftTestUtil.SimpleMessage[] messages = RaftTestUtil.SimpleMessage.create(numTrx); try(final RaftClient client = cluster.createClient()) { for (RaftTestUtil.SimpleMessage message : messages) { client.send(message); } } // TODO: there eshould be a better way to ensure all data is replicated and applied Thread.sleep(cluster.getMaxTimeout() + 100); for (RaftServerImpl raftServer : cluster.iterateServerImpls()) { final SMTransactionContext sm = SMTransactionContext.get(raftServer); sm.rethrowIfException(); assertEquals(numTrx, sm.numApplied.get()); } // check leader RaftServerImpl raftServer = cluster.getLeader(); // assert every transaction has obtained context in leader final SMTransactionContext sm = SMTransactionContext.get(raftServer); List<Long> ll = sm.applied.stream().collect(Collectors.toList()); Collections.sort(ll); assertEquals(ll.toString(), ll.size(), numTrx); for (int i=0; i < numTrx; i++) { assertEquals(ll.toString(), Long.valueOf(i+1), ll.get(i)); } }