private boolean compact ( ) throws IOException { try { final boolean sibEnabled = _dataArray . isSibEnabled ( ) ; _segTarget = _dataArray . getSegmentManager ( ) . nextSegment ( ) ; for ( Segment seg : _segSourceList ) { if ( ! _enabled ) { try { _updateManager . endUpdate ( _segTarget ) ; } catch ( Exception e ) { _log . warn ( "compact abort" , e ) ; } _log . info ( "ignored Segment " + seg . getSegmentId ( ) ) ; continue ; } try { if ( compact ( seg , _segTarget , sibEnabled ) ) { _compactedQueue . add ( seg ) ; } } catch ( Exception e ) { if ( _dataArray . isOpen ( ) ) { _ignoredSegs . add ( seg ) ; _log . error ( "failed to compact Segment " + seg . getSegmentId ( ) , e ) ; } } } // Mark target segment index buffer as dirty if sibEnabled is changed from true to false if ( sibEnabled && ! _dataArray . isSibEnabled ( ) ) { _dataArray . getSegmentManager ( ) . openSegmentIndexBuffer ( _segTarget . getSegmentId ( ) ) . markAsDirty ( ) ; } _targetQueue . add ( _segTarget ) ; _log . info ( "bytes transferred to " + _segTarget . getSegmentId ( ) + ": " + ( _segTarget . getAppendPosition ( ) - Segment . dataStartPosition ) ) ; } catch ( ConcurrentModificationException e1 ) { _segSourceList . clear ( ) ; return false ; } catch ( Exception e2 ) { _log . warn ( e2 . getMessage ( ) , e2 ) ; return false ; } _log . info ( "compact done" ) ; return true ; }
Compacts a number of source fragmented Segments by moving data into a new target Segment .