org.neo4j.kernel.api.index
Class SchemaIndexProvider
java.lang.Object
org.neo4j.kernel.lifecycle.LifecycleAdapter
org.neo4j.kernel.api.index.SchemaIndexProvider
- All Implemented Interfaces:
- Comparable<SchemaIndexProvider>, Lifecycle
public abstract class SchemaIndexProvider
- extends LifecycleAdapter
- implements Comparable<SchemaIndexProvider>
Contract for implementing an index in Neo4j.
This is a sensitive thing to implement, because it manages data that is controlled by
Neo4js logical log. As such, the implementation needs to behave under some rather strict rules.
Populating the index
When an index rule is added, the IndexingService
is notified. It will, in turn, ask
your SchemaIndexProvider
for a batch index writer
.
A background index job is triggered, and all existing data that applies to the new rule, as well as new data
from the "outside", will be inserted using the writer. You are guaranteed that usage of this writer,
during population, will be single threaded.
These are the rules you must adhere to here:
- You CANNOT say that the state of the index is
InternalIndexState.ONLINE
- You MUST store all updates given to you
- You MAY persistently store the updates
The Flip
Once population is done, the index needs to be "flipped" to an online mode of operation.
The index will be notified, through the IndexPopulator.close(boolean)
method, that population is done, and that the index should turn it's state to InternalIndexState.ONLINE
or
InternalIndexState.FAILED
depending on the value given to the
close method
.
If the index is persisted to disk, this is a vital part of the index lifecycle.
For a persisted index, the index MUST NOT store the state as online unless it first guarantees that the entire index
is flushed to disk. Failure to do so could produce a situation where, after a crash,
an index is believed to be online
when it in fact was not yet fully populated. This would break the database recovery process.
If you are implementing this interface, you can choose to not store index state. In that case,
you should report index state as InternalIndexState.POPULATING
upon startup.
This will cause the database to re-create the index from scratch again.
These are the rules you must adhere to here:
Online operation
Once the index is online, the database will move to using the online accessor
to
write to the index.
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
NO_INDEX_PROVIDER
public static final SchemaIndexProvider NO_INDEX_PROVIDER
HIGHEST_PRIORITIZED_OR_NONE
public static final DependencyResolver.SelectionStrategy<SchemaIndexProvider> HIGHEST_PRIORITIZED_OR_NONE
SchemaIndexProvider
protected SchemaIndexProvider(int priority)
getPopulator
public abstract IndexPopulator getPopulator(long indexId)
- Used for initially populating a created index, using batch insertion.
getOnlineAccessor
public abstract IndexAccessor getOnlineAccessor(long indexId)
- Used for updating an index once initial population has completed.
getInitialState
public abstract InternalIndexState getInitialState(long indexId)
- Called during startup to find out which state an index is in.
compareTo
public int compareTo(SchemaIndexProvider o)
- Specified by:
compareTo
in interface Comparable<SchemaIndexProvider>
getRootDirectory
protected File getRootDirectory(Config config,
String key)
Copyright © 2002-2013 The Neo4j Graph Database Project. All Rights Reserved.