Skip to content

Commit

Permalink
Break out DropAction into separate class IndexDropAction
Browse files Browse the repository at this point in the history
To be used by GenericNativeIndex
  • Loading branch information
burqen committed Mar 7, 2019
1 parent 611f08a commit 4c7283b
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 64 deletions.
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.index.schema;

import java.io.IOException;
import java.io.UncheckedIOException;

import org.neo4j.io.fs.FileSystemAbstraction;
import org.neo4j.kernel.api.index.IndexDirectoryStructure;

import static org.neo4j.kernel.impl.index.schema.NativeIndexes.deleteIndex;

public class FileSystemIndexDropAction implements IndexDropAction
{
private final FileSystemAbstraction fs;
private final IndexDirectoryStructure directoryStructure;

public FileSystemIndexDropAction( FileSystemAbstraction fs, IndexDirectoryStructure directoryStructure )
{
this.fs = fs;
this.directoryStructure = directoryStructure;
}

@Override
public void drop( long indexId, boolean archiveExistentIndex )
{
try
{
deleteIndex( fs, directoryStructure, indexId, archiveExistentIndex );
}
catch ( IOException e )
{
throw new UncheckedIOException( e );
}
}
}
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2002-2019 "Neo4j,"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.neo4j.kernel.impl.index.schema;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;

@FunctionalInterface
public
interface IndexDropAction
{
/**
* Deletes the index directory and everything in it, as last part of dropping an index.
* Can be configured to create archive with content of index directories for future analysis.
*
* @param indexId the index id, for which directory to drop.
* @param archiveExistentIndex create archive with content of dropped directories
* @see GraphDatabaseSettings#archive_failed_index
*/
void drop( long indexId, boolean archiveExistentIndex );

/**
* Deletes the index directory and everything in it, as last part of dropping an index.
*
* @param indexId the index id, for which directory to drop.
*/
default void drop( long indexId )
{
drop( indexId, false );
}
}
Expand Up @@ -29,9 +29,9 @@
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexAccessor;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.storageengine.api.NodePropertyAccessor;
import org.neo4j.kernel.impl.api.index.IndexUpdateMode;
import org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider.DropAction;
import org.neo4j.kernel.impl.index.schema.IndexDropAction;
import org.neo4j.storageengine.api.NodePropertyAccessor;
import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.storageengine.api.schema.StoreIndexDescriptor;
import org.neo4j.values.storable.Value;
Expand All @@ -41,12 +41,12 @@
class FusionIndexAccessor extends FusionIndexBase<IndexAccessor> implements IndexAccessor
{
private final StoreIndexDescriptor descriptor;
private final DropAction dropAction;
private final IndexDropAction dropAction;

FusionIndexAccessor( SlotSelector slotSelector,
InstanceSelector<IndexAccessor> instanceSelector,
StoreIndexDescriptor descriptor,
DropAction dropAction )
IndexDropAction dropAction )
{
super( slotSelector, instanceSelector );
this.descriptor = descriptor;
Expand Down
Expand Up @@ -26,19 +26,19 @@
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.impl.index.schema.IndexDropAction;
import org.neo4j.storageengine.api.NodePropertyAccessor;
import org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider.DropAction;
import org.neo4j.storageengine.api.schema.IndexSample;

import static org.neo4j.kernel.impl.index.schema.fusion.FusionIndexSampler.combineSamples;

class FusionIndexPopulator extends FusionIndexBase<IndexPopulator> implements IndexPopulator
{
private final long indexId;
private final DropAction dropAction;
private final IndexDropAction dropAction;
private final boolean archiveFailedIndex;

FusionIndexPopulator( SlotSelector slotSelector, InstanceSelector<IndexPopulator> instanceSelector, long indexId, DropAction dropAction,
FusionIndexPopulator( SlotSelector slotSelector, InstanceSelector<IndexPopulator> instanceSelector, long indexId, IndexDropAction dropAction,
boolean archiveFailedIndex )
{
super( slotSelector, instanceSelector );
Expand Down
Expand Up @@ -20,11 +20,9 @@
package org.neo4j.kernel.impl.index.schema.fusion;

import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.EnumMap;
import java.util.List;

import org.neo4j.graphdb.factory.GraphDatabaseSettings;
import org.neo4j.helpers.collection.Iterables;
import org.neo4j.internal.kernel.api.IndexCapability;
import org.neo4j.internal.kernel.api.IndexOrder;
Expand All @@ -37,14 +35,15 @@
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.api.index.IndexProvider;
import org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig;
import org.neo4j.kernel.impl.index.schema.FileSystemIndexDropAction;
import org.neo4j.kernel.impl.index.schema.IndexDropAction;
import org.neo4j.kernel.impl.newapi.UnionIndexCapability;
import org.neo4j.kernel.impl.storemigration.StoreMigrationParticipant;
import org.neo4j.storageengine.api.schema.StoreIndexDescriptor;
import org.neo4j.values.storable.ValueCategory;

import static org.neo4j.internal.kernel.api.InternalIndexState.FAILED;
import static org.neo4j.internal.kernel.api.InternalIndexState.POPULATING;
import static org.neo4j.kernel.impl.index.schema.NativeIndexes.deleteIndex;
import static org.neo4j.kernel.impl.index.schema.fusion.IndexSlot.LUCENE;
import static org.neo4j.kernel.impl.index.schema.fusion.IndexSlot.NUMBER;
import static org.neo4j.kernel.impl.index.schema.fusion.IndexSlot.SPATIAL;
Expand All @@ -60,7 +59,7 @@ public class FusionIndexProvider extends IndexProvider
private final boolean archiveFailedIndex;
private final InstanceSelector<IndexProvider> providers;
private final SlotSelector slotSelector;
private final DropAction dropAction;
private final IndexDropAction dropAction;

public FusionIndexProvider(
// good to be strict with specific providers here since this is dev facing
Expand All @@ -79,7 +78,7 @@ public FusionIndexProvider(
this.archiveFailedIndex = archiveFailedIndex;
this.slotSelector = slotSelector;
this.providers = new InstanceSelector<>();
this.dropAction = new FileSystemDropAction( fs, directoryStructure() );
this.dropAction = new FileSystemIndexDropAction( fs, directoryStructure() );
fillProvidersSelector( stringProvider, numberProvider, spatialProvider, temporalProvider, luceneProvider );
slotSelector.validateSatisfied( providers );
}
Expand Down Expand Up @@ -182,52 +181,4 @@ public StoreMigrationParticipant storeMigrationParticipant( FileSystemAbstractio
return StoreMigrationParticipant.NOT_PARTICIPATING;
}

@FunctionalInterface
interface DropAction
{
/**
* Deletes the index directory and everything in it, as last part of dropping an index.
* Can be configured to create archive with content of index directories for future analysis.
*
* @param indexId the index id, for which directory to drop.
* @param archiveExistentIndex create archive with content of dropped directories
* @see GraphDatabaseSettings#archive_failed_index
*/
void drop( long indexId, boolean archiveExistentIndex );

/**
* Deletes the index directory and everything in it, as last part of dropping an index.
*
* @param indexId the index id, for which directory to drop.
*/
default void drop( long indexId )
{
drop( indexId, false );
}
}

private static class FileSystemDropAction implements DropAction
{
private final FileSystemAbstraction fs;
private final IndexDirectoryStructure directoryStructure;

FileSystemDropAction( FileSystemAbstraction fs, IndexDirectoryStructure directoryStructure )
{
this.fs = fs;
this.directoryStructure = directoryStructure;
}

@Override
public void drop( long indexId, boolean archiveExistentIndex )
{
try
{
deleteIndex( fs, directoryStructure, indexId, archiveExistentIndex );
}
catch ( IOException e )
{
throw new UncheckedIOException( e );
}
}
}
}
Expand Up @@ -41,7 +41,7 @@
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.schema.SchemaDescriptorFactory;
import org.neo4j.kernel.impl.api.index.IndexUpdateMode;
import org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider.DropAction;
import org.neo4j.kernel.impl.index.schema.IndexDropAction;
import org.neo4j.storageengine.api.schema.IndexDescriptorFactory;
import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.storageengine.api.schema.StoreIndexDescriptor;
Expand Down Expand Up @@ -83,7 +83,7 @@ public class FusionIndexAccessorTest
{
private FusionIndexAccessor fusionIndexAccessor;
private final long indexId = 0;
private final DropAction dropAction = mock( DropAction.class );
private final IndexDropAction dropAction = mock( IndexDropAction.class );
private EnumMap<IndexSlot,IndexAccessor> accessors;
private IndexAccessor[] aliveAccessors;
private StoreIndexDescriptor indexDescriptor =
Expand Down
Expand Up @@ -36,7 +36,7 @@
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.index.IndexEntryUpdate;
import org.neo4j.kernel.api.index.IndexPopulator;
import org.neo4j.kernel.impl.index.schema.fusion.FusionIndexProvider.DropAction;
import org.neo4j.kernel.impl.index.schema.IndexDropAction;
import org.neo4j.values.storable.Value;

import static org.junit.Assert.fail;
Expand Down Expand Up @@ -69,7 +69,7 @@ public class FusionIndexPopulatorTest
private EnumMap<IndexSlot,IndexPopulator> populators;
private FusionIndexPopulator fusionIndexPopulator;
private final long indexId = 8;
private final DropAction dropAction = mock( DropAction.class );
private final IndexDropAction dropAction = mock( IndexDropAction.class );

@Parameterized.Parameters( name = "{0}" )
public static FusionVersion[] versions()
Expand Down

0 comments on commit 4c7283b

Please sign in to comment.