Search in sources :

Example 1 with RaftDbErrorEvent

use of com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent in project nacos by alibaba.

the class DistributedDatabaseOperateImpl method init.

protected void init() throws Exception {
    this.dataSourceService = (LocalDataSourceServiceImpl) DynamicDataSource.getInstance().getDataSource();
    // Because in Raft + Derby mode, ensuring data consistency depends on the Raft's
    // log playback and snapshot recovery capabilities, and the last data must be cleared
    this.dataSourceService.cleanAndReopenDerby();
    this.jdbcTemplate = dataSourceService.getJdbcTemplate();
    this.transactionTemplate = dataSourceService.getTransactionTemplate();
    // Registers a Derby Raft state machine failure event for node degradation processing
    NotifyCenter.registerToSharePublisher(RaftDbErrorEvent.class);
    // Register the snapshot load event
    NotifyCenter.registerToSharePublisher(DerbyLoadEvent.class);
    NotifyCenter.registerSubscriber(new Subscriber<RaftDbErrorEvent>() {

        @Override
        public void onEvent(RaftDbErrorEvent event) {
            dataSourceService.setHealthStatus("DOWN");
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return RaftDbErrorEvent.class;
        }
    });
    NotifyCenter.registerToPublisher(ConfigDumpEvent.class, NotifyCenter.ringBufferSize);
    NotifyCenter.registerSubscriber(new DumpConfigHandler());
    this.protocol.addRequestProcessors(Collections.singletonList(this));
    LogUtil.DEFAULT_LOG.info("use DistributedTransactionServicesImpl");
}
Also used : DumpConfigHandler(com.alibaba.nacos.config.server.service.dump.DumpConfigHandler) RaftDbErrorEvent(com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent) Event(com.alibaba.nacos.common.notify.Event) DerbyLoadEvent(com.alibaba.nacos.config.server.model.event.DerbyLoadEvent) ConfigDumpEvent(com.alibaba.nacos.config.server.model.event.ConfigDumpEvent) RaftDbErrorEvent(com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent)

Example 2 with RaftDbErrorEvent

use of com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent in project nacos by alibaba.

the class ConfigDerbyRaft_DITCase method test_h_derby_has_error.

@Test
public void test_h_derby_has_error() throws Exception {
    ThreadUtils.sleep(5000);
    boolean result = iconfig7.publishConfig("raft_test_raft_error", "cluster_test_1", "this.is.raft_cluster=lessspring_7");
    Assert.assertTrue(result);
    NotifyCenter.registerToPublisher(RaftDbErrorRecoverEvent.class, 8);
    CountDownLatch latch1 = new CountDownLatch(1);
    NotifyCenter.registerSubscriber(new Subscriber<RaftDbErrorEvent>() {

        @Override
        public void onEvent(RaftDbErrorEvent event) {
            latch1.countDown();
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return RaftDbErrorEvent.class;
        }
    });
    NotifyCenter.publishEvent(new RaftDbErrorEvent());
    latch1.await(10_000L, TimeUnit.MILLISECONDS);
    result = iconfig7.publishConfig("raft_test_raft_error", "cluster_test_1", "this.is.raft_cluster=lessspring_7");
    Assert.assertFalse(result);
    CountDownLatch latch2 = new CountDownLatch(1);
    NotifyCenter.registerSubscriber(new Subscriber<RaftDbErrorRecoverEvent>() {

        @Override
        public void onEvent(RaftDbErrorRecoverEvent event) {
            latch2.countDown();
        }

        @Override
        public Class<? extends Event> subscribeType() {
            return RaftDbErrorRecoverEvent.class;
        }
    });
    NotifyCenter.publishEvent(new RaftDbErrorRecoverEvent());
    latch2.await(10_000L, TimeUnit.MILLISECONDS);
    result = iconfig7.publishConfig("raft_test_raft_error", "cluster_test_1", "this.is.raft_cluster=lessspring_7");
    Assert.assertTrue(result);
}
Also used : RaftDbErrorRecoverEvent(com.alibaba.nacos.config.server.model.event.RaftDbErrorRecoverEvent) RaftDbErrorRecoverEvent(com.alibaba.nacos.config.server.model.event.RaftDbErrorRecoverEvent) RaftDbErrorEvent(com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent) Event(com.alibaba.nacos.common.notify.Event) BeforeClass(org.junit.BeforeClass) CountDownLatch(java.util.concurrent.CountDownLatch) RaftDbErrorEvent(com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent) Test(org.junit.Test) BaseClusterTest(com.alibaba.nacos.test.base.BaseClusterTest)

Aggregations

Event (com.alibaba.nacos.common.notify.Event)2 RaftDbErrorEvent (com.alibaba.nacos.config.server.model.event.RaftDbErrorEvent)2 ConfigDumpEvent (com.alibaba.nacos.config.server.model.event.ConfigDumpEvent)1 DerbyLoadEvent (com.alibaba.nacos.config.server.model.event.DerbyLoadEvent)1 RaftDbErrorRecoverEvent (com.alibaba.nacos.config.server.model.event.RaftDbErrorRecoverEvent)1 DumpConfigHandler (com.alibaba.nacos.config.server.service.dump.DumpConfigHandler)1 BaseClusterTest (com.alibaba.nacos.test.base.BaseClusterTest)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 BeforeClass (org.junit.BeforeClass)1 Test (org.junit.Test)1