@SuppressWarnings("unchecked") @SneakyThrows(ConnectionFailedException.class) private <T extends Reply> T transformReply(Reply reply, Class<T> klass) { if (klass.isAssignableFrom(reply.getClass())) { return (T) reply; } closeConnection(reply); if (reply instanceof WireCommands.NoSuchSegment) { throw new NoSuchSegmentException(reply.toString()); } else if (reply instanceof WrongHost) { throw new ConnectionFailedException(reply.toString()); } else { throw new ConnectionFailedException("Unexpected reply of " + reply + " when expecting a " + klass.getName()); } }
@Override public Void answer(InvocationOnMock invocation) throws Throwable { PendingEvent event = (PendingEvent) invocation.getArgument(0); event.getAckFuture().completeExceptionally(new NoSuchSegmentException("segment")); return null; } }).when(outputStream).write(Mockito.any(PendingEvent.class));
private RuntimeException handelUnexpectedReply(Reply reply) { closeConnection(reply.toString()); if (reply instanceof WireCommands.NoSuchSegment) { throw new NoSuchSegmentException(reply.toString()); } else if (reply instanceof SegmentIsSealed) { throw Exceptions.sneakyThrow(new SegmentSealedException(reply.toString())); } else if (reply instanceof WrongHost) { throw Exceptions.sneakyThrow(new ConnectionFailedException(reply.toString())); } else { throw Exceptions.sneakyThrow(new ConnectionFailedException("Unexpected reply of " + reply + " when expecting an AppendSetup")); } }
public List<PendingEvent> refreshSegmentEventWritersUponSealed(Segment sealedSegment, Consumer<Segment> segmentSealedCallback) { StreamSegmentsWithPredecessors successors = Futures.getAndHandleExceptions( controller.getSuccessors(sealedSegment), t -> { log.error("Error while fetching successors for segment: {}", sealedSegment, t); return null; }); if (successors == null) { // Stream is deleted, complete all pending writes exceptionally. log.error("Stream is deleted, all pending writes will be completed exceptionally"); removeAllWriters().forEach(event -> event.getAckFuture() .completeExceptionally(new NoSuchSegmentException(sealedSegment.toString()))); return Collections.emptyList(); } else { return updateSegmentsUponSealed(successors, sealedSegment, segmentSealedCallback); } }
@Override public void noSuchSegment(NoSuchSegment noSuchSegment) { final String segment = noSuchSegment.getSegment(); if (StreamSegmentNameUtils.isTransactionSegment(segment)) { log.info("Transaction Segment: {} no longer exists since the txn is aborted. {}", noSuchSegment.getSegment(), noSuchSegment.getServerStackTrace()); //close the connection and update the exception to SegmentSealed. state.failConnection(new SegmentSealedException(segment)); } else { state.failConnection(new NoSuchSegmentException(segment)); log.info("Segment being written to {} by writer {} no longer exists due to Stream Truncation, resending to the newer segment. {}", noSuchSegment.getSegment(), writerId, noSuchSegment.getServerStackTrace()); invokeResendCallBack(noSuchSegment); } }