org.apache.ratis.util.CollectionUtils Java Examples
The following examples show how to use
org.apache.ratis.util.CollectionUtils.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GrpcClientProtocolClient.java From ratis with Apache License 2.0 | 6 votes |
CompletableFuture<RaftClientReply> onNext(RaftClientRequest request) { final Map<Long, CompletableFuture<RaftClientReply>> map = replies.get(); if (map == null) { return JavaUtils.completeExceptionally(new AlreadyClosedException(getName() + " is closed.")); } final CompletableFuture<RaftClientReply> f = new CompletableFuture<>(); CollectionUtils.putNew(request.getCallId(), f, map, () -> getName() + ":" + getClass().getSimpleName()); try { requestStreamObserver.onNext(ClientProtoUtils.toRaftClientRequestProto(request)); scheduler.onTimeout(requestTimeoutDuration, () -> timeoutCheck(request), LOG, () -> "Timeout check failed for client request: " + request); } catch(Throwable t) { handleReplyFuture(request.getCallId(), future -> future.completeExceptionally(t)); } return f; }
Example #2
Source File: RaftTestUtil.java From ratis with Apache License 2.0 | 5 votes |
static Iterable<LogEntryProto> getLogEntryProtos(RaftLog log) { return CollectionUtils.as(log.getEntries(0, Long.MAX_VALUE), ti -> { try { return log.get(ti.getIndex()); } catch (IOException exception) { throw new AssertionError("Failed to get log at " + ti, exception); } }); }
Example #3
Source File: FileInfo.java From incubator-ratis with Apache License 2.0 | 5 votes |
private CompletableFuture<Integer> submitWrite( CheckedSupplier<Integer, IOException> task, ExecutorService executor, RaftPeerId id, long index) { final CompletableFuture<Integer> f = writeQueue.submit(task, executor, e -> new IOException("Failed " + task, e)); final WriteInfo info = new WriteInfo(f, lastWriteIndex.getAndSet(index)); CollectionUtils.putNew(index, info, writeInfos, () -> id + ":writeInfos"); return f; }
Example #4
Source File: MiniRaftCluster.java From ratis with Apache License 2.0 | 5 votes |
public MiniRaftCluster initServers() { LOG.info("servers = " + servers); if (servers.isEmpty()) { putNewServers(CollectionUtils.as(group.getPeers(), RaftPeer::getId), true); } return this; }
Example #5
Source File: FileInfo.java From ratis with Apache License 2.0 | 5 votes |
private CompletableFuture<Integer> submitWrite( CheckedSupplier<Integer, IOException> task, ExecutorService executor, RaftPeerId id, long index) { final CompletableFuture<Integer> f = writeQueue.submit(task, executor, e -> new IOException("Failed " + task, e)); final WriteInfo info = new WriteInfo(f, lastWriteIndex.getAndSet(index)); CollectionUtils.putNew(index, info, writeInfos, () -> id + ":writeInfos"); return f; }
Example #6
Source File: RaftClientImpl.java From incubator-ratis with Apache License 2.0 | 5 votes |
void handleIOException(RaftClientRequest request, IOException ioe, RaftPeerId newLeader, Consumer<RaftClientRequest> handler) { LOG.debug("{}: suggested new leader: {}. Failed {} with {}", clientId, newLeader, request, ioe); if (LOG.isTraceEnabled()) { LOG.trace("Stack trace", new Throwable("TRACE")); } Optional.ofNullable(handler).ifPresent(h -> h.accept(request)); if (ioe instanceof LeaderNotReadyException || ioe instanceof ResourceUnavailableException) { return; } final RaftPeerId oldLeader = request.getServerId(); final RaftPeerId curLeader = leaderId; final boolean stillLeader = oldLeader.equals(curLeader); if (newLeader == null && stillLeader) { newLeader = CollectionUtils.random(oldLeader, CollectionUtils.as(peers, RaftPeer::getId)); } LOG.debug("{}: oldLeader={}, curLeader={}, newLeader={}", clientId, oldLeader, curLeader, newLeader); final boolean changeLeader = newLeader != null && stillLeader; final boolean reconnect = changeLeader || clientRpc.shouldReconnect(ioe); if (reconnect) { if (changeLeader && oldLeader.equals(leaderId)) { LOG.debug("{} {}: client change Leader from {} to {} ex={}", groupId, clientId, oldLeader, newLeader, ioe.getClass().getName()); this.leaderId = newLeader; } clientRpc.handleException(oldLeader, ioe, true); } }
Example #7
Source File: MiniRaftCluster.java From incubator-ratis with Apache License 2.0 | 5 votes |
public MiniRaftCluster initServers() { LOG.info("servers = " + servers); if (servers.isEmpty()) { putNewServers(CollectionUtils.as(group.getPeers(), RaftPeer::getId), true); } return this; }
Example #8
Source File: RaftTestUtil.java From incubator-ratis with Apache License 2.0 | 5 votes |
static Iterable<LogEntryProto> getLogEntryProtos(RaftLog log) { return CollectionUtils.as(log.getEntries(0, Long.MAX_VALUE), ti -> { try { return log.get(ti.getIndex()); } catch (IOException exception) { throw new AssertionError("Failed to get log at " + ti, exception); } }); }
Example #9
Source File: MiniRaftCluster.java From incubator-ratis with Apache License 2.0 | 4 votes |
public Iterable<RaftServerImpl> iterateServerImpls() { return CollectionUtils.as(getServers(), this::getRaftServerImpl); }
Example #10
Source File: MiniRaftCluster.java From ratis with Apache License 2.0 | 4 votes |
public Iterable<RaftServerImpl> iterateServerImpls() { return CollectionUtils.as(getServers(), this::getRaftServerImpl); }
Example #11
Source File: FileStore.java From ratis with Apache License 2.0 | 4 votes |
ReadOnly close(UnderConstruction uc) { LOG.trace("{}: close {}", name, uc.getRelativePath()); final ReadOnly ro = new ReadOnly(uc); CollectionUtils.replaceExisting(uc.getRelativePath(), uc, ro, map, name::toString); return ro; }
Example #12
Source File: FileStore.java From ratis with Apache License 2.0 | 4 votes |
void putNew(UnderConstruction uc) { LOG.trace("{}: putNew {}", name, uc.getRelativePath()); CollectionUtils.putNew(uc.getRelativePath(), uc, map, name::toString); }
Example #13
Source File: TestOzoneContainerRatis.java From hadoop-ozone with Apache License 2.0 | 4 votes |
private static void runTest( String testName, RpcType rpc, int numNodes, CheckedBiConsumer<Long, XceiverClientSpi, Exception> test) throws Exception { LOG.info("{}(rpc={}, numNodes={}", testName, rpc, numNodes); // create Ozone clusters final OzoneConfiguration conf = newOzoneConfiguration(); RatisTestHelper.initRatisConf(rpc, conf); final MiniOzoneCluster cluster = MiniOzoneCluster.newBuilder(conf) .setNumDatanodes(numNodes) .build(); try { cluster.waitForClusterToBeReady(); final String containerName = OzoneUtils.getRequestID(); final List<HddsDatanodeService> datanodes = cluster.getHddsDatanodes(); final Pipeline pipeline = MockPipeline.createPipeline( CollectionUtils.as(datanodes, HddsDatanodeService::getDatanodeDetails)); LOG.info("pipeline={}", pipeline); // Create Ratis cluster // final String ratisId = "ratis1"; // final PipelineManager manager = RatisManagerImpl.newRatisManager(conf); // manager.createPipeline(ratisId, pipeline.getNodes()); // LOG.info("Created RatisCluster " + ratisId); // // // check Ratis cluster members // final List<DatanodeDetails> dns = manager.getMembers(ratisId); // Assert.assertEquals(pipeline.getNodes(), dns); // // // run test // final XceiverClientSpi client = XceiverClientRatis // .newXceiverClientRatis( // pipeline, conf); // test.accept(containerName, client); } finally { cluster.shutdown(); } }
Example #14
Source File: GrpcClientProtocolClient.java From incubator-ratis with Apache License 2.0 | 4 votes |
synchronized CompletableFuture<RaftClientReply> putNew(long callId) { return Optional.ofNullable(map.get()) .map(m -> CollectionUtils.putNew(callId, new CompletableFuture<>(), m, this::toString)) .orElse(null); }
Example #15
Source File: GrpcClientProtocolService.java From incubator-ratis with Apache License 2.0 | 4 votes |
void removeExisting(OrderedRequestStreamObserver so) { CollectionUtils.removeExisting(so.getId(), so, map, () -> getClass().getSimpleName()); }
Example #16
Source File: GrpcClientProtocolService.java From incubator-ratis with Apache License 2.0 | 4 votes |
void putNew(OrderedRequestStreamObserver so) { CollectionUtils.putNew(so.getId(), so, map, () -> getClass().getSimpleName()); }
Example #17
Source File: FileStore.java From incubator-ratis with Apache License 2.0 | 4 votes |
ReadOnly close(UnderConstruction uc) { LOG.trace("{}: close {}", name, uc.getRelativePath()); final ReadOnly ro = new ReadOnly(uc); CollectionUtils.replaceExisting(uc.getRelativePath(), uc, ro, map, name::toString); return ro; }
Example #18
Source File: FileStore.java From incubator-ratis with Apache License 2.0 | 4 votes |
void putNew(UnderConstruction uc) { LOG.trace("{}: putNew {}", name, uc.getRelativePath()); CollectionUtils.putNew(uc.getRelativePath(), uc, map, name::toString); }