private void createChunk(RollingSegmentHandle handle) throws StreamSegmentException { // Create new active SegmentChunk, only after which serialize the handle update and update the handle. // We ignore if the SegmentChunk exists and is empty - that's most likely due to a previous failed attempt. long segmentLength = handle.length(); SegmentChunk newSegmentChunk = SegmentChunk.forSegment(handle.getSegmentName(), segmentLength); try { this.baseStorage.create(newSegmentChunk.getName()); } catch (StreamSegmentExistsException ex) { checkIfEmptyAndNotSealed(ex, newSegmentChunk.getName()); } serializeNewChunk(handle, newSegmentChunk); val activeHandle = this.baseStorage.openWrite(newSegmentChunk.getName()); handle.addChunk(newSegmentChunk, activeHandle); log.debug("Created new SegmentChunk '{}' for '{}'.", newSegmentChunk, handle); }