Search in sources :

Example 1 with TransactionLogFilesHelper

use of org.neo4j.kernel.impl.transaction.log.files.TransactionLogFilesHelper in project neo4j by neo4j.

the class BatchingNeoStores method databaseExistsAndContainsData.

private boolean databaseExistsAndContainsData() {
    TransactionLogFilesHelper logFilesHelper = new TransactionLogFilesHelper(fileSystem, databaseLayout.getTransactionLogsDirectory());
    TransactionLogFilesHelper checkpointFilesHelper = new TransactionLogFilesHelper(fileSystem, databaseLayout.getTransactionLogsDirectory(), CHECKPOINT_FILE_PREFIX);
    try {
        if (logFilesHelper.getMatchedFiles().length > 0 || checkpointFilesHelper.getMatchedFiles().length > 0) {
            return true;
        }
    } catch (IOException e) {
    // Could not check txlogs (does not exist?) Do nothing
    }
    Path metaDataFile = databaseLayout.metadataStore();
    try (PagedFile pagedFile = pageCache.map(metaDataFile, pageCache.pageSize(), databaseName, immutable.of(READ))) {
    // OK so the db probably exists
    } catch (IOException e) {
        // It's OK
        return false;
    }
    try (NeoStores stores = newStoreFactory(databaseLayout, idGeneratorFactory, pageCacheTracer, immutable.empty()).openNeoStores(StoreType.NODE, StoreType.RELATIONSHIP)) {
        return stores.getNodeStore().getHighId() > 0 || stores.getRelationshipStore().getHighId() > 0;
    }
}
Also used : Path(java.nio.file.Path) PagedFile(org.neo4j.io.pagecache.PagedFile) NeoStores(org.neo4j.kernel.impl.store.NeoStores) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) TransactionLogFilesHelper(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFilesHelper)

Aggregations

IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 Path (java.nio.file.Path)1 PagedFile (org.neo4j.io.pagecache.PagedFile)1 NeoStores (org.neo4j.kernel.impl.store.NeoStores)1 TransactionLogFilesHelper (org.neo4j.kernel.impl.transaction.log.files.TransactionLogFilesHelper)1