Search in sources :

Example 16 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TestBlockLogBuffer method canWriteReallyLargeByteArray.

@Test
public void canWriteReallyLargeByteArray() throws Exception {
    byte[] bytes = new byte[650];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
    byte[] bytesValue = new byte[600];
    bytesValue[1] = 1;
    bytesValue[99] = 2;
    bytesValue[199] = 3;
    bytesValue[299] = 4;
    bytesValue[399] = 5;
    bytesValue[499] = 6;
    bytesValue[599] = 7;
    buffer.put(bytesValue, bytesValue.length);
    buffer.close();
    byte[] actual;
    ByteBuffer verificationBuffer = ByteBuffer.wrap(bytes);
    assertEquals((byte) 0, verificationBuffer.get());
    actual = new byte[255];
    verificationBuffer.get(actual);
    assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 0, 255)));
    assertEquals((byte) 0, verificationBuffer.get());
    actual = new byte[255];
    verificationBuffer.get(actual);
    assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 255, 510)));
    assertEquals((byte) 90, verificationBuffer.get());
    actual = new byte[90];
    verificationBuffer.get(actual);
    assertThat(actual, new ArrayMatches<byte[]>(Arrays.copyOfRange(bytesValue, 510, 600)));
}
Also used : ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) BlockLogBuffer(org.neo4j.com.BlockLogBuffer) Monitors(org.neo4j.kernel.monitoring.Monitors) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 17 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TestBlockLogBuffer method readSmallPortions.

@Test
public void readSmallPortions() throws IOException {
    byte[] bytes = new byte[255];
    ChannelBuffer wrappedBuffer = ChannelBuffers.wrappedBuffer(bytes);
    wrappedBuffer.resetWriterIndex();
    BlockLogBuffer buffer = new BlockLogBuffer(wrappedBuffer, new Monitors().newMonitor(ByteCounterMonitor.class));
    byte byteValue = 5;
    int intValue = 1234;
    long longValue = 574853;
    buffer.put(byteValue);
    buffer.putInt(intValue);
    buffer.putLong(longValue);
    buffer.close();
    ReadableByteChannel reader = new BlockLogReader(wrappedBuffer);
    ByteBuffer verificationBuffer = ByteBuffer.wrap(new byte[1]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    assertEquals(byteValue, verificationBuffer.get());
    verificationBuffer = ByteBuffer.wrap(new byte[4]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    assertEquals(intValue, verificationBuffer.getInt());
    verificationBuffer = ByteBuffer.wrap(new byte[8]);
    reader.read(verificationBuffer);
    verificationBuffer.flip();
    assertEquals(longValue, verificationBuffer.getLong());
}
Also used : ByteCounterMonitor(org.neo4j.kernel.monitoring.ByteCounterMonitor) ReadableByteChannel(java.nio.channels.ReadableByteChannel) BlockLogBuffer(org.neo4j.com.BlockLogBuffer) BlockLogReader(org.neo4j.com.BlockLogReader) Monitors(org.neo4j.kernel.monitoring.Monitors) ByteBuffer(java.nio.ByteBuffer) ChannelBuffer(org.jboss.netty.buffer.ChannelBuffer) Test(org.junit.Test)

Example 18 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class QueryLoggerKernelExtension method newInstance.

@Override
public Lifecycle newInstance(@SuppressWarnings("unused") KernelContext context, final Dependencies dependencies) throws Throwable {
    final Config config = dependencies.config();
    boolean queryLogEnabled = config.get(GraphDatabaseSettings.log_queries);
    final File queryLogFile = config.get(GraphDatabaseSettings.log_queries_filename);
    final FileSystemAbstraction fileSystem = dependencies.fileSystem();
    final JobScheduler jobScheduler = dependencies.jobScheduler();
    final Monitors monitoring = dependencies.monitoring();
    if (!queryLogEnabled) {
        return createEmptyAdapter();
    }
    return new LifecycleAdapter() {

        Closeable closable;

        @Override
        public void init() throws Throwable {
            Long thresholdMillis = config.get(GraphDatabaseSettings.log_queries_threshold);
            Long rotationThreshold = config.get(GraphDatabaseSettings.log_queries_rotation_threshold);
            int maxArchives = config.get(GraphDatabaseSettings.log_queries_max_archives);
            boolean logQueryParameters = config.get(GraphDatabaseSettings.log_queries_parameter_logging_enabled);
            FormattedLog.Builder logBuilder = FormattedLog.withUTCTimeZone();
            Log log;
            if (rotationThreshold == 0) {
                OutputStream logOutputStream = createOrOpenAsOuputStream(fileSystem, queryLogFile, true);
                log = logBuilder.toOutputStream(logOutputStream);
                closable = logOutputStream;
            } else {
                RotatingFileOutputStreamSupplier rotatingSupplier = new RotatingFileOutputStreamSupplier(fileSystem, queryLogFile, rotationThreshold, 0, maxArchives, jobScheduler.executor(JobScheduler.Groups.queryLogRotation));
                log = logBuilder.toOutputStream(rotatingSupplier);
                closable = rotatingSupplier;
            }
            QueryLogger logger = new QueryLogger(Clocks.systemClock(), log, thresholdMillis, logQueryParameters);
            monitoring.addMonitorListener(logger);
        }

        @Override
        public void shutdown() throws Throwable {
            closable.close();
        }
    };
}
Also used : JobScheduler(org.neo4j.kernel.impl.util.JobScheduler) FormattedLog(org.neo4j.logging.FormattedLog) FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) Log(org.neo4j.logging.Log) FormattedLog(org.neo4j.logging.FormattedLog) Config(org.neo4j.kernel.configuration.Config) Closeable(java.io.Closeable) OutputStream(java.io.OutputStream) LifecycleAdapter(org.neo4j.kernel.lifecycle.LifecycleAdapter) RotatingFileOutputStreamSupplier(org.neo4j.logging.RotatingFileOutputStreamSupplier) Monitors(org.neo4j.kernel.monitoring.Monitors) File(java.io.File)

Example 19 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class TestStartTransactionDuringLogRotation method setUp.

@Before
public void setUp() throws InterruptedException {
    executor = Executors.newCachedThreadPool();
    startLogRotationLatch = new CountDownLatch(1);
    completeLogRotationLatch = new CountDownLatch(1);
    writerStopped = new AtomicBoolean();
    monitors = db.getDependencyResolver().resolveDependency(Monitors.class);
    rotationListener = new LogRotation.Monitor() {

        @Override
        public void startedRotating(long currentVersion) {
            startLogRotationLatch.countDown();
            try {
                completeLogRotationLatch.await();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public void finishedRotating(long currentVersion) {
        }
    };
    monitors.addMonitorListener(rotationListener);
    label = Label.label("Label");
    rotationFuture = t2.execute(forceLogRotation(db));
    // Waiting for the writer task to start a log rotation
    startLogRotationLatch.await();
// Then we should be able to start a transaction, though perhaps not be able to finish it.
// This is what the individual test methods will be doing.
// The test passes when transaction.close completes within the test timeout, that is, it didn't deadlock.
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Monitors(org.neo4j.kernel.monitoring.Monitors) LogRotation(org.neo4j.kernel.impl.transaction.log.rotation.LogRotation) CountDownLatch(java.util.concurrent.CountDownLatch) Before(org.junit.Before)

Example 20 with Monitors

use of org.neo4j.kernel.monitoring.Monitors in project neo4j by neo4j.

the class CommunityCypherEngineProvider method createEngine.

@Override
protected QueryExecutionEngine createEngine(Dependencies deps, GraphDatabaseAPI graphAPI) {
    GraphDatabaseCypherService queryService = new GraphDatabaseCypherService(graphAPI);
    deps.satisfyDependency(queryService);
    DependencyResolver resolver = graphAPI.getDependencyResolver();
    LogService logService = resolver.resolveDependency(LogService.class);
    KernelAPI kernelAPI = resolver.resolveDependency(KernelAPI.class);
    Monitors monitors = resolver.resolveDependency(Monitors.class);
    LogProvider logProvider = logService.getInternalLogProvider();
    CommunityCompatibilityFactory compatibilityFactory = new CommunityCompatibilityFactory(queryService, kernelAPI, monitors, logProvider);
    deps.satisfyDependencies(compatibilityFactory);
    return new ExecutionEngine(queryService, logProvider, compatibilityFactory);
}
Also used : LogProvider(org.neo4j.logging.LogProvider) QueryExecutionEngine(org.neo4j.kernel.impl.query.QueryExecutionEngine) Monitors(org.neo4j.kernel.monitoring.Monitors) CommunityCompatibilityFactory(org.neo4j.cypher.internal.CommunityCompatibilityFactory) GraphDatabaseCypherService(org.neo4j.cypher.javacompat.internal.GraphDatabaseCypherService) KernelAPI(org.neo4j.kernel.api.KernelAPI) LogService(org.neo4j.kernel.impl.logging.LogService) DependencyResolver(org.neo4j.graphdb.DependencyResolver)

Aggregations

Monitors (org.neo4j.kernel.monitoring.Monitors)79 Test (org.junit.Test)53 LifeSupport (org.neo4j.kernel.lifecycle.LifeSupport)12 TransactionIdStore (org.neo4j.kernel.impl.transaction.log.TransactionIdStore)11 File (java.io.File)10 ByteBuffer (java.nio.ByteBuffer)9 StoreId (org.neo4j.causalclustering.identity.StoreId)9 FileSystemAbstraction (org.neo4j.io.fs.FileSystemAbstraction)9 LogicalTransactionStore (org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore)9 ByteCounterMonitor (org.neo4j.kernel.monitoring.ByteCounterMonitor)9 IOException (java.io.IOException)8 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)8 BlockLogBuffer (org.neo4j.com.BlockLogBuffer)8 Config (org.neo4j.kernel.configuration.Config)8 PageCache (org.neo4j.io.pagecache.PageCache)7 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)7 DependencyResolver (org.neo4j.graphdb.DependencyResolver)6 URI (java.net.URI)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ClusterConfiguration (org.neo4j.cluster.protocol.cluster.ClusterConfiguration)5