@Override public CompletableFuture<Void> createStreamSegment(String streamSegmentName, Collection<AttributeUpdate> attributes, Duration timeout) { if (this.segments.add(streamSegmentName)) { return CompletableFuture.completedFuture(null); } else { return Futures.failedFuture(new StreamSegmentExistsException(streamSegmentName)); } }
@Override public SegmentHandle create(String streamSegmentName) throws StreamSegmentException { ensurePreconditions(); synchronized (this.lock) { if (this.streamSegments.containsKey(streamSegmentName)) { throw new StreamSegmentExistsException(streamSegmentName); } StreamSegmentData data = new StreamSegmentData(streamSegmentName, this.syncContext); this.streamSegments.put(streamSegmentName, data); return data.openWrite(); } }
private <T> T throwException(String segmentName, Exception e) throws StreamSegmentException { if (e instanceof NoSuchFileException || e instanceof FileNotFoundException) { throw new StreamSegmentNotExistsException(segmentName); } if (e instanceof FileAlreadyExistsException) { throw new StreamSegmentExistsException(segmentName); } if (e instanceof IndexOutOfBoundsException) { throw new IllegalArgumentException(e.getMessage()); } if (e instanceof AccessControlException || e instanceof AccessDeniedException || e instanceof NonWritableChannelException) { throw new StreamSegmentSealedException(segmentName, e); } throw Exceptions.sneakyThrow(e); }
private <T> T throwException(String segmentName, Exception e) throws StreamSegmentException { if (e instanceof S3Exception) { S3Exception s3Exception = (S3Exception) e; String errorCode = Strings.nullToEmpty(s3Exception.getErrorCode()); if (errorCode.equals("NoSuchKey")) { throw new StreamSegmentNotExistsException(segmentName); } if (errorCode.equals("PreconditionFailed")) { throw new StreamSegmentExistsException(segmentName); } if (errorCode.equals("InvalidRange") || errorCode.equals("InvalidArgument") || errorCode.equals("MethodNotAllowed") || s3Exception.getHttpCode() == HttpStatus.SC_REQUESTED_RANGE_NOT_SATISFIABLE) { throw new IllegalArgumentException(segmentName, e); } if (errorCode.equals("AccessDenied")) { throw new StreamSegmentSealedException(segmentName, e); } } if (e instanceof IndexOutOfBoundsException) { throw new ArrayIndexOutOfBoundsException(e.getMessage()); } throw Exceptions.sneakyThrow(e); }
synchronized (this.internalIds) { if (this.internalIds.containsKey(logName)) { return Futures.failedFuture(new StreamSegmentExistsException(logName));
@Override public CompletableFuture<Void> createStreamSegment(String segmentName, Collection<AttributeUpdate> attributes, Duration timeout) { if (this.segment.get() != null) { return Futures.failedFuture(new StreamSegmentExistsException(segmentName)); } return CompletableFuture .runAsync(() -> { SegmentMock segment = this.segmentCreator.get(); Assert.assertTrue(this.segment.compareAndSet(null, segment)); }, executorService()) .thenCompose(v -> this.segment.get().updateAttributes(attributes == null ? Collections.emptyList() : attributes, timeout)); }
@Override public CompletableFuture<Void> createSegment(String segmentName, Duration timeout) { Exceptions.checkNotClosed(this.closed.get(), this); return CompletableFuture.runAsync(() -> { synchronized (this.tables) { if (this.tables.containsKey(segmentName)) { throw new CompletionException(new StreamSegmentExistsException(segmentName)); } this.tables.put(segmentName, new TableData(segmentName)); } }, this.executor); }
@Override protected CompletableFuture<Void> createSegment(String segmentName, ArrayView segmentInfo, TimeoutTimer timer) { ensureInitialized(); TableEntry entry = TableEntry.notExists(getTableKey(segmentName), segmentInfo); return this.tableStore .put(this.metadataSegmentName, Collections.singletonList(entry), timer.getRemaining()) .handle((ignored, ex) -> { if (ex != null) { if (Exceptions.unwrap(ex) instanceof BadKeyVersionException) { ex = new StreamSegmentExistsException(segmentName); } throw new CompletionException(ex); } return null; }); }
/** * Translates HDFS specific Exceptions to Pravega-equivalent Exceptions. * * @param segmentName Name of the stream segment on which the exception occurs. * @param e The exception to be translated. * @return The exception to be thrown. */ static <T> StreamSegmentException convertException(String segmentName, Throwable e) { if (e instanceof RemoteException) { e = ((RemoteException) e).unwrapRemoteException(); } if (e instanceof PathNotFoundException || e instanceof FileNotFoundException) { return new StreamSegmentNotExistsException(segmentName, e); } else if (e instanceof FileAlreadyExistsException || e instanceof AlreadyBeingCreatedException) { return new StreamSegmentExistsException(segmentName, e); } else if (e instanceof AclException) { return new StreamSegmentSealedException(segmentName, e); } else { throw Exceptions.sneakyThrow(e); } }
@Override public CompletableFuture<Void> createStream(String streamName, Duration timeout) { ensureRunning(); return CompletableFuture.runAsync(() -> { if (this.streamWriters.containsKey(streamName)) { throw new CompletionException(new StreamSegmentExistsException(streamName)); } StreamConfiguration config = StreamConfiguration .builder() .scalingPolicy(ScalingPolicy.fixed(this.testConfig.getSegmentsPerStream())) .build(); if (!getStreamManager().createStream(SCOPE, streamName, config)) { throw new CompletionException(new StreamingException(String.format("Unable to create Stream '%s'.", streamName))); } int writerCount = Math.max(1, this.testConfig.getProducerCount() / this.testConfig.getStreamCount()); List<EventStreamWriter<byte[]>> writers = new ArrayList<>(writerCount); if (this.streamWriters.putIfAbsent(streamName, writers) == null) { for (int i = 0; i < writerCount; i++) { writers.add(getClientFactory().createEventWriter(streamName, SERIALIZER, WRITER_CONFIG)); } } List<TransactionalEventStreamWriter<byte[]>> txnWriters = new ArrayList<>(writerCount); if (this.transactionalWriters.putIfAbsent(streamName, txnWriters) == null) { for (int i = 0; i < writerCount; i++) { txnWriters.add(getClientFactory().createTransactionalEventWriter(streamName, SERIALIZER, WRITER_CONFIG)); } } }, this.testExecutor); }
throw new StreamSegmentExistsException(segmentName);
/** * Creates a new Segment with given name. * * @param segmentName The case-sensitive Segment Name. * @param attributes The initial attributes for the StreamSegment, if any. * @param timeout Timeout for the operation. * @return A CompletableFuture that, when completed normally, will indicate the Segment has been created. * If the operation failed, this will contain the exception that caused the failure. Notable exceptions: * <ul> * <li>{@link StreamSegmentExistsException} If the Segment already exists. * </ul> */ CompletableFuture<Void> createSegment(String segmentName, Collection<AttributeUpdate> attributes, Duration timeout) { long traceId = LoggerHelpers.traceEnterWithContext(log, traceObjectId, "createSegment", segmentName); long segmentId = this.connector.containerMetadata.getStreamSegmentId(segmentName, true); if (isValidSegmentId(segmentId)) { // Quick fail: see if this is an active Segment, and if so, don't bother with anything else. return Futures.failedFuture(new StreamSegmentExistsException(segmentName)); } ArrayView segmentInfo = SegmentInfo.serialize(SegmentInfo.newSegment(segmentName, attributes)); CompletableFuture<Void> result = createSegment(segmentName, segmentInfo, new TimeoutTimer(timeout)); if (log.isTraceEnabled()) { result.thenAccept(v -> LoggerHelpers.traceLeave(log, traceObjectId, "createSegment", traceId, segmentName)); } return result; }
if (status != null && status.length > 1) { this.fileSystem.delete(fullPath, true); throw new StreamSegmentExistsException(streamSegmentName);
throw new StreamSegmentExistsException(streamSegmentName);