Search in sources :

Example 1 with DefaultRheaKVStore

use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.

the class ChaosTestCluster method addPeer.

public synchronized void addPeer(final PeerId peerId) {
    if (this.peerIds.contains(peerId)) {
        throw new RuntimeException("peerId is exist: " + peerId);
    }
    this.peerIds.add(peerId);
    final Configuration conf = new Configuration(this.peerIds);
    final String initialServerList = conf.toString();
    final PlacementDriverOptions pdOpts = // use a fake pd
    PlacementDriverOptionsConfigured.newConfigured().withFake(true).config();
    final StoreEngineOptions storeOpts = // 
    StoreEngineOptionsConfigured.newConfigured().withStorageType(// 
    this.storageType).withRocksDBOptions(// 
    RocksDBOptionsConfigured.newConfigured().withDbPath(DB_PATH).config()).withRaftDataPath(// 
    RAFT_DATA_PATH).withServerAddress(// 
    peerId.getEndpoint()).config();
    final RheaKVStoreOptions opts = // 
    RheaKVStoreOptionsConfigured.newConfigured().withClusterName(// 
    "chaos_test").withInitialServerList(initialServerList).withStoreEngineOptions(// 
    storeOpts).withPlacementDriverOptions(// 
    pdOpts).config();
    BatchingOptions batchingOptions = opts.getBatchingOptions();
    if (batchingOptions == null) {
        batchingOptions = new BatchingOptions();
    }
    batchingOptions.setAllowBatching(this.allowBatching);
    opts.setBatchingOptions(batchingOptions);
    final RheaKVStore store = new DefaultRheaKVStore();
    if (!store.init(opts)) {
        throw new IllegalStateException("fail to init store with options: " + opts);
    }
    final RheaKVStore leader = getLeaderStore();
    final PlacementDriverClient pdClient = leader.getPlacementDriverClient();
    if (!pdClient.addReplica(Constants.DEFAULT_REGION_ID, JRaftHelper.toPeer(peerId), true)) {
        throw new RuntimeException("fail to add peer: " + peerId);
    }
    this.stores.add(store);
    awaitLeader();
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) BatchingOptions(com.alipay.sofa.jraft.rhea.options.BatchingOptions) PlacementDriverOptions(com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions) Configuration(com.alipay.sofa.jraft.conf.Configuration) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) StoreEngineOptions(com.alipay.sofa.jraft.rhea.options.StoreEngineOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)

Example 2 with DefaultRheaKVStore

use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.

the class ChaosTestCluster method start.

public synchronized void start() {
    deleteFiles();
    final Configuration conf = new Configuration(this.peerIds);
    final String initialServerList = conf.toString();
    for (final PeerId p : conf.listPeers()) {
        final PlacementDriverOptions pdOpts = // use a fake pd
        PlacementDriverOptionsConfigured.newConfigured().withFake(true).config();
        final StoreEngineOptions storeOpts = // 
        StoreEngineOptionsConfigured.newConfigured().withStorageType(// 
        this.storageType).withRocksDBOptions(// 
        RocksDBOptionsConfigured.newConfigured().withDbPath(DB_PATH).config()).withRaftDataPath(// 
        RAFT_DATA_PATH).withServerAddress(// 
        p.getEndpoint()).withLeastKeysOnSplit(// 
        10).config();
        final RheaKVStoreOptions opts = // 
        RheaKVStoreOptionsConfigured.newConfigured().withClusterName(// 
        CLUSTER_NAME).withInitialServerList(initialServerList).withOnlyLeaderRead(// 
        this.onlyLeaderRead).withStoreEngineOptions(// 
        storeOpts).withPlacementDriverOptions(// 
        pdOpts).withFailoverRetries(// 
        30).withFutureTimeoutMillis(// 
        TimeUnit.SECONDS.toMillis(60)).config();
        BatchingOptions batchingOptions = opts.getBatchingOptions();
        if (batchingOptions == null) {
            batchingOptions = new BatchingOptions();
        }
        batchingOptions.setAllowBatching(this.allowBatching);
        opts.setBatchingOptions(batchingOptions);
        final RheaKVStore store = new DefaultRheaKVStore();
        if (!store.init(opts)) {
            throw new IllegalStateException("fail to init store with options: " + opts);
        }
        this.stores.add(store);
    }
    awaitLeader();
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) BatchingOptions(com.alipay.sofa.jraft.rhea.options.BatchingOptions) PlacementDriverOptions(com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions) Configuration(com.alipay.sofa.jraft.conf.Configuration) StoreEngineOptions(com.alipay.sofa.jraft.rhea.options.StoreEngineOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) PeerId(com.alipay.sofa.jraft.entity.PeerId)

Example 3 with DefaultRheaKVStore

use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.

the class RheaKVTestCluster method start.

protected void start(final StorageType storageType, final boolean deleteFiles) throws Exception {
    if (deleteFiles) {
        deleteFiles();
    }
    for (final String c : CONF) {
        final RheaKVStoreOptions opts = readOpts(c);
        opts.getStoreEngineOptions().setStorageType(storageType);
        final RheaKVStore rheaKVStore = new DefaultRheaKVStore();
        if (rheaKVStore.init(opts)) {
            stores.add(rheaKVStore);
        } else {
            throw new RuntimeException("Fail to init rhea kv store witch conf: " + c);
        }
    }
    for (final Long id : REGION_IDS) {
        getLeaderStore(id);
    }
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)

Example 4 with DefaultRheaKVStore

use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.

the class RheaBenchmarkCluster method start.

protected void start() throws IOException, InterruptedException {
    SystemPropertyUtil.setProperty(Configs.NETTY_BUFFER_LOW_WATERMARK, Integer.toString(256 * 1024));
    SystemPropertyUtil.setProperty(Configs.NETTY_BUFFER_HIGH_WATERMARK, Integer.toString(512 * 1024));
    File file = new File("benchmark_rhea_db");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("benchmark_rhea_db");
    if (file.mkdir()) {
        this.tempDbPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempDbPath);
    }
    file = new File("benchmark_rhea_raft");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("benchmark_rhea_raft");
    if (file.mkdir()) {
        this.tempRaftPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempRaftPath);
    }
    for (String c : CONF) {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final RheaKVStoreOptions opts = mapper.readValue(new File(c), RheaKVStoreOptions.class);
        RheaKVStore rheaKVStore = new DefaultRheaKVStore();
        if (rheaKVStore.init(opts)) {
            stores.add(rheaKVStore);
        } else {
            throw new RuntimeException("Fail to init rhea kv store witch conf: " + c);
        }
    }
    PlacementDriverClient pdClient = stores.get(0).getPlacementDriverClient();
    Endpoint leader1 = pdClient.getLeader(1, true, 10000);
    System.out.println("The region 1 leader is: " + leader1);
// Endpoint leader2 = pdClient.getLeader(2, true, 10000);
// System.out.println("The region 2 leader is: " + leader2);
// Endpoint leader3 = pdClient.getLeader(3, true, 10000);
// System.out.println("The region 3 leader is: " + leader3);
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) Endpoint(com.alipay.sofa.jraft.util.Endpoint) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) File(java.io.File) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with DefaultRheaKVStore

use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore in project sofa-jraft by sofastack.

the class BenchmarkClient method main.

public static void main(final String[] args) {
    if (args.length < 7) {
        LOG.error("Args: [initialServerList], [configPath], [threads], [writeRatio], [readRatio], [valueSize] are needed.");
        System.exit(-1);
    }
    final String initialServerList = args[1];
    final String configPath = args[2];
    final int threads = Integer.parseInt(args[3]);
    final int writeRatio = Integer.parseInt(args[4]);
    final int readRatio = Integer.parseInt(args[5]);
    final int valueSize = Integer.parseInt(args[6]);
    final RheaKVStoreOptions opts = Yaml.readConfig(configPath);
    opts.setInitialServerList(initialServerList);
    final RheaKVStore rheaKVStore = new DefaultRheaKVStore();
    if (!rheaKVStore.init(opts)) {
        LOG.error("Fail to init [RheaKVStore]");
        System.exit(-1);
    }
    final List<RegionRouteTableOptions> regionRouteTableOptionsList = opts.getPlacementDriverOptions().getRegionRouteTableOptionsList();
    rebalance(rheaKVStore, initialServerList, regionRouteTableOptionsList);
    rheaKVStore.bPut("benchmark", BytesUtil.writeUtf8("benchmark start at: " + new Date()));
    LOG.info(BytesUtil.readUtf8(rheaKVStore.bGet("benchmark")));
    // 
    ConsoleReporter.forRegistry(KVMetrics.metricRegistry()).build().start(30, TimeUnit.SECONDS);
    LOG.info("Start benchmark...");
    startBenchmark(rheaKVStore, threads, writeRatio, readRatio, valueSize, regionRouteTableOptionsList);
}
Also used : RegionRouteTableOptions(com.alipay.sofa.jraft.rhea.options.RegionRouteTableOptions) RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) Endpoint(com.alipay.sofa.jraft.util.Endpoint) Date(java.util.Date)

Aggregations

DefaultRheaKVStore (com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)8 RheaKVStoreOptions (com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions)7 RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)6 PlacementDriverClient (com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient)3 Endpoint (com.alipay.sofa.jraft.util.Endpoint)3 Configuration (com.alipay.sofa.jraft.conf.Configuration)2 BatchingOptions (com.alipay.sofa.jraft.rhea.options.BatchingOptions)2 PlacementDriverOptions (com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions)2 StoreEngineOptions (com.alipay.sofa.jraft.rhea.options.StoreEngineOptions)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)2 File (java.io.File)2 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 RegionEngineOptions (com.alipay.sofa.jraft.rhea.options.RegionEngineOptions)1 RegionRouteTableOptions (com.alipay.sofa.jraft.rhea.options.RegionRouteTableOptions)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1