use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class NeoStoreDataSource method start.
@Override
public void start() throws IOException {
dependencies = new Dependencies();
life = new LifeSupport();
schemaIndexProvider = dependencyResolver.resolveDependency(SchemaIndexProvider.class, HighestSelectionStrategy.getInstance());
labelScanStoreProvider = dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new NamedLabelScanStoreSelectionStrategy(config));
dependencyResolver.resolveDependency(LabelScanStoreProvider.class, new DeleteStoresFromOtherLabelScanStoreProviders(labelScanStoreProvider));
IndexConfigStore indexConfigStore = new IndexConfigStore(storeDir, fs);
dependencies.satisfyDependency(lockService);
dependencies.satisfyDependency(indexConfigStore);
life.add(indexConfigStore);
// Monitor listeners
LoggingLogFileMonitor loggingLogMonitor = new LoggingLogFileMonitor(msgLog);
monitors.addMonitorListener(loggingLogMonitor);
life.add(new Delegate(Lifecycles.multiple(indexProviders.values())));
// Upgrade the store before we begin
RecordFormats formats = selectStoreFormats(config, storeDir, fs, pageCache, logService);
upgradeStore(formats);
// Build all modules and their services
StorageEngine storageEngine = null;
try {
UpdateableSchemaState updateableSchemaState = new KernelSchemaStateStore(logProvider);
SynchronizedArrayIdOrderingQueue legacyIndexTransactionOrdering = new SynchronizedArrayIdOrderingQueue(20);
storageEngine = buildStorageEngine(propertyKeyTokenHolder, labelTokens, relationshipTypeTokens, legacyIndexProviderLookup, indexConfigStore, updateableSchemaState::clear, legacyIndexTransactionOrdering);
LogEntryReader<ReadableClosablePositionAwareChannel> logEntryReader = new VersionAwareLogEntryReader<>(storageEngine.commandReaderFactory());
TransactionIdStore transactionIdStore = dependencies.resolveDependency(TransactionIdStore.class);
LogVersionRepository logVersionRepository = dependencies.resolveDependency(LogVersionRepository.class);
NeoStoreTransactionLogModule transactionLogModule = buildTransactionLogs(storeDir, config, logProvider, scheduler, fs, storageEngine, logEntryReader, legacyIndexTransactionOrdering, transactionIdStore, logVersionRepository);
transactionLogModule.satisfyDependencies(dependencies);
buildRecovery(fs, transactionIdStore, logVersionRepository, monitors.newMonitor(Recovery.Monitor.class), monitors.newMonitor(PositionToRecoverFrom.Monitor.class), transactionLogModule.logFiles(), startupStatistics, storageEngine, logEntryReader, transactionLogModule.logicalTransactionStore());
// At the time of writing this comes from the storage engine (IndexStoreView)
PropertyAccessor propertyAccessor = dependencies.resolveDependency(PropertyAccessor.class);
final NeoStoreKernelModule kernelModule = buildKernel(transactionLogModule.transactionAppender(), dependencies.resolveDependency(IndexingService.class), storageEngine.storeReadLayer(), updateableSchemaState, dependencies.resolveDependency(LabelScanStore.class), storageEngine, indexConfigStore, transactionIdStore, availabilityGuard, clock, propertyAccessor);
kernelModule.satisfyDependencies(dependencies);
// Do these assignments last so that we can ensure no cyclical dependencies exist
this.storageEngine = storageEngine;
this.transactionLogModule = transactionLogModule;
this.kernelModule = kernelModule;
dependencies.satisfyDependency(this);
dependencies.satisfyDependency(updateableSchemaState);
dependencies.satisfyDependency(storageEngine.storeReadLayer());
dependencies.satisfyDependency(logEntryReader);
dependencies.satisfyDependency(storageEngine);
} catch (Throwable e) {
// Something unexpected happened during startup
msgLog.warn("Exception occurred while setting up store modules. Attempting to close things down.", e);
try {
// Close the neostore, so that locks are released properly
if (storageEngine != null) {
storageEngine.forceClose();
}
} catch (Exception closeException) {
msgLog.error("Couldn't close neostore after startup failure", closeException);
}
throw Exceptions.launderedException(e);
}
// NOTE: please make sure this is performed after having added everything to the life, in fact we would like
// to perform the checkpointing as first step when the life is shutdown.
life.add(lifecycleToTriggerCheckPointOnShutdown());
try {
life.start();
} catch (Throwable e) {
// Something unexpected happened during startup
msgLog.warn("Exception occurred while starting the datasource. Attempting to close things down.", e);
try {
life.shutdown();
// Close the neostore, so that locks are released properly
storageEngine.forceClose();
} catch (Exception closeException) {
msgLog.error("Couldn't close neostore after startup failure", closeException);
}
throw Exceptions.launderedException(e);
}
/*
* At this point recovery has completed and the datasource is ready for use. Whatever panic might have
* happened before has been healed. So we can safely set the kernel health to ok.
* This right now has any real effect only in the case of internal restarts (for example, after a store copy
* in the case of HA). Standalone instances will have to be restarted by the user, as is proper for all
* kernel panics.
*/
databaseHealth.healed();
}
use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class RecordStorageEngineRule method get.
private RecordStorageEngine get(FileSystemAbstraction fs, PageCache pageCache, SchemaIndexProvider schemaIndexProvider, DatabaseHealth databaseHealth, File storeDirectory, Function<BatchTransactionApplierFacade, BatchTransactionApplierFacade> transactionApplierTransformer) {
if (!fs.fileExists(storeDirectory) && !fs.mkdir(storeDirectory)) {
throw new IllegalStateException();
}
IdGeneratorFactory idGeneratorFactory = new EphemeralIdGenerator.Factory();
LabelScanStoreProvider labelScanStoreProvider = nativeLabelScanStoreProvider(storeDirectory, fs, pageCache);
LegacyIndexProviderLookup legacyIndexProviderLookup = mock(LegacyIndexProviderLookup.class);
when(legacyIndexProviderLookup.all()).thenReturn(Iterables.empty());
IndexConfigStore indexConfigStore = new IndexConfigStore(storeDirectory, fs);
JobScheduler scheduler = life.add(new Neo4jJobScheduler());
Config config = Config.defaults();
Supplier<KernelTransactionsSnapshot> txSnapshotSupplier = () -> new KernelTransactionsSnapshot(Collections.emptySet(), 0);
return life.add(new ExtendedRecordStorageEngine(storeDirectory, config, idGeneratorFactory, IdReuseEligibility.ALWAYS, new CommunityIdTypeConfigurationProvider(), pageCache, fs, NullLogProvider.getInstance(), mock(PropertyKeyTokenHolder.class), mock(LabelTokenHolder.class), mock(RelationshipTypeTokenHolder.class), () -> {
}, new StandardConstraintSemantics(), scheduler, mock(TokenNameLookup.class), new ReentrantLockService(), schemaIndexProvider, IndexingService.NO_MONITOR, databaseHealth, labelScanStoreProvider, legacyIndexProviderLookup, indexConfigStore, new SynchronizedArrayIdOrderingQueue(20), txSnapshotSupplier, transactionApplierTransformer));
}
use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class LuceneCommandApplierTest method shouldHandleMultipleIdSpaces.
@Test
public void shouldHandleMultipleIdSpaces() throws Exception {
// GIVEN
fs.get().mkdirs(dir);
String indexName = "name", key = "key";
IndexConfigStore configStore = new IndexConfigStore(dir, fs.get());
configStore.set(Node.class, indexName, EXACT_CONFIG);
LuceneDataSource dataSource = life.add(spy(new LuceneDataSource(dir, Config.embeddedDefaults(stringMap(LuceneDataSource.Configuration.ephemeral.name(), Settings.TRUE)), configStore, fs.get())));
try (LuceneCommandApplier applier = new LuceneCommandApplier(dataSource, false)) {
// WHEN issuing a command where the index name is mapped to a certain id
IndexDefineCommand definitions = definitions(MapUtil.<String, Integer>genericMap(indexName, 0), MapUtil.<String, Integer>genericMap(key, 0));
applier.visitIndexDefineCommand(definitions);
applier.visitIndexAddNodeCommand(addNodeToIndex(definitions, indexName, 0L));
// and then later issuing a command for that same index, but in another transaction where
// the local index name id is a different one
definitions = definitions(MapUtil.<String, Integer>genericMap(indexName, 1), MapUtil.<String, Integer>genericMap(key, 0));
applier.visitIndexDefineCommand(definitions);
applier.visitIndexAddNodeCommand(addNodeToIndex(definitions, indexName, 1L));
}
// THEN both those updates should have been directed to the same index
verify(dataSource, times(1)).getIndexSearcher(any(IndexIdentifier.class));
}
use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class LuceneDataSourceTest method setUp.
@Before
public void setUp() {
indexStore = new IndexConfigStore(directory.directory(), fileSystemRule.get());
addIndex("foo");
}
use of org.neo4j.kernel.impl.index.IndexConfigStore in project neo4j by neo4j.
the class RecoveryTest method recoveryForRelationshipCommandsOnly.
@Test
public void recoveryForRelationshipCommandsOnly() throws Throwable {
// shutdown db here
File storeDir = db.getStoreDirFile();
shutdownDB();
try (Transaction tx = db.beginTx()) {
Index<Relationship> index = db.index().forRelationships("myIndex");
Node node = db.createNode();
Relationship relationship = db.createNode().createRelationshipTo(node, RelationshipType.withName("KNOWS"));
index.add(relationship, "key", "value");
tx.success();
}
db.shutdown();
Config config = Config.embeddedDefaults();
IndexConfigStore indexStore = new IndexConfigStore(storeDir, fileSystemRule.get());
LuceneDataSource ds = new LuceneDataSource(storeDir, config, indexStore, fileSystemRule.get());
ds.start();
ds.stop();
}
Aggregations