/** * Creates a new instance of the ContainerException class. * * @param containerId The Id of the ContainerException. * @param maxSegmentCount The maximum number of active Segments per container. */ public TooManyActiveSegmentsException(int containerId, int maxSegmentCount) { super(containerId, getMessage(maxSegmentCount)); }
Futures.failedFuture(new TooManyActiveSegmentsException(exceptionCounter.incrementAndGet(), 0))); ex -> ex instanceof TooManyActiveSegmentsException && ((TooManyActiveSegmentsException) ex).getContainerId() == exceptionCounter.get()); Assert.assertEquals("Unexpected number of attempts to map.", 2, exceptionCounter.get()); Assert.assertTrue("Cleanup was not invoked.", cleanupInvoked.get()); "Unexpected outcome when trying to map a Segment to a full metadata that cannot be cleaned.", () -> context.getMetadataStore().getOrAssignSegmentId(segmentNames.get(2), TIMEOUT), ex -> ex instanceof TooManyActiveSegmentsException && ((TooManyActiveSegmentsException) ex).getContainerId() == exceptionCounter.get()); Assert.assertEquals("Unexpected number of attempts to map.", 2, exceptionCounter.get()); Assert.assertTrue("Cleanup was not invoked.", cleanupInvoked.get()); return Futures.failedFuture(new TooManyActiveSegmentsException(exceptionCounter.incrementAndGet(), 0)); });
private void assignUniqueSegmentId(StreamSegmentMapOperation mapping) throws TooManyActiveSegmentsException { if (!this.recoveryMode) { if (getActiveSegmentCount() >= this.maximumActiveSegmentCount && !mapping.isPinned()) { throw new TooManyActiveSegmentsException(this.containerId, this.maximumActiveSegmentCount); } // Assign the SegmentId, but only in non-recovery mode and only if not already assigned. if (mapping.getStreamSegmentId() == ContainerMetadata.NO_STREAM_SEGMENT_ID) { mapping.setStreamSegmentId(generateUniqueSegmentId()); } } }