
org.neo4j.kernel.impl.api.index.PopulatingIndexProxy Maven / Gradle / Ivy
/*
* Copyright (c) 2002-2016 "Neo Technology,"
* Network Engine for Objects in Lund AB [http://neotechnology.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 .
*/
package org.neo4j.kernel.impl.api.index;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.Future;
import org.neo4j.collection.primitive.PrimitiveLongSet;
import org.neo4j.graphdb.ResourceIterator;
import org.neo4j.graphdb.index.IndexPopulationProgress;
import org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException;
import org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException;
import org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException;
import org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException;
import org.neo4j.kernel.api.index.IndexConfiguration;
import org.neo4j.kernel.api.index.IndexDescriptor;
import org.neo4j.kernel.api.index.IndexUpdater;
import org.neo4j.kernel.api.index.InternalIndexState;
import org.neo4j.kernel.api.index.NodePropertyUpdate;
import org.neo4j.kernel.api.index.SchemaIndexProvider;
import org.neo4j.storageengine.api.schema.IndexReader;
import org.neo4j.storageengine.api.schema.PopulationProgress;
import static org.neo4j.helpers.collection.IteratorUtil.emptyIterator;
public class PopulatingIndexProxy implements IndexProxy
{
private final IndexDescriptor descriptor;
private final SchemaIndexProvider.Descriptor providerDescriptor;
private final IndexConfiguration configuration;
private final IndexPopulationJob job;
public PopulatingIndexProxy( IndexDescriptor descriptor,
IndexConfiguration configuration,
SchemaIndexProvider.Descriptor providerDescriptor,
IndexPopulationJob job )
{
this.descriptor = descriptor;
this.configuration = configuration;
this.providerDescriptor = providerDescriptor;
this.job = job;
}
@Override
public void start()
{
}
@Override
public IndexUpdater newUpdater( final IndexUpdateMode mode )
{
switch ( mode )
{
case ONLINE:
case RECOVERY:
return new PopulatingIndexUpdater()
{
@Override
public void process( NodePropertyUpdate update ) throws IOException, IndexEntryConflictException
{
job.update( update );
}
};
default:
return new PopulatingIndexUpdater()
{
@Override
public void process( NodePropertyUpdate update ) throws IOException, IndexEntryConflictException
{
throw new IllegalArgumentException( "Unsupported update mode: " + mode );
}
};
}
}
@Override
public Future drop()
{
return job.cancel();
}
@Override
public IndexDescriptor getDescriptor()
{
return descriptor;
}
@Override
public SchemaIndexProvider.Descriptor getProviderDescriptor()
{
return providerDescriptor;
}
@Override
public InternalIndexState getState()
{
return InternalIndexState.POPULATING;
}
@Override
public void force()
{
// Ignored... this isn't controlled from the outside while we're populating the index.
}
@Override
public void flush() throws IOException
{
// Ignored... this isn't controlled from the outside while we're populating the index.
}
@Override
public Future close()
{
return job.cancel();
}
@Override
public IndexReader newReader() throws IndexNotFoundKernelException
{
throw new IndexNotFoundKernelException( "Index is still populating: " + job );
}
@Override
public boolean awaitStoreScanCompleted() throws IndexPopulationFailedKernelException, InterruptedException
{
job.awaitCompletion();
return true;
}
@Override
public void activate() throws IndexActivationFailedKernelException
{
throw new IllegalStateException( "Cannot activate index while it is still populating: " + job );
}
@Override
public void validate()
{
throw new IllegalStateException( "Cannot validate index while it is still populating: " + job );
}
@Override
public ResourceIterator snapshotFiles()
{
return emptyIterator();
}
@Override
public IndexPopulationFailure getPopulationFailure() throws IllegalStateException
{
throw new IllegalStateException( this + " is POPULATING" );
}
@Override
public PopulationProgress getIndexPopulationProgress()
{
return job.getPopulationProgress();
}
@Override
public IndexConfiguration config()
{
return configuration;
}
@Override
public String toString()
{
return getClass().getSimpleName() + "[job:" + job + "]";
}
private abstract class PopulatingIndexUpdater implements IndexUpdater
{
@Override
public void close() throws IOException, IndexEntryConflictException
{
}
@Override
public void remove( PrimitiveLongSet nodeIds )
{
throw new UnsupportedOperationException( "Should not remove() from populating index." );
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy