private void rollover ( RollingSegmentHandle handle ) throws StreamSegmentException { Preconditions . checkArgument ( handle . getHeaderHandle ( ) != null , "Cannot rollover a Segment with no header." ) ; Preconditions . checkArgument ( ! handle . isReadOnly ( ) , "Cannot rollover using a read-only handle." ) ; Preconditions . checkArgument ( ! handle . isSealed ( ) , "Cannot rollover a Sealed Segment." ) ; log . debug ( "Rolling over '{}'." , handle ) ; sealActiveChunk ( handle ) ; try { createChunk ( handle ) ; } catch ( StreamSegmentExistsException ex ) { // It may be possible that a concurrent rollover request using a different handle (either from this instance // or another) has already created the new chunk. Refresh the handle and try again. This is usually the case // with concurrent Storage instances trying to modify the same segment at the same time. int chunkCount = handle . chunks ( ) . size ( ) ; handle . refresh ( openHandle ( handle . getSegmentName ( ) , false ) ) ; if ( chunkCount == handle . chunks ( ) . size ( ) ) { // Nothing changed; re-throw the exception. throw ex ; } else { // We've just refreshed the handle and picked up the latest chunk. Move on. log . warn ( "Aborted rollover due to concurrent rollover detected ('{}')." , handle ) ; } } }
region SegmentChunk Operations