Search in sources :

Example 36 with LogFiles

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

the class DatabaseFileListingTest method shouldCloseIndexSnapshots.

@Test
void shouldCloseIndexSnapshots() throws Exception {
    // Given
    IndexingService indexingService = mock(IndexingService.class);
    DatabaseLayout databaseLayout = mock(DatabaseLayout.class);
    when(databaseLayout.metadataStore()).thenReturn(mock(Path.class));
    LogFiles logFiles = mock(LogFiles.class);
    filesInStoreDirAre(databaseLayout, STANDARD_STORE_DIR_FILES, STANDARD_STORE_DIR_DIRECTORIES);
    StorageEngine storageEngine = mock(StorageEngine.class);
    IdGeneratorFactory idGeneratorFactory = mock(IdGeneratorFactory.class);
    DatabaseFileListing fileListing = new DatabaseFileListing(databaseLayout, logFiles, indexingService, storageEngine, idGeneratorFactory);
    ResourceIterator<Path> indexSnapshot = indexFilesAre(indexingService, new String[] { "schema/index/my.index" });
    ResourceIterator<StoreFileMetadata> result = fileListing.builder().excludeLogFiles().build();
    // When
    result.close();
    // Then
    verify(indexSnapshot).close();
}
Also used : Path(java.nio.file.Path) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Test(org.junit.jupiter.api.Test)

Example 37 with LogFiles

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

the class DatabaseFileListingTest method verifyLogFilesWithCustomPathListing.

private void verifyLogFilesWithCustomPathListing(Path path) throws IOException {
    DatabaseManagementService managementService = new TestDatabaseManagementServiceBuilder(testDirectory.homePath("customDb")).setConfig(GraphDatabaseSettings.transaction_logs_root_path, path).build();
    GraphDatabaseAPI graphDatabase = (GraphDatabaseAPI) managementService.database(DEFAULT_DATABASE_NAME);
    Database database = graphDatabase.getDependencyResolver().resolveDependency(Database.class);
    LogFiles logFiles = graphDatabase.getDependencyResolver().resolveDependency(LogFiles.class);
    assertTrue(database.listStoreFiles(true).stream().anyMatch(metadata -> metadata.isLogFile() && logFiles.isLogFile(metadata.path())));
    assertEquals(path.getFileName().toString(), logFiles.logFilesDirectory().getParent().getFileName().toString());
    managementService.shutdown();
}
Also used : IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) ResourceIterator(org.neo4j.graphdb.ResourceIterator) StoreFileMetadata(org.neo4j.storageengine.api.StoreFileMetadata) IdGeneratorFactory(org.neo4j.internal.id.IdGeneratorFactory) GraphDatabaseSettings(org.neo4j.configuration.GraphDatabaseSettings) Resource(org.neo4j.graphdb.Resource) Mockito.spy(org.mockito.Mockito.spy) DatabaseLayout(org.neo4j.io.layout.DatabaseLayout) ArrayList(java.util.ArrayList) DEFAULT_DATABASE_NAME(org.neo4j.configuration.GraphDatabaseSettings.DEFAULT_DATABASE_NAME) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) Inject(org.neo4j.test.extension.Inject) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Path(java.nio.file.Path) DEFAULT_FILENAME_FILTER(org.neo4j.kernel.impl.transaction.log.files.TransactionLogFiles.DEFAULT_FILENAME_FILTER) Files(java.nio.file.Files) Iterators(org.neo4j.internal.helpers.collection.Iterators) StorageEngine(org.neo4j.storageengine.api.StorageEngine) Collection(java.util.Collection) Set(java.util.Set) TestDirectory(org.neo4j.test.rule.TestDirectory) IOException(java.io.IOException) DbmsExtension(org.neo4j.test.extension.DbmsExtension) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) File(java.io.File) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) UncheckedIOException(java.io.UncheckedIOException) List(java.util.List) Database(org.neo4j.kernel.database.Database) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService) Mockito.mock(org.mockito.Mockito.mock) Iterators.asResourceIterator(org.neo4j.internal.helpers.collection.Iterators.asResourceIterator) TestDatabaseManagementServiceBuilder(org.neo4j.test.TestDatabaseManagementServiceBuilder) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) Database(org.neo4j.kernel.database.Database) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DatabaseManagementService(org.neo4j.dbms.api.DatabaseManagementService)

Example 38 with LogFiles

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

the class CheckPointerIntegrationTest method checkPointsInTxLog.

private static List<CheckpointInfo> checkPointsInTxLog(GraphDatabaseService db) throws IOException {
    DependencyResolver dependencyResolver = ((GraphDatabaseAPI) db).getDependencyResolver();
    LogFiles logFiles = dependencyResolver.resolveDependency(LogFiles.class);
    return logFiles.getCheckpointFile().reachableCheckpoints();
}
Also used : GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 39 with LogFiles

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

the class VersionAwareLogEntryReaderIT method correctlyResetPositionWhenEndOfCommandsReached.

@Test
void correctlyResetPositionWhenEndOfCommandsReached() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogEntryReader(entryReader).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).build();
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        LogPosition logPosition = entryReader.lastPosition();
        assertEquals(0L, logPosition.getLogVersion());
        // this position in a log file before 0's are actually starting
        assertEquals(END_OF_DATA_OFFSET, logPosition.getByteOffset());
        for (int i = 0; i < 10; i++) {
            assertEquals(END_OF_DATA_OFFSET, getLastReadablePosition(logFiles));
        }
    }
}
Also used : SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) Test(org.junit.jupiter.api.Test)

Example 40 with LogFiles

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

the class VersionAwareLogEntryReaderIT method readOnlyLogFilesWhileCommandsAreAvailable.

@Test
@EnabledOnOs(OS.LINUX)
void readOnlyLogFilesWhileCommandsAreAvailable() throws IOException {
    LogFiles logFiles = LogFilesBuilder.builder(databaseLayout, fs).withLogEntryReader(entryReader).withLogVersionRepository(new SimpleLogVersionRepository()).withTransactionIdStore(new SimpleTransactionIdStore()).withStoreId(StoreId.UNKNOWN).build();
    try (Lifespan lifespan = new Lifespan(logFiles)) {
        assertEquals(kibiBytes(128), Files.size(logFiles.getLogFile().getHighestLogFile()));
        LogPosition logPosition = entryReader.lastPosition();
        assertEquals(0L, logPosition.getLogVersion());
        // this position in a log file before 0's are actually starting
        assertEquals(END_OF_DATA_OFFSET, logPosition.getByteOffset());
    }
}
Also used : SimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore) LogFiles(org.neo4j.kernel.impl.transaction.log.files.LogFiles) SimpleLogVersionRepository(org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogPosition(org.neo4j.kernel.impl.transaction.log.LogPosition) EnabledOnOs(org.junit.jupiter.api.condition.EnabledOnOs) Test(org.junit.jupiter.api.Test)

Aggregations

LogFiles (org.neo4j.kernel.impl.transaction.log.files.LogFiles)61 Test (org.junit.jupiter.api.Test)33 LogFile (org.neo4j.kernel.impl.transaction.log.files.LogFile)21 SimpleTransactionIdStore (org.neo4j.kernel.impl.transaction.SimpleTransactionIdStore)16 Path (java.nio.file.Path)13 IOException (java.io.IOException)10 SimpleLogVersionRepository (org.neo4j.kernel.impl.transaction.SimpleLogVersionRepository)10 LogPosition (org.neo4j.kernel.impl.transaction.log.LogPosition)9 VersionAwareLogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.VersionAwareLogEntryReader)9 Lifespan (org.neo4j.kernel.lifecycle.Lifespan)8 TransactionIdStore (org.neo4j.storageengine.api.TransactionIdStore)8 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)7 StoreChannel (org.neo4j.io.fs.StoreChannel)7 DatabaseLayout (org.neo4j.io.layout.DatabaseLayout)7 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)4 LogEntryReader (org.neo4j.kernel.impl.transaction.log.entry.LogEntryReader)4 UncheckedIOException (java.io.UncheckedIOException)3