Search in sources :

Example 1 with IndexImplementation

use of org.neo4j.kernel.spi.legacyindex.IndexImplementation in project neo4j by neo4j.

the class LegacyIndexMigratorTest method getIndexProviders.

private HashMap<String, IndexImplementation> getIndexProviders() {
    HashMap<String, IndexImplementation> indexProviders = new HashMap<>();
    IndexImplementation indexImplementation = mock(IndexImplementation.class);
    indexProviders.put("lucene", indexImplementation);
    when(indexImplementation.getIndexImplementationDirectory(storeDir)).thenReturn(originalIndexStore);
    when(indexImplementation.getIndexImplementationDirectory(migrationDir)).thenReturn(migratedIndexStore);
    return indexProviders;
}
Also used : HashMap(java.util.HashMap) IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation)

Example 2 with IndexImplementation

use of org.neo4j.kernel.spi.legacyindex.IndexImplementation in project neo4j by neo4j.

the class LegacyIndexTransactionStateImpl method nodeChanges.

@Override
public LegacyIndex nodeChanges(String indexName) throws LegacyIndexNotFoundKernelException {
    Map<String, String> configuration = indexConfigStore.get(Node.class, indexName);
    if (configuration == null) {
        throw new LegacyIndexNotFoundKernelException("Node index '" + indexName + " not found");
    }
    String providerName = configuration.get(IndexManager.PROVIDER);
    IndexImplementation provider = providerLookup.apply(providerName);
    LegacyIndexProviderTransaction transaction = transactions.get(providerName);
    if (transaction == null) {
        transactions.put(providerName, transaction = provider.newTransaction(this));
    }
    return transaction.nodeIndex(indexName, configuration);
}
Also used : LegacyIndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException) IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation) LegacyIndexProviderTransaction(org.neo4j.kernel.spi.legacyindex.LegacyIndexProviderTransaction)

Example 3 with IndexImplementation

use of org.neo4j.kernel.spi.legacyindex.IndexImplementation in project neo4j by neo4j.

the class LegacyIndexStore method findIndexConfig.

private Map<String, String> findIndexConfig(Class<? extends PropertyContainer> cls, String indexName, Map<String, String> suppliedConfig, @Nonnull Config dbConfig) {
    // Check stored config (has this index been created previously?)
    Map<String, String> storedConfig = indexStore.get(cls, indexName);
    if (storedConfig != null && suppliedConfig == null) {
        // Fill in "provider" if not already filled in, backwards compatibility issue
        Map<String, String> newConfig = injectDefaultProviderIfMissing(indexName, dbConfig, storedConfig);
        if (newConfig != storedConfig) {
            indexStore.set(cls, indexName, newConfig);
        }
        return newConfig;
    }
    Map<String, String> configToUse = suppliedConfig;
    // Check db config properties for provider
    String provider;
    IndexImplementation indexProvider;
    if (configToUse == null) {
        provider = getDefaultProvider(indexName, dbConfig);
        configToUse = MapUtil.stringMap(PROVIDER, provider);
    } else {
        provider = configToUse.get(PROVIDER);
        provider = provider == null ? getDefaultProvider(indexName, dbConfig) : provider;
    }
    indexProvider = indexProviders.apply(provider);
    configToUse = indexProvider.fillInDefaults(configToUse);
    configToUse = injectDefaultProviderIfMissing(indexName, dbConfig, configToUse);
    // Do they match (stored vs. supplied)?
    if (storedConfig != null) {
        assertConfigMatches(indexProvider, indexName, storedConfig, suppliedConfig);
        // Fill in "provider" if not already filled in, backwards compatibility issue
        Map<String, String> newConfig = injectDefaultProviderIfMissing(indexName, dbConfig, storedConfig);
        if (newConfig != storedConfig) {
            indexStore.set(cls, indexName, newConfig);
        }
        configToUse = newConfig;
    }
    return Collections.unmodifiableMap(configToUse);
}
Also used : IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation)

Example 4 with IndexImplementation

use of org.neo4j.kernel.spi.legacyindex.IndexImplementation in project neo4j by neo4j.

the class LegacyIndexMigrator method migrate.

@Override
public void migrate(File storeDir, File migrationDir, MigrationProgressMonitor.Section progressMonitor, String versionToMigrateFrom, String versionToMigrateTo) throws IOException {
    IndexImplementation indexImplementation = indexProviders.get(LUCENE_LEGACY_INDEX_PROVIDER_NAME);
    if (indexImplementation != null) {
        RecordFormats from = RecordFormatSelector.selectForVersion(versionToMigrateFrom);
        RecordFormats to = RecordFormatSelector.selectForVersion(versionToMigrateTo);
        if (!from.hasSameCapabilities(to, CapabilityType.INDEX)) {
            originalLegacyIndexesRoot = indexImplementation.getIndexImplementationDirectory(storeDir);
            migrationLegacyIndexesRoot = indexImplementation.getIndexImplementationDirectory(migrationDir);
            if (isNotEmptyDirectory(originalLegacyIndexesRoot)) {
                migrateLegacyIndexes(progressMonitor);
                legacyIndexMigrated = true;
            }
        }
    } else {
        log.debug("Lucene index provider not found, nothing to migrate.");
    }
}
Also used : RecordFormats(org.neo4j.kernel.impl.store.format.RecordFormats) IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation)

Example 5 with IndexImplementation

use of org.neo4j.kernel.spi.legacyindex.IndexImplementation in project neo4j by neo4j.

the class LegacyIndexTransactionStateImplTest method newLegacyIndexTxState.

private static LegacyIndexTransactionStateImpl newLegacyIndexTxState() {
    IndexConfigStore indexConfigStore = mock(IndexConfigStore.class);
    when(indexConfigStore.get(eq(Node.class), anyString())).thenReturn(singletonMap(IndexManager.PROVIDER, "test"));
    when(indexConfigStore.get(eq(Relationship.class), anyString())).thenReturn(singletonMap(IndexManager.PROVIDER, "test"));
    Function<String, IndexImplementation> providerLookup = s -> mock(IndexImplementation.class);
    return new LegacyIndexTransactionStateImpl(indexConfigStore, providerLookup);
}
Also used : Arrays(java.util.Arrays) IndexDefineCommand(org.neo4j.kernel.impl.index.IndexDefineCommand) IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Function(java.util.function.Function) Node(org.neo4j.graphdb.Node) Matchers.anyString(org.mockito.Matchers.anyString) StorageCommand(org.neo4j.storageengine.api.StorageCommand) HashSet(java.util.HashSet) IndexManager(org.neo4j.graphdb.index.IndexManager) IndexEntityType(org.neo4j.kernel.impl.index.IndexEntityType) Command(org.neo4j.kernel.impl.transaction.command.Command) Relationship(org.neo4j.graphdb.Relationship) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.eq(org.mockito.Matchers.eq) IndexCommand(org.neo4j.kernel.impl.index.IndexCommand) Collections.singletonMap(java.util.Collections.singletonMap) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) IndexImplementation(org.neo4j.kernel.spi.legacyindex.IndexImplementation) Node(org.neo4j.graphdb.Node) Relationship(org.neo4j.graphdb.Relationship) IndexConfigStore(org.neo4j.kernel.impl.index.IndexConfigStore) Matchers.anyString(org.mockito.Matchers.anyString)

Aggregations

IndexImplementation (org.neo4j.kernel.spi.legacyindex.IndexImplementation)9 Test (org.junit.Test)2 LegacyIndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.legacyindex.LegacyIndexNotFoundKernelException)2 LegacyIndexProviderTransaction (org.neo4j.kernel.spi.legacyindex.LegacyIndexProviderTransaction)2 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections.singletonMap (java.util.Collections.singletonMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Matchers.eq (org.mockito.Matchers.eq)1 Mockito.mock (org.mockito.Mockito.mock)1 Mockito.when (org.mockito.Mockito.when)1 Node (org.neo4j.graphdb.Node)1 Relationship (org.neo4j.graphdb.Relationship)1