com.alipay.sofa.jraft.option.CliOptions Java Examples
The following examples show how to use
com.alipay.sofa.jraft.option.CliOptions.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractRheaKVStoreTest.java From sofa-jraft with Apache License 2.0 | 6 votes |
@Test public void rangeSplitTest() { final RheaKVStore store = getRandomLeaderStore(); final long regionId = 1; for (int i = 0; i < 20; i++) { store.bPut("a" + i, BytesUtil.writeUtf8("split")); } final CliOptions opts = new CliOptions(); opts.setTimeoutMs(30000); final RheaKVCliService cliService = RheaKVServiceFactory.createAndInitRheaKVCliService(opts); final long newRegionId = 101; final String groupId = JRaftHelper.getJRaftGroupId("rhea_test", regionId); final Configuration conf = JRaftUtils.getConfiguration("127.0.0.1:18181,127.0.0.1:18182,127.0.0.1:18183"); final Status st = cliService.rangeSplit(regionId, newRegionId, groupId, conf); System.err.println("Status:" + st); assertTrue(st.isOk()); final RheaKVStore newStore = getLeaderStore(101); newStore.bPut("f_first_key", BytesUtil.writeUtf8("split_ok")); assertArrayEquals(BytesUtil.writeUtf8("split_ok"), newStore.bGet("f_first_key")); }
Example #2
Source File: CliClientServiceImpl.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Override public synchronized boolean init(final RpcOptions rpcOptions) { boolean ret = super.init(rpcOptions); if (ret) { this.cliOptions = (CliOptions) this.rpcOptions; } return ret; }
Example #3
Source File: DmetaClient.java From distkv with BSD 3-Clause "New" or "Revised" License | 5 votes |
public DmetaClient(String confStr) { final Configuration conf = JRaftUtils.getConfiguration(confStr); RouteTable.getInstance().updateConfiguration(RAFT_GROUP_ID, conf); //init RPC client and update Routing table cliClientService = new BoltCliClientService(); cliClientService.init(new CliOptions()); refreshLeader(); }
Example #4
Source File: RaftClient.java From sofa-registry with Apache License 2.0 | 5 votes |
/** * @param groupId * @param confStr * @param cliClientService */ public RaftClient(String groupId, String confStr, AbstractBoltClientService cliClientService) { this.groupId = groupId; conf = new Configuration(); if (!conf.parse(confStr)) { throw new IllegalArgumentException("Fail to parse conf:" + confStr); } cliOptions = new CliOptions(); this.cliClientService = (BoltCliClientService) cliClientService; }
Example #5
Source File: RaftClient.java From sofa-registry with Apache License 2.0 | 5 votes |
/** * @param groupId * @param confStr Example: 127.0.0.1:8081,127.0.0.1:8082,127.0.0.1:8083 */ public RaftClient(String groupId, String confStr) { this.groupId = groupId; conf = new Configuration(); if (!conf.parse(confStr)) { throw new IllegalArgumentException("Fail to parse conf:" + confStr); } cliOptions = new CliOptions(); cliClientService = new BoltCliClientService(); }
Example #6
Source File: RaftExchanger.java From sofa-registry with Apache License 2.0 | 5 votes |
/** * start cli service */ public void startCliService() { if (clsStart.compareAndSet(false, true)) { try { cliService = new CliServiceImpl(); cliService.init(new CliOptions()); } catch (Exception e) { LOGGER_START.error("Start raft cliService error!", e); throw new RuntimeException("Start raft cliService error!", e); } } }
Example #7
Source File: CounterClient.java From sofa-jraft with Apache License 2.0 | 5 votes |
public static void main(final String[] args) throws Exception { if (args.length != 2) { System.out.println("Useage : java com.alipay.sofa.jraft.example.counter.CounterClient {groupId} {conf}"); System.out .println("Example: java com.alipay.sofa.jraft.example.counter.CounterClient counter 127.0.0.1:8081,127.0.0.1:8082,127.0.0.1:8083"); System.exit(1); } final String groupId = args[0]; final String confStr = args[1]; final Configuration conf = new Configuration(); if (!conf.parse(confStr)) { throw new IllegalArgumentException("Fail to parse conf:" + confStr); } RouteTable.getInstance().updateConfiguration(groupId, conf); final CliClientServiceImpl cliClientService = new CliClientServiceImpl(); cliClientService.init(new CliOptions()); if (!RouteTable.getInstance().refreshLeader(cliClientService, groupId, 1000).isOk()) { throw new IllegalStateException("Refresh leader failed"); } final PeerId leader = RouteTable.getInstance().selectLeader(groupId); System.out.println("Leader is " + leader); final int n = 1000; final CountDownLatch latch = new CountDownLatch(n); final long start = System.currentTimeMillis(); for (int i = 0; i < n; i++) { incrementAndGet(cliClientService, leader, i, latch); } latch.await(); System.out.println(n + " ops, cost : " + (System.currentTimeMillis() - start) + " ms."); System.exit(0); }
Example #8
Source File: RouteTableTest.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { cliClientService = new CliClientServiceImpl(); cliClientService.init(new CliOptions()); this.dataPath = TestUtils.mkTempDir(); FileUtils.forceMkdir(new File(this.dataPath)); assertEquals(NodeImpl.GLOBAL_NUM_NODES.get(), 0); final List<PeerId> peers = TestUtils.generatePeers(3); cluster = new TestCluster(groupId, dataPath, peers); for (final PeerId peer : peers) { cluster.start(peer.getEndpoint()); } cluster.waitLeader(); }
Example #9
Source File: CliServiceImpl.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Override public synchronized boolean init(final CliOptions opts) { Requires.requireNonNull(opts, "Null cli options"); if (this.cliClientService != null) { return true; } this.cliOptions = opts; this.cliClientService = new CliClientServiceImpl(); return this.cliClientService.init(this.cliOptions); }
Example #10
Source File: RaftServiceFactory.java From sofa-jraft with Apache License 2.0 | 5 votes |
/** * Create and initialize a CliService instance. */ public static CliService createAndInitCliService(final CliOptions cliOptions) { final CliService ret = createCliService(); if (!ret.init(cliOptions)) { throw new IllegalStateException("Fail to init CliService"); } return ret; }
Example #11
Source File: AtomicClient.java From sofa-jraft with Apache License 2.0 | 5 votes |
public void start() throws InterruptedException, TimeoutException { cliOptions = new CliOptions(); this.cliClientService.init(cliOptions); this.rpcClient = this.cliClientService.getRpcClient(); if (conf != null) { final Set<PeerId> peers = conf.getPeerSet(); for (final PeerId peer : peers) { try { final BooleanCommand cmd = (BooleanCommand) this.rpcClient.invokeSync(peer.getEndpoint(), new GetSlotsCommand(), cliOptions.getRpcDefaultTimeout()); if (cmd instanceof SlotsResponseCommand) { groups = ((SlotsResponseCommand) cmd).getMap(); break; } else { LOG.warn("Fail to get slots from peer {}, error: {}", peer, cmd.getErrorMsg()); } } catch (final Throwable t) { LOG.warn("Fail to get slots from peer {}, error: {}", peer, t.getMessage()); //continue; } } if (groups == null || groups.isEmpty()) { throw new IllegalArgumentException("Can't get slots from any peers"); } else { LOG.info("All groups is {}", groups); } for (final String groupId : groups.values()) { RouteTable.getInstance().updateConfiguration(groupId, conf); refreshLeader(groupId); refreshConf(groupId); } } }
Example #12
Source File: RouteTableTest.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { cliClientService = new CliClientServiceImpl(); cliClientService.init(new CliOptions()); this.dataPath = TestUtils.mkTempDir(); FileUtils.forceMkdir(new File(this.dataPath)); assertEquals(NodeImpl.GLOBAL_NUM_NODES.get(), 0); final List<PeerId> peers = TestUtils.generatePeers(3); cluster = new TestCluster(groupId, dataPath, peers); for (final PeerId peer : peers) { cluster.start(peer.getEndpoint()); } cluster.waitLeader(); }
Example #13
Source File: DefaultRheaKVCliService.java From sofa-jraft with Apache License 2.0 | 5 votes |
@Override public boolean init(final CliOptions opts) { if (this.started) { LOG.info("[DefaultRheaKVRpcService] already started."); return true; } initCli(opts); LOG.info("[DefaultRheaKVCliService] start successfully, options: {}.", opts); return this.started = true; }
Example #14
Source File: RheaKVServiceFactory.java From sofa-jraft with Apache License 2.0 | 5 votes |
/** * Create and initialize a RheaKVCliService instance. */ public static RheaKVCliService createAndInitRheaKVCliService(final CliOptions opts) { final RheaKVCliService cliService = new DefaultRheaKVCliService(); if (!cliService.init(opts)) { throw new IllegalStateException("Fail to init RheaKVCliService"); } return cliService; }
Example #15
Source File: PlacementDriverOptions.java From sofa-jraft with Apache License 2.0 | 4 votes |
public CliOptions getCliOptions() { return cliOptions; }
Example #16
Source File: PlacementDriverOptionsConfigured.java From sofa-jraft with Apache License 2.0 | 4 votes |
public PlacementDriverOptionsConfigured withCliOptions(final CliOptions cliOptions) { this.opts.setCliOptions(cliOptions); return this; }
Example #17
Source File: PlacementDriverOptions.java From sofa-jraft with Apache License 2.0 | 4 votes |
public void setCliOptions(CliOptions cliOptions) { this.cliOptions = cliOptions; }