Skip to content

Commit

Permalink
Cleanups after review
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Dec 6, 2016
1 parent 48cedb6 commit d1c4a79
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 34 deletions.
Expand Up @@ -30,9 +30,8 @@
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import java.util.stream.Stream;


import org.neo4j.graphdb.ResourceIterator; import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.helpers.ArrayUtil; import org.neo4j.helpers.ArrayUtil;
Expand Down Expand Up @@ -60,6 +59,8 @@ public abstract class AbstractLuceneIndex
{ {
protected final PartitionedIndexStorage indexStorage; protected final PartitionedIndexStorage indexStorage;
private final IndexPartitionFactory partitionFactory; private final IndexPartitionFactory partitionFactory;
// Note that we rely on the thread-safe internal snapshot feature of the CopyOnWriteArrayList
// for the thread-safety of this and derived classes.
private CopyOnWriteArrayList<AbstractIndexPartition> partitions = new CopyOnWriteArrayList<>(); private CopyOnWriteArrayList<AbstractIndexPartition> partitions = new CopyOnWriteArrayList<>();
private volatile boolean open; private volatile boolean open;


Expand Down Expand Up @@ -93,33 +94,16 @@ public void create() throws IOException
*/ */
public void open() throws IOException public void open() throws IOException
{ {
Stream<Map.Entry<File,Directory>> indexDirectories = indexStorage.openIndexDirectories().entrySet().stream(); Set<Map.Entry<File,Directory>> indexDirectories = indexStorage.openIndexDirectories().entrySet();
List<AbstractIndexPartition> list = null; List<AbstractIndexPartition> list = new ArrayList<>( indexDirectories.size() );
try for ( Map.Entry<File,Directory> entry : indexDirectories )
{
list = indexDirectories.map( e -> createPartition( e.getKey(), e.getValue() ) )
.collect( Collectors.toList() );
}
catch ( UncheckedIOException e )
{ {
throw e.getCause(); list.add( partitionFactory.createPartition( entry.getKey(), entry.getValue() ) );
} }
partitions.addAll( list ); partitions.addAll( list );
open = true; open = true;
} }


private AbstractIndexPartition createPartition( File key, Directory value )
{
try
{
return partitionFactory.createPartition( key, value );
}
catch ( IOException e )
{
throw new UncheckedIOException( e );
}
}

public boolean isOpen() public boolean isOpen()
{ {
return open; return open;
Expand Down Expand Up @@ -221,9 +205,8 @@ public void flush() throws IOException
public void close() throws IOException public void close() throws IOException
{ {
open = false; open = false;
List<AbstractIndexPartition> partitionsCopy = new ArrayList<>( partitions ); IOUtils.closeAll( partitions );
partitions.clear(); partitions.clear();
IOUtils.closeAll( partitionsCopy );
} }


/** /**
Expand Down
Expand Up @@ -44,15 +44,7 @@ public WritableDatabaseLabelScanIndex( BitmapDocumentFormat format, PartitionedI
@Override @Override
public LabelScanReader getLabelScanReader() public LabelScanReader getLabelScanReader()
{ {
// partitionsLock.lock(); return luceneIndex.getLabelScanReader();
try
{
return luceneIndex.getLabelScanReader();
}
finally
{
// partitionsLock.unlock();
}
} }


@Override @Override
Expand Down

0 comments on commit d1c4a79

Please sign in to comment.