You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by bbende <gi...@git.apache.org> on 2016/09/06 15:44:47 UTC

[GitHub] nifi pull request #958: NIFI-2681: Refactored IndexManager into an interface...

Github user bbende commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/958#discussion_r77661605
  
    --- Diff: nifi-nar-bundles/nifi-provenance-repository-bundle/nifi-persistent-provenance-repository/src/main/java/org/apache/nifi/provenance/lucene/CachingIndexManager.java ---
    @@ -0,0 +1,535 @@
    +/*
    + * 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.
    + */
    +package org.apache.nifi.provenance.lucene;
    +
    +import java.io.Closeable;
    +import java.io.File;
    +import java.io.IOException;
    +import java.util.ArrayList;
    +import java.util.HashMap;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.Map;
    +import java.util.concurrent.atomic.AtomicInteger;
    +import java.util.concurrent.locks.Lock;
    +import java.util.concurrent.locks.ReentrantLock;
    +
    +import org.apache.lucene.analysis.Analyzer;
    +import org.apache.lucene.analysis.standard.StandardAnalyzer;
    +import org.apache.lucene.index.DirectoryReader;
    +import org.apache.lucene.index.IndexWriter;
    +import org.apache.lucene.index.IndexWriterConfig;
    +import org.apache.lucene.search.IndexSearcher;
    +import org.apache.lucene.store.Directory;
    +import org.apache.lucene.store.FSDirectory;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +public class CachingIndexManager implements Closeable, IndexManager {
    +    private static final Logger logger = LoggerFactory.getLogger(CachingIndexManager.class);
    +
    +    private final Lock lock = new ReentrantLock();
    +    private final Map<File, IndexWriterCount> writerCounts = new HashMap<>();
    +    private final Map<File, List<ActiveIndexSearcher>> activeSearchers = new HashMap<>();
    +
    +
    +    public void removeIndex(final File indexDirectory) {
    +        final File absoluteFile = indexDirectory.getAbsoluteFile();
    +        logger.info("Removing index {}", indexDirectory);
    +
    +        lock.lock();
    +        try {
    +            final IndexWriterCount count = writerCounts.remove(absoluteFile);
    +            if ( count != null ) {
    +                try {
    +                    count.close();
    +                } catch (final IOException ioe) {
    +                    logger.warn("Failed to close Index Writer {} for {}", count.getWriter(), absoluteFile);
    +                    if ( logger.isDebugEnabled() ) {
    +                        logger.warn("", ioe);
    +                    }
    +                }
    +            }
    +
    +            for ( final List<ActiveIndexSearcher> searcherList : activeSearchers.values() ) {
    --- End diff --
    
    Wouldn't we want to get the List<ActiveIndexSearcher> for the absoluteFile, rather than every active searcher? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---