use of com.alipay.sofa.jraft.option.NodeOptions in project sofa-jraft by sofastack.
the class SnapshotExecutorTest method testNotDoSnapshotWithIntervalDist.
@Test
public void testNotDoSnapshotWithIntervalDist() throws Exception {
final NodeOptions nodeOptions = new NodeOptions();
nodeOptions.setSnapshotLogIndexMargin(10);
Mockito.when(this.node.getOptions()).thenReturn(nodeOptions);
Mockito.when(this.fSMCaller.getLastAppliedIndex()).thenReturn(1L);
this.executor.doSnapshot(null);
this.executor.join();
assertEquals(0, this.executor.getLastSnapshotTerm());
assertEquals(0, this.executor.getLastSnapshotIndex());
}
use of com.alipay.sofa.jraft.option.NodeOptions in project sofa-jraft by sofastack.
the class AbstractCliRequestProcessorTest method testHandleRequest.
@Test
public void testHandleRequest() {
this.mockNodes(3);
Mockito.when(this.node.getGroupId()).thenReturn(this.groupId);
PeerId peerId = new PeerId();
peerId.parse(this.peerIdStr);
Mockito.when(this.node.getOptions()).thenReturn(new NodeOptions());
Mockito.when(this.node.getNodeId()).thenReturn(new NodeId("test", peerId));
NodeManager.getInstance().addAddress(peerId.getEndpoint());
NodeManager.getInstance().add(this.node);
BaseCliRequestProcessor<T> processor = newProcessor();
processor.handleRequest(this.asyncContext, createRequest(this.groupId, peerId));
ArgumentCaptor<Closure> doneArg = ArgumentCaptor.forClass(Closure.class);
verify(processor.interest(), this.node, doneArg);
}
use of com.alipay.sofa.jraft.option.NodeOptions in project sofa-jraft by sofastack.
the class BaseCliRequestProcessorTest method mockNode.
private Node mockNode(boolean disableCli) {
Node node = Mockito.mock(Node.class);
Mockito.when(node.getGroupId()).thenReturn("test");
Mockito.when(node.getNodeId()).thenReturn(new NodeId("test", this.peer.copy()));
NodeOptions opts = new NodeOptions();
opts.setDisableCli(disableCli);
Mockito.when(node.getOptions()).thenReturn(opts);
NodeManager.getInstance().addAddress(this.peer.getEndpoint());
NodeManager.getInstance().add(node);
return node;
}
use of com.alipay.sofa.jraft.option.NodeOptions in project sofa-jraft by sofastack.
the class RegionEngine method init.
@Override
public synchronized boolean init(final RegionEngineOptions opts) {
if (this.started) {
LOG.info("[RegionEngine: {}] already started.", this.region);
return true;
}
this.regionOpts = Requires.requireNonNull(opts, "opts");
this.fsm = new KVStoreStateMachine(this.region, this.storeEngine);
// node options
NodeOptions nodeOpts = opts.getNodeOptions();
if (nodeOpts == null) {
nodeOpts = new NodeOptions();
}
final long metricsReportPeriod = opts.getMetricsReportPeriod();
if (metricsReportPeriod > 0) {
// metricsReportPeriod > 0 means enable metrics
nodeOpts.setEnableMetrics(true);
}
final Configuration initialConf = new Configuration();
if (!initialConf.parse(opts.getInitialServerList())) {
LOG.error("Fail to parse initial configuration {}.", opts.getInitialServerList());
return false;
}
nodeOpts.setInitialConf(initialConf);
nodeOpts.setFsm(this.fsm);
final String raftDataPath = opts.getRaftDataPath();
try {
FileUtils.forceMkdir(new File(raftDataPath));
} catch (final Throwable t) {
LOG.error("Fail to make dir for raftDataPath {}.", raftDataPath);
return false;
}
if (Strings.isBlank(nodeOpts.getLogUri())) {
final Path logUri = Paths.get(raftDataPath, "log");
nodeOpts.setLogUri(logUri.toString());
}
if (Strings.isBlank(nodeOpts.getRaftMetaUri())) {
final Path meteUri = Paths.get(raftDataPath, "meta");
nodeOpts.setRaftMetaUri(meteUri.toString());
}
if (Strings.isBlank(nodeOpts.getSnapshotUri())) {
final Path snapshotUri = Paths.get(raftDataPath, "snapshot");
nodeOpts.setSnapshotUri(snapshotUri.toString());
}
LOG.info("[RegionEngine: {}], log uri: {}, raft meta uri: {}, snapshot uri: {}.", this.region, nodeOpts.getLogUri(), nodeOpts.getRaftMetaUri(), nodeOpts.getSnapshotUri());
final Endpoint serverAddress = opts.getServerAddress();
final PeerId serverId = new PeerId(serverAddress, 0);
final RpcServer rpcServer = this.storeEngine.getRpcServer();
this.raftGroupService = new RaftGroupService(opts.getRaftGroupId(), serverId, nodeOpts, rpcServer, true);
this.node = this.raftGroupService.start(false);
RouteTable.getInstance().updateConfiguration(this.raftGroupService.getGroupId(), nodeOpts.getInitialConf());
if (this.node != null) {
final RawKVStore rawKVStore = this.storeEngine.getRawKVStore();
final Executor readIndexExecutor = this.storeEngine.getReadIndexExecutor();
this.raftRawKVStore = new RaftRawKVStore(this.node, rawKVStore, readIndexExecutor);
this.metricsRawKVStore = new MetricsRawKVStore(this.region.getId(), this.raftRawKVStore);
// metrics config
if (this.regionMetricsReporter == null && metricsReportPeriod > 0) {
final MetricRegistry metricRegistry = this.node.getNodeMetrics().getMetricRegistry();
if (metricRegistry != null) {
final ScheduledExecutorService scheduler = this.storeEngine.getMetricsScheduler();
// start raft node metrics reporter
this.regionMetricsReporter = //
Slf4jReporter.forRegistry(metricRegistry).prefixedWith(//
"region_" + this.region.getId()).withLoggingLevel(//
Slf4jReporter.LoggingLevel.INFO).outputTo(//
LOG).scheduleOn(//
scheduler).shutdownExecutorOnStop(//
scheduler != null).build();
this.regionMetricsReporter.start(metricsReportPeriod, TimeUnit.SECONDS);
}
}
this.started = true;
LOG.info("[RegionEngine] start successfully: {}.", this);
}
return this.started;
}
use of com.alipay.sofa.jraft.option.NodeOptions in project sofa-jraft by sofastack.
the class DefaultRaftClientServiceTest method setup.
@Before
public void setup() {
this.clientService = new DefaultRaftClientService(this.rgGroup);
this.clientService.init(new NodeOptions());
}
Aggregations