Search in sources :

Example 1 with StoreFileMetadata

use of org.neo4j.storageengine.api.StoreFileMetadata in project neo4j by neo4j.

the class NeoStoreFileListingTest method shouldCloseIndexAndLabelScanSnapshots.

@Test
public void shouldCloseIndexAndLabelScanSnapshots() throws Exception {
    // Given
    LabelScanStore labelScanStore = mock(LabelScanStore.class);
    IndexingService indexingService = mock(IndexingService.class);
    LegacyIndexProviderLookup legacyIndexes = mock(LegacyIndexProviderLookup.class);
    when(legacyIndexes.all()).thenReturn(Collections.emptyList());
    File storeDir = mock(File.class);
    filesInStoreDirAre(storeDir, STANDARD_STORE_DIR_FILES, STANDARD_STORE_DIR_DIRECTORIES);
    StorageEngine storageEngine = mock(StorageEngine.class);
    NeoStoreFileListing fileListing = new NeoStoreFileListing(storeDir, labelScanStore, indexingService, legacyIndexes, storageEngine);
    ResourceIterator<File> scanSnapshot = scanStoreFilesAre(labelScanStore, new String[] { "blah/scan.store", "scan.more" });
    ResourceIterator<File> indexSnapshot = indexFilesAre(indexingService, new String[] { "schema/index/my.index" });
    ResourceIterator<StoreFileMetadata> result = fileListing.listStoreFiles(false);
    // When
    result.close();
    // Then
    verify(scanSnapshot).close();
    verify(indexSnapshot).close();
}
Also used : LabelScanStore(org.neo4j.kernel.api.labelscan.LabelScanStore) LegacyIndexProviderLookup(org.neo4j.kernel.impl.api.LegacyIndexProviderLookup) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) StorageEngine(org.neo4j.storageengine.api.StorageEngine) StoreFile(org.neo4j.kernel.impl.storemigration.StoreFile) File(java.io.File) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) Test(org.junit.Test)

Example 2 with StoreFileMetadata

use of org.neo4j.storageengine.api.StoreFileMetadata 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)

Example 3 with StoreFileMetadata

use of org.neo4j.storageengine.api.StoreFileMetadata 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 4 with StoreFileMetadata

use of org.neo4j.storageengine.api.StoreFileMetadata in project neo4j by neo4j.

the class RecordStorageEngine method addCountStoreFiles.

private void addCountStoreFiles(List<StoreFileMetadata> files) {
    Iterable<File> countStoreFiles = neoStores.getCounts().allFiles();
    for (File countStoreFile : countStoreFiles) {
        StoreFileMetadata countStoreFileMetadata = new StoreFileMetadata(countStoreFile, Optional.of(StoreType.COUNTS), RecordFormat.NO_RECORD_SIZE);
        files.add(countStoreFileMetadata);
    }
}
Also used : StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) File(java.io.File)

Example 5 with StoreFileMetadata

use of org.neo4j.storageengine.api.StoreFileMetadata in project neo4j by neo4j.

the class GetStoreRequestHandler method channelRead0.

@Override
protected void channelRead0(ChannelHandlerContext ctx, GetStoreRequest msg) throws Exception {
    if (!msg.expectedStoreId().equalToKernelStoreId(dataSource.get().getStoreId())) {
        endStoreCopy(SUCCESS, ctx, -1);
    } else {
        CheckPointer checkPointer = checkPointerSupplier.get();
        long lastCheckPointedTx;
        try (Resource lock = mutex.storeCopy(() -> checkPointer.tryCheckPoint(new SimpleTriggerInfo("Store copy")));
            ResourceIterator<StoreFileMetadata> files = dataSource.get().listStoreFiles(false)) {
            lastCheckPointedTx = checkPointer.lastCheckPointedTransactionId();
            while (files.hasNext()) {
                StoreFileMetadata fileMetadata = files.next();
                File file = fileMetadata.file();
                log.debug("Sending file " + file);
                ctx.writeAndFlush(ResponseMessageType.FILE);
                ctx.writeAndFlush(new FileHeader(relativePath(dataSource.get().getStoreDir(), file), fileMetadata.recordSize()));
                Optional<PagedFile> existingMapping = pageCache.getExistingMapping(file);
                if (existingMapping.isPresent()) {
                    try (PagedFile pagedFile = existingMapping.get()) {
                        ctx.writeAndFlush(new FileSender(pagedFile.openReadableByteChannel()));
                    }
                } else {
                    ctx.writeAndFlush(new FileSender(fs.open(file, "r")));
                }
            }
        }
        endStoreCopy(SUCCESS, ctx, lastCheckPointedTx);
    }
    protocol.expect(State.MESSAGE_TYPE);
}
Also used : SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) PagedFile(org.neo4j.io.pagecache.PagedFile) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Resource(org.neo4j.graphdb.Resource) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) PagedFile(org.neo4j.io.pagecache.PagedFile) File(java.io.File)

Aggregations

StoreFileMetadata (org.neo4j.storageengine.api.StoreFileMetadata)8 File (java.io.File)5 ArrayList (java.util.ArrayList)3 Resource (org.neo4j.graphdb.Resource)3 Test (org.junit.Test)2 PagedFile (org.neo4j.io.pagecache.PagedFile)2 StoreType (org.neo4j.kernel.impl.store.StoreType)2 SimpleTriggerInfo (org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ReadableByteChannel (java.nio.channels.ReadableByteChannel)1 Assert (org.junit.Assert)1 ServerFailureException (org.neo4j.com.ServerFailureException)1 FileUtils.getMostCanonicalFile (org.neo4j.io.fs.FileUtils.getMostCanonicalFile)1 NeoStoreDataSource (org.neo4j.kernel.NeoStoreDataSource)1 LabelScanStore (org.neo4j.kernel.api.labelscan.LabelScanStore)1 LegacyIndexProviderLookup (org.neo4j.kernel.impl.api.LegacyIndexProviderLookup)1 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)1 AbstractBaseRecord (org.neo4j.kernel.impl.store.record.AbstractBaseRecord)1 StoreFile (org.neo4j.kernel.impl.storemigration.StoreFile)1