Search in sources :

Example 56 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class PhysicalLogFileTest method shouldSuppressFailueToCloseChannelInFailedAttemptToReadHeaderAfterOpen.

@Test
public void shouldSuppressFailueToCloseChannelInFailedAttemptToReadHeaderAfterOpen() throws Exception {
    // GIVEN a file which returns 1/2 log header size worth of bytes
    File directory = new File("/dir");
    FileSystemAbstraction fs = mock(FileSystemAbstraction.class);
    PhysicalLogFiles logFiles = new PhysicalLogFiles(directory, fs);
    int logVersion = 0;
    File logFile = logFiles.getLogFileForVersion(logVersion);
    StoreChannel channel = mock(StoreChannel.class);
    when(channel.read(any(ByteBuffer.class))).thenReturn(LogHeader.LOG_HEADER_SIZE / 2);
    when(fs.fileExists(logFile)).thenReturn(true);
    when(fs.open(eq(logFile), anyString())).thenReturn(channel);
    doThrow(IOException.class).when(channel).close();
    // WHEN
    try {
        PhysicalLogFile.openForVersion(logFiles, fs, logVersion, false);
        fail("Should have failed");
    } catch (IncompleteLogHeaderException e) {
        // THEN good
        verify(channel).close();
        assertEquals(1, e.getSuppressed().length);
        assertTrue(e.getSuppressed()[0] instanceof IOException);
    }
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) StoreChannel(org.neo4j.io.fs.StoreChannel) IOException(java.io.IOException) File(java.io.File) ByteBuffer(java.nio.ByteBuffer) IncompleteLogHeaderException(org.neo4j.kernel.impl.transaction.log.entry.IncompleteLogHeaderException) Test(org.junit.Test)

Example 57 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class Runner method call.

@Override
public Long call() throws Exception {
    long lastCommittedTransactionId;
    try (FileSystemAbstraction fileSystem = new DefaultFileSystemAbstraction();
        Lifespan life = new Lifespan()) {
        TransactionIdStore transactionIdStore = new DeadSimpleTransactionIdStore();
        TransactionMetadataCache transactionMetadataCache = new TransactionMetadataCache(100_000);
        LogHeaderCache logHeaderCache = new LogHeaderCache(1000);
        LogFile logFile = life.add(createPhysicalLogFile(transactionIdStore, logHeaderCache, fileSystem));
        TransactionAppender transactionAppender = life.add(createBatchingTransactionAppender(transactionIdStore, transactionMetadataCache, logFile));
        ExecutorService executorService = Executors.newFixedThreadPool(threads);
        try {
            Future<?>[] handlers = new Future[threads];
            for (int i = 0; i < threads; i++) {
                TransactionRepresentationFactory factory = new TransactionRepresentationFactory();
                Worker task = new Worker(transactionAppender, factory, condition);
                handlers[i] = executorService.submit(task);
            }
            // wait for all the workers to complete
            for (Future<?> handle : handlers) {
                handle.get();
            }
        } finally {
            executorService.shutdown();
        }
        lastCommittedTransactionId = transactionIdStore.getLastCommittedTransactionId();
    }
    return lastCommittedTransactionId;
}
Also used : DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) DefaultFileSystemAbstraction(org.neo4j.io.fs.DefaultFileSystemAbstraction) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) TransactionAppender(org.neo4j.kernel.impl.transaction.log.TransactionAppender) BatchingTransactionAppender(org.neo4j.kernel.impl.transaction.log.BatchingTransactionAppender) DeadSimpleTransactionIdStore(org.neo4j.kernel.impl.transaction.DeadSimpleTransactionIdStore) TransactionMetadataCache(org.neo4j.kernel.impl.transaction.log.TransactionMetadataCache) LogFile(org.neo4j.kernel.impl.transaction.log.LogFile) PhysicalLogFile(org.neo4j.kernel.impl.transaction.log.PhysicalLogFile) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Lifespan(org.neo4j.kernel.lifecycle.Lifespan) LogHeaderCache(org.neo4j.kernel.impl.transaction.log.LogHeaderCache)

Example 58 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class LogPruneStrategyFactoryTest method testLogPruneThresholdsByType.

@Test
public void testLogPruneThresholdsByType() throws Exception {
    FileSystemAbstraction fsa = Mockito.mock(FileSystemAbstraction.class);
    assertThat(getThresholdByType(fsa, new ThresholdConfigValue("files", 25), ""), instanceOf(FileCountThreshold.class));
    assertThat(getThresholdByType(fsa, new ThresholdConfigValue("size", 16000), ""), instanceOf(FileSizeThreshold.class));
    assertThat(getThresholdByType(fsa, new ThresholdConfigValue("txs", 4000), ""), instanceOf(EntryCountThreshold.class));
    assertThat(getThresholdByType(fsa, new ThresholdConfigValue("entries", 4000), ""), instanceOf(EntryCountThreshold.class));
    assertThat(getThresholdByType(fsa, new ThresholdConfigValue("hours", 100), ""), instanceOf(EntryTimespanThreshold.class));
    assertThat(getThresholdByType(fsa, new ThresholdConfigValue("days", 100_000), ""), instanceOf(EntryTimespanThreshold.class));
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) ThresholdConfigValue(org.neo4j.kernel.impl.transaction.log.pruning.ThresholdConfigParser.ThresholdConfigValue) Test(org.junit.Test)

Example 59 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class EnterpriseSecurityModule method setup.

@Override
public void setup(Dependencies dependencies) throws KernelException {
    Config config = dependencies.config();
    Procedures procedures = dependencies.procedures();
    LogProvider logProvider = dependencies.logService().getUserLogProvider();
    JobScheduler jobScheduler = dependencies.scheduler();
    FileSystemAbstraction fileSystem = dependencies.fileSystem();
    LifeSupport life = dependencies.lifeSupport();
    SecurityLog securityLog = SecurityLog.create(config, dependencies.logService().getInternalLog(GraphDatabaseFacade.class), fileSystem, jobScheduler);
    life.add(securityLog);
    boolean allowTokenCreate = config.get(SecuritySettings.allow_publisher_create_token);
    PredefinedRolesBuilder.setAllowPublisherTokenCreate(allowTokenCreate);
    procedures.writerCreateToken(allowTokenCreate);
    EnterpriseAuthAndUserManager authManager = newAuthManager(config, logProvider, securityLog, fileSystem, jobScheduler);
    life.add(dependencies.dependencySatisfier().satisfyDependency(authManager));
    // Register procedures
    procedures.registerComponent(SecurityLog.class, (ctx) -> securityLog, false);
    procedures.registerComponent(EnterpriseAuthManager.class, ctx -> authManager, false);
    procedures.registerComponent(EnterpriseSecurityContext.class, ctx -> asEnterprise(ctx.get(SECURITY_CONTEXT)), true);
    if (config.get(SecuritySettings.native_authentication_enabled) || config.get(SecuritySettings.native_authorization_enabled)) {
        procedures.registerComponent(EnterpriseUserManager.class, ctx -> authManager.getUserManager(asEnterprise(ctx.get(SECURITY_CONTEXT))), true);
        if (config.get(SecuritySettings.auth_providers).size() > 1) {
            procedures.registerProcedure(UserManagementProcedures.class, true, Optional.of("%s only applies to native users."));
        } else {
            procedures.registerProcedure(UserManagementProcedures.class, true);
        }
    } else {
        procedures.registerComponent(EnterpriseUserManager.class, ctx -> EnterpriseUserManager.NOOP, true);
    }
    procedures.registerProcedure(SecurityProcedures.class, true);
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) LogProvider(org.neo4j.logging.LogProvider) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Config(org.neo4j.kernel.configuration.Config) Procedures(org.neo4j.kernel.impl.proc.Procedures) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) SecurityLog(org.neo4j.server.security.enterprise.log.SecurityLog) GraphDatabaseFacade(org.neo4j.kernel.impl.factory.GraphDatabaseFacade)

Example 60 with FileSystemAbstraction

use of org.neo4j.io.fs.FileSystemAbstraction in project neo4j by neo4j.

the class FileRoleRepositoryTest method shouldRecoverIfCrashedDuringMove.

@Test
public void shouldRecoverIfCrashedDuringMove() throws Throwable {
    // Given
    final IOException exception = new IOException("simulated IO Exception on create");
    FileSystemAbstraction craschingFileSystem = new DelegatingFileSystemAbstraction(fs) {

        @Override
        public void renameFile(File oldLocation, File newLocation, CopyOption... copyOptions) throws IOException {
            if (roleFile.getName().equals(newLocation.getName())) {
                throw exception;
            }
            super.renameFile(oldLocation, newLocation, copyOptions);
        }
    };
    roleRepository = new FileRoleRepository(craschingFileSystem, roleFile, logProvider);
    roleRepository.start();
    RoleRecord role = new RoleRecord("admin", "jake");
    // When
    try {
        roleRepository.create(role);
        fail("Expected an IOException");
    } catch (IOException e) {
        assertSame(exception, e);
    }
    // Then
    assertFalse(craschingFileSystem.fileExists(roleFile));
    assertThat(craschingFileSystem.listFiles(roleFile.getParentFile()).length, equalTo(0));
}
Also used : DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) DelegateFileSystemAbstraction(org.neo4j.io.fs.DelegateFileSystemAbstraction) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) CopyOption(java.nio.file.CopyOption) IOException(java.io.IOException) DelegatingFileSystemAbstraction(org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction) File(java.io.File) Test(org.junit.Test)

Aggregations

FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)125 File (java.io.File)88 Test (org.junit.Test)82 DefaultFileSystemAbstraction (org.neo4j.io.fs.DefaultFileSystemAbstraction)34 IOException (java.io.IOException)28 Config (org.neo4j.kernel.configuration.Config)23 EphemeralFileSystemAbstraction (org.neo4j.graphdb.mockfs.EphemeralFileSystemAbstraction)22 PageCache (org.neo4j.io.pagecache.PageCache)22 DelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.DelegatingFileSystemAbstraction)20 ByteBuffer (java.nio.ByteBuffer)13 StoreChannel (org.neo4j.io.fs.StoreChannel)11 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)10 UncloseableDelegatingFileSystemAbstraction (org.neo4j.graphdb.mockfs.UncloseableDelegatingFileSystemAbstraction)9 DefaultIdGeneratorFactory (org.neo4j.kernel.impl.store.id.DefaultIdGeneratorFactory)9 OutputStream (java.io.OutputStream)8 AdversarialFileSystemAbstraction (org.neo4j.adversaries.fs.AdversarialFileSystemAbstraction)8 DelegatingStoreChannel (org.neo4j.graphdb.mockfs.DelegatingStoreChannel)8 Map (java.util.Map)7 Matchers.containsString (org.hamcrest.Matchers.containsString)7 AdversarialPagedFile (org.neo4j.adversaries.pagecache.AdversarialPagedFile)7