package org.apache.lucene.index; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import org.apache.lucene.index.IndexFileNames; import org.apache.lucene.index.IndexFileNameFilter; import org.apache.lucene.index.SegmentInfos; import org.apache.lucene.store.Directory; import java.io.IOException; import java.io.PrintStream; import java.util.Vector; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; /** * A utility class (used by both IndexReader and * IndexWriter) to keep track of files that need to be * deleted because they are no longer referenced by the * index. */ final class IndexFileDeleter { private Vector deletable; private HashSet pending; private Directory directory; private SegmentInfos segmentInfos; private PrintStream infoStream; IndexFileDeleter(SegmentInfos segmentInfos, Directory directory) throws IOException { this.segmentInfos = segmentInfos; this.directory = directory; } void setSegmentInfos(SegmentInfos segmentInfos) { this.segmentInfos = segmentInfos; } SegmentInfos getSegmentInfos() { return segmentInfos; } void setInfoStream(PrintStream infoStream) { this.infoStream = infoStream; } /** Determine index files that are no longer referenced * and therefore should be deleted. This is called once * (by the writer), and then subsequently we add onto * deletable any files that are no longer needed at the * point that we create the unused file (eg when merging * segments), and we only remove from deletable when a * file is successfully deleted. */ void findDeletableFiles() throws IOException { // Gather all "current" segments: HashMap current = new HashMap(); for(int j=0;j