Search in sources :

Example 36 with Monitors

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

the class MultiPaxosServer method start.

public void start() throws IOException {
    broadcastSerializer = new AtomicBroadcastSerializer(new ObjectStreamFactory(), new ObjectStreamFactory());
    final LifeSupport life = new LifeSupport();
    try {
        MessageTimeoutStrategy timeoutStrategy = new MessageTimeoutStrategy(new FixedTimeoutStrategy(5000)).timeout(HeartbeatMessage.sendHeartbeat, 200);
        Monitors monitors = new Monitors();
        NetworkedServerFactory serverFactory = new NetworkedServerFactory(life, new MultiPaxosServerFactory(new ClusterConfiguration("default", NullLogProvider.getInstance()), NullLogProvider.getInstance(), monitors.newMonitor(StateMachines.Monitor.class)), timeoutStrategy, NullLogProvider.getInstance(), new ObjectStreamFactory(), new ObjectStreamFactory(), monitors.newMonitor(NetworkReceiver.Monitor.class), monitors.newMonitor(NetworkSender.Monitor.class), monitors.newMonitor(NamedThreadFactory.Monitor.class));
        ServerIdElectionCredentialsProvider electionCredentialsProvider = new ServerIdElectionCredentialsProvider();
        server = serverFactory.newNetworkedServer(Config.embeddedDefaults(), new InMemoryAcceptorInstanceStore(), electionCredentialsProvider);
        server.addBindingListener(electionCredentialsProvider);
        server.addBindingListener(new BindingListener() {

            @Override
            public void listeningAt(URI me) {
                System.out.println("Listening at:" + me);
            }
        });
        cluster = server.newClient(Cluster.class);
        cluster.addClusterListener(new ClusterListener() {

            @Override
            public void enteredCluster(ClusterConfiguration clusterConfiguration) {
                System.out.println("Entered cluster:" + clusterConfiguration);
            }

            @Override
            public void joinedCluster(InstanceId instanceId, URI member) {
                System.out.println("Joined cluster:" + instanceId + " (at URI " + member + ")");
            }

            @Override
            public void leftCluster(InstanceId instanceId, URI member) {
                System.out.println("Left cluster:" + instanceId);
            }

            @Override
            public void leftCluster() {
                System.out.println("Left cluster");
            }

            @Override
            public void elected(String role, InstanceId instanceId, URI electedMember) {
                System.out.println(instanceId + " at URI " + electedMember + " was elected as " + role);
            }

            @Override
            public void unelected(String role, InstanceId instanceId, URI electedMember) {
                System.out.println(instanceId + " at URI " + electedMember + " was removed from " + role);
            }
        });
        Heartbeat heartbeat = server.newClient(Heartbeat.class);
        heartbeat.addHeartbeatListener(new HeartbeatListener() {

            @Override
            public void failed(InstanceId server) {
                System.out.println(server + " failed");
            }

            @Override
            public void alive(InstanceId server) {
                System.out.println(server + " alive");
            }
        });
        broadcast = server.newClient(AtomicBroadcast.class);
        broadcast.addAtomicBroadcastListener(new AtomicBroadcastListener() {

            @Override
            public void receive(Payload value) {
                try {
                    System.out.println(broadcastSerializer.receive(value));
                } catch (IOException e) {
                    e.printStackTrace();
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        });
        life.start();
        String command;
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (!(command = reader.readLine()).equals("quit")) {
            String[] arguments = command.split(" ");
            Method method = getCommandMethod(arguments[0]);
            if (method != null) {
                String[] realArgs = new String[arguments.length - 1];
                System.arraycopy(arguments, 1, realArgs, 0, realArgs.length);
                try {
                    method.invoke(this, (Object[]) realArgs);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
        cluster.leave();
    } finally {
        life.shutdown();
        System.out.println("Done");
    }
}
Also used : FixedTimeoutStrategy(org.neo4j.cluster.timeout.FixedTimeoutStrategy) NetworkedServerFactory(org.neo4j.cluster.NetworkedServerFactory) ClusterConfiguration(org.neo4j.cluster.protocol.cluster.ClusterConfiguration) URI(java.net.URI) AtomicBroadcastListener(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastListener) BindingListener(org.neo4j.cluster.BindingListener) LifeSupport(org.neo4j.kernel.lifecycle.LifeSupport) ServerIdElectionCredentialsProvider(org.neo4j.cluster.protocol.election.ServerIdElectionCredentialsProvider) AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) InputStreamReader(java.io.InputStreamReader) InstanceId(org.neo4j.cluster.InstanceId) AtomicBroadcast(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast) StateMachines(org.neo4j.cluster.StateMachines) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) IOException(java.io.IOException) Method(java.lang.reflect.Method) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) InvocationTargetException(java.lang.reflect.InvocationTargetException) HeartbeatListener(org.neo4j.cluster.protocol.heartbeat.HeartbeatListener) ClusterListener(org.neo4j.cluster.protocol.cluster.ClusterListener) Heartbeat(org.neo4j.cluster.protocol.heartbeat.Heartbeat) Monitors(org.neo4j.kernel.monitoring.Monitors) MultiPaxosServerFactory(org.neo4j.cluster.MultiPaxosServerFactory) BufferedReader(java.io.BufferedReader) MessageTimeoutStrategy(org.neo4j.cluster.timeout.MessageTimeoutStrategy) Payload(org.neo4j.cluster.protocol.atomicbroadcast.Payload)

Example 37 with Monitors

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

the class MultiPaxosTest method testFailure.

@Test
public void testFailure() throws Exception {
    ScriptableNetworkFailureLatencyStrategy networkLatency = new ScriptableNetworkFailureLatencyStrategy();
    NetworkMock network = new NetworkMock(NullLogService.getInstance(), new Monitors(), 50, new MultipleFailureLatencyStrategy(networkLatency), new MessageTimeoutStrategy(new FixedTimeoutStrategy(1000)));
    List<TestProtocolServer> nodes = new ArrayList<TestProtocolServer>();
    TestProtocolServer server = network.addServer(1, URI.create("cluster://server1"));
    server.newClient(Cluster.class).create("default");
    network.tickUntilDone();
    nodes.add(server);
    for (int i = 1; i < 3; i++) {
        TestProtocolServer protocolServer = network.addServer(i + 1, new URI("cluster://server" + (i + 1)));
        protocolServer.newClient(Cluster.class).join("default", new URI("cluster://server1"));
        network.tick(10);
        nodes.add(protocolServer);
    }
    final AtomicBroadcast atomicBroadcast = nodes.get(0).newClient(AtomicBroadcast.class);
    ObjectStreamFactory objectStreamFactory = new ObjectStreamFactory();
    final AtomicBroadcastSerializer serializer = new AtomicBroadcastSerializer(objectStreamFactory, objectStreamFactory);
    atomicBroadcast.broadcast(serializer.broadcast(new DaPayload()));
    networkLatency.nodeIsDown("cluster://server2");
    networkLatency.nodeIsDown("cluster://server3");
    atomicBroadcast.broadcast(serializer.broadcast(new DaPayload()));
    network.tick(100);
    networkLatency.nodeIsUp("cluster://server3");
    network.tick(1000);
    for (TestProtocolServer node : nodes) {
        node.newClient(Cluster.class).leave();
        network.tick(10);
    }
}
Also used : AtomicBroadcastSerializer(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcastSerializer) FixedTimeoutStrategy(org.neo4j.cluster.timeout.FixedTimeoutStrategy) NetworkMock(org.neo4j.cluster.NetworkMock) ScriptableNetworkFailureLatencyStrategy(org.neo4j.cluster.ScriptableNetworkFailureLatencyStrategy) MultipleFailureLatencyStrategy(org.neo4j.cluster.MultipleFailureLatencyStrategy) AtomicBroadcast(org.neo4j.cluster.protocol.atomicbroadcast.AtomicBroadcast) ArrayList(java.util.ArrayList) Cluster(org.neo4j.cluster.protocol.cluster.Cluster) URI(java.net.URI) ObjectStreamFactory(org.neo4j.cluster.protocol.atomicbroadcast.ObjectStreamFactory) TestProtocolServer(org.neo4j.cluster.TestProtocolServer) Monitors(org.neo4j.kernel.monitoring.Monitors) MessageTimeoutStrategy(org.neo4j.cluster.timeout.MessageTimeoutStrategy) Test(org.junit.Test)

Example 38 with Monitors

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

the class DefaultMasterImplSPITest method flushStoreFilesWithCorrectCheckpointTriggerName.

@Test
public void flushStoreFilesWithCorrectCheckpointTriggerName() throws IOException {
    CheckPointer checkPointer = mock(CheckPointer.class);
    NeoStoreDataSource dataSource = mock(NeoStoreDataSource.class);
    when(dataSource.listStoreFiles(anyBoolean())).thenReturn(Iterators.emptyIterator());
    DefaultMasterImplSPI master = new DefaultMasterImplSPI(mock(GraphDatabaseAPI.class, RETURNS_MOCKS), mock(FileSystemAbstraction.class), new Monitors(), mock(LabelTokenHolder.class), mock(PropertyKeyTokenHolder.class), mock(RelationshipTypeTokenHolder.class), mock(IdGeneratorFactory.class), mock(TransactionCommitProcess.class), checkPointer, mock(TransactionIdStore.class), mock(LogicalTransactionStore.class), dataSource, mock(PageCache.class), new StoreCopyCheckPointMutex());
    master.flushStoresAndStreamStoreFiles(mock(StoreWriter.class));
    TriggerInfo expectedTriggerInfo = new SimpleTriggerInfo(DefaultMasterImplSPI.STORE_COPY_CHECKPOINT_TRIGGER);
    verify(checkPointer).tryCheckPoint(expectedTriggerInfo);
}
Also used : FileSystemAbstraction(org.neo4j.io.fs.FileSystemAbstraction) RelationshipTypeTokenHolder(org.neo4j.kernel.impl.core.RelationshipTypeTokenHolder) TransactionIdStore(org.neo4j.kernel.impl.transaction.log.TransactionIdStore) NeoStoreDataSource(org.neo4j.kernel.NeoStoreDataSource) TransactionCommitProcess(org.neo4j.kernel.impl.api.TransactionCommitProcess) TriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.TriggerInfo) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) IdGeneratorFactory(org.neo4j.kernel.impl.store.id.IdGeneratorFactory) LogicalTransactionStore(org.neo4j.kernel.impl.transaction.log.LogicalTransactionStore) SimpleTriggerInfo(org.neo4j.kernel.impl.transaction.log.checkpoint.SimpleTriggerInfo) GraphDatabaseAPI(org.neo4j.kernel.internal.GraphDatabaseAPI) PropertyKeyTokenHolder(org.neo4j.kernel.impl.core.PropertyKeyTokenHolder) StoreWriter(org.neo4j.com.storecopy.StoreWriter) CheckPointer(org.neo4j.kernel.impl.transaction.log.checkpoint.CheckPointer) Monitors(org.neo4j.kernel.monitoring.Monitors) StoreCopyCheckPointMutex(org.neo4j.kernel.impl.transaction.log.checkpoint.StoreCopyCheckPointMutex) LabelTokenHolder(org.neo4j.kernel.impl.core.LabelTokenHolder) PageCache(org.neo4j.io.pagecache.PageCache) Test(org.junit.Test)

Example 39 with Monitors

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

the class RaftMachineTest method shouldMonitorLeaderNotFound.

@Test
public void shouldMonitorLeaderNotFound() throws Exception {
    // Given
    ControlledRenewableTimeoutService timeouts = new ControlledRenewableTimeoutService();
    Monitors monitors = new Monitors();
    LeaderNotFoundMonitor leaderNotFoundMonitor = new StubLeaderNotFoundMonitor();
    monitors.addMonitorListener(leaderNotFoundMonitor);
    RaftMachine raft = new RaftMachineBuilder(myself, 3, RaftTestMemberSetBuilder.INSTANCE).timeoutService(timeouts).monitors(monitors).build();
    raft.installCoreState(new RaftCoreState(new MembershipEntry(0, asSet(myself, member1, member2))));
    try {
        // When
        // There is no leader
        raft.getLeader();
        fail("Should have thrown exception");
    }// Then
     catch (NoLeaderFoundException e) {
        // expected
        assertEquals(1, leaderNotFoundMonitor.leaderNotFoundExceptions());
    }
}
Also used : MembershipEntry(org.neo4j.causalclustering.core.consensus.membership.MembershipEntry) RaftCoreState(org.neo4j.causalclustering.core.state.snapshot.RaftCoreState) Monitors(org.neo4j.kernel.monitoring.Monitors) ControlledRenewableTimeoutService(org.neo4j.causalclustering.core.consensus.schedule.ControlledRenewableTimeoutService) Test(org.junit.Test)

Example 40 with Monitors

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

the class MonitoredRaftLogTest method shouldMonitorAppendIndexAndCommitIndex.

@Test
public void shouldMonitorAppendIndexAndCommitIndex() throws Exception {
    // Given
    Monitors monitors = new Monitors();
    StubRaftLogAppendIndexMonitor appendMonitor = new StubRaftLogAppendIndexMonitor();
    monitors.addMonitorListener(appendMonitor);
    StubRaftLogCommitIndexMonitor commitMonitor = new StubRaftLogCommitIndexMonitor();
    monitors.addMonitorListener(commitMonitor);
    MonitoredRaftLog log = new MonitoredRaftLog(new InMemoryRaftLog(), monitors);
    // When
    log.append(new RaftLogEntry(0, ReplicatedInteger.valueOf(1)));
    log.append(new RaftLogEntry(0, ReplicatedInteger.valueOf(1)));
    assertEquals(1, appendMonitor.appendIndex());
    assertEquals(0, commitMonitor.commitIndex());
    log.truncate(1);
    assertEquals(0, appendMonitor.appendIndex());
}
Also used : Monitors(org.neo4j.kernel.monitoring.Monitors) Test(org.junit.Test)

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