Search in sources :

Example 1 with StoreType

use of org.neo4j.kernel.impl.store.StoreType in project neo4j by neo4j.

the class DumpStore method dumpFile.

private static void dumpFile(Function<File, StoreFactory> createStoreFactory, String fileName) throws Exception {
    File file = new File(fileName);
    // null means all possible ids
    long[] ids = null;
    if (file.isFile()) {
    /* If file exists, even with : in its path, then accept it straight off. */
    } else if (!file.isDirectory() && file.getName().indexOf(':') != -1) {
        /* Now we know that it is not a directory either, and that the last component
                   of the path contains a colon, thus it is very likely an attempt to use the
                   id-specifying syntax. */
        int idStart = fileName.lastIndexOf(':');
        String[] idStrings = fileName.substring(idStart + 1).split(",");
        ids = new long[idStrings.length];
        for (int i = 0; i < ids.length; i++) {
            ids[i] = Long.parseLong(idStrings[i]);
        }
        file = new File(fileName.substring(0, idStart));
        if (!file.isFile()) {
            throw new IllegalArgumentException("No such file: " + fileName);
        }
    }
    StoreType storeType = StoreType.typeOf(file.getName()).orElseThrow(() -> new IllegalArgumentException("Not a store file: " + fileName));
    try (NeoStores neoStores = createStoreFactory.apply(file).openNeoStores(storeType)) {
        switch(storeType) {
            case META_DATA:
                dumpMetaDataStore(neoStores);
                break;
            case NODE:
                dumpNodeStore(neoStores, ids);
                break;
            case RELATIONSHIP:
                dumpRelationshipStore(neoStores, ids);
                break;
            case PROPERTY:
                dumpPropertyStore(neoStores, ids);
                break;
            case SCHEMA:
                dumpSchemaStore(neoStores, ids);
                break;
            case PROPERTY_KEY_TOKEN:
                dumpPropertyKeys(neoStores, ids);
                break;
            case LABEL_TOKEN:
                dumpLabels(neoStores, ids);
                break;
            case RELATIONSHIP_TYPE_TOKEN:
                dumpRelationshipTypes(neoStores, ids);
                break;
            case RELATIONSHIP_GROUP:
                dumpRelationshipGroups(neoStores, ids);
                break;
            default:
                throw new IllegalArgumentException("Unsupported store type: " + storeType);
        }
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) NeoStores(org.neo4j.kernel.impl.store.NeoStores) File(java.io.File)

Example 2 with StoreType

use of org.neo4j.kernel.impl.store.StoreType in project neo4j by neo4j.

the class RecordStorageEngine method listStorageFiles.

@Override
public Collection<StoreFileMetadata> listStorageFiles() {
    List<StoreFileMetadata> files = new ArrayList<>();
    for (StoreType type : StoreType.values()) {
        if (type.equals(StoreType.COUNTS)) {
            addCountStoreFiles(files);
        } else {
            final RecordStore<AbstractBaseRecord> recordStore = neoStores.getRecordStore(type);
            StoreFileMetadata metadata = new StoreFileMetadata(recordStore.getStorageFileName(), Optional.of(type), recordStore.getRecordSize());
            files.add(metadata);
        }
    }
    return files;
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) AbstractBaseRecord(org.neo4j.kernel.impl.store.record.AbstractBaseRecord) ArrayList(java.util.ArrayList) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata)

Example 3 with StoreType

use of org.neo4j.kernel.impl.store.StoreType in project neo4j by neo4j.

the class DirectRecordStoreMigrator method migrate.

public void migrate(File fromStoreDir, RecordFormats fromFormat, File toStoreDir, RecordFormats toFormat, MigrationProgressMonitor.Section progressMonitor, StoreType[] types, StoreType... additionalTypesToOpen) {
    StoreType[] storesToOpen = ArrayUtil.concat(types, additionalTypesToOpen);
    progressMonitor.start(storesToOpen.length);
    try (NeoStores fromStores = new StoreFactory(fromStoreDir, config, new DefaultIdGeneratorFactory(fs), pageCache, fs, fromFormat, NullLogProvider.getInstance()).openNeoStores(true, storesToOpen);
        NeoStores toStores = new StoreFactory(toStoreDir, withPersistedStoreHeadersAsConfigFrom(fromStores, storesToOpen), new DefaultIdGeneratorFactory(fs), pageCache, fs, toFormat, NullLogProvider.getInstance()).openNeoStores(true, storesToOpen)) {
        for (StoreType type : types) {
            // This condition will exclude counts store first and foremost.
            if (type.isRecordStore()) {
                migrate(fromStores.getRecordStore(type), toStores.getRecordStore(type));
                progressMonitor.progress(1);
            }
        }
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) NeoStores(org.neo4j.kernel.impl.store.NeoStores) DefaultIdGeneratorFactory(org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory) StoreFactory(org.neo4j.kernel.impl.store.StoreFactory)

Example 4 with StoreType

use of org.neo4j.kernel.impl.store.StoreType in project neo4j by neo4j.

the class NeoStoreFileListingTest method expectedStoreFiles.

private Set<String> expectedStoreFiles(boolean includeLogFiles) {
    Set<String> storeFileNames = new HashSet<>();
    for (StoreType type : StoreType.values()) {
        if (!type.equals(StoreType.COUNTS)) {
            storeFileNames.add(type.getStoreFile().fileName(StoreFileType.STORE));
        }
    }
    if (includeLogFiles) {
        storeFileNames.add(PhysicalLogFile.DEFAULT_NAME + ".0");
    }
    storeFileNames.add(IndexConfigStore.INDEX_DB_FILE_NAME);
    return storeFileNames;
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) HashSet(java.util.HashSet)

Example 5 with StoreType

use of org.neo4j.kernel.impl.store.StoreType in project neo4j by neo4j.

the class NeoStoreFileListingTest method shouldListNeostoreDbLast.

@Test
public void shouldListNeostoreDbLast() throws Exception {
    Boolean[] foundStoreType = new Boolean[StoreType.values().length];
    boolean foundTxLogs = false;
    final ResourceIterator<StoreFileMetadata> storeFiles = neoStoreDataSource.listStoreFiles(true);
    while (storeFiles.hasNext()) {
        final StoreFileMetadata storeFile = storeFiles.next();
        if (storeFile.storeType().isPresent()) {
            StoreType storeType = storeFile.storeType().get();
            foundStoreType[storeType.ordinal()] = true;
            if (storeType == StoreType.META_DATA) {
                Arrays.stream(foundStoreType).forEach(Assert::assertTrue);
                assertTrue("Transaction logs was not listed before neostore.db", foundTxLogs);
            }
        } else if (transactionLogFile(storeFile.file().getName())) {
            foundTxLogs = true;
        }
    }
}
Also used : StoreType(org.neo4j.kernel.impl.store.StoreType) Assert(org.junit.Assert) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) Test(org.junit.Test)

Aggregations

StoreType (org.neo4j.kernel.impl.store.StoreType)17 NeoStores (org.neo4j.kernel.impl.store.NeoStores)5 ArrayList (java.util.ArrayList)4 PageCache (org.neo4j.io.pagecache.PageCache)4 File (java.io.File)3 Path (java.nio.file.Path)3 Test (org.junit.Test)3 DefaultIdGeneratorFactory (org.neo4j.internal.id.DefaultIdGeneratorFactory)3 ScanOnOpenReadOnlyIdGeneratorFactory (org.neo4j.internal.id.ScanOnOpenReadOnlyIdGeneratorFactory)3 CursorContext (org.neo4j.io.pagecache.context.CursorContext)3 StoreFactory (org.neo4j.kernel.impl.store.StoreFactory)3 StoreFileMetadata (org.neo4j.storageengine.api.StoreFileMetadata)3 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 HashSet (java.util.HashSet)2 LongSupplier (java.util.function.LongSupplier)2 ImmutableSet (org.eclipse.collections.api.set.ImmutableSet)2 Config (org.neo4j.configuration.Config)2 DatabaseReadOnlyChecker (org.neo4j.configuration.helpers.DatabaseReadOnlyChecker)2 IdGeneratorFactory (org.neo4j.internal.id.IdGeneratorFactory)2