コード例 #1
0
        public virtual SegmentFile Prune(long pruneIndex)
        {
            lock (this)
            {
                IEnumerator <SegmentFile> itr = _allSegments.GetEnumerator();
//JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops:
                SegmentFile notDisposed    = itr.next();                // we should always leave at least one segment
                int         firstRemaining = 0;

                while (itr.MoveNext())
                {
                    SegmentFile current = itr.Current;
                    if (current.Header().prevFileLastIndex() > pruneIndex)
                    {
                        break;
                    }

                    if (!notDisposed.TryClose())
                    {
                        break;
                    }

                    _log.info("Pruning %s", notDisposed);
                    if (!notDisposed.Delete())
                    {
                        _log.error("Failed to delete %s", notDisposed);
                        break;
                    }

                    // TODO: Sync the parent directory. Also consider handling fs operations under its own lock.

                    firstRemaining++;
                    notDisposed = current;
                }

                _rangeMap.remove(notDisposed.Header().prevIndex() + 1);
                _allSegments.RemoveRange(0, firstRemaining);

                return(notDisposed);
            }
        }