Search in sources :

Example 11 with RheaKVStoreOptions

use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.

the class Server1 method main.

public static void main(final String[] args) {
    final PlacementDriverOptions pdOpts = PlacementDriverOptionsConfigured.newConfigured().withFake(// use a fake pd
    true).config();
    final StoreEngineOptions storeOpts = // 
    StoreEngineOptionsConfigured.newConfigured().withStorageType(StorageType.RocksDB).withRocksDBOptions(RocksDBOptionsConfigured.newConfigured().withDbPath(Configs.DB_PATH).config()).withRaftDataPath(Configs.RAFT_DATA_PATH).withServerAddress(new Endpoint("127.0.0.1", 8181)).config();
    final RheaKVStoreOptions opts = // 
    RheaKVStoreOptionsConfigured.newConfigured().withClusterName(// 
    Configs.CLUSTER_NAME).withUseParallelCompress(// 
    true).withInitialServerList(Configs.ALL_NODE_ADDRESSES).withStoreEngineOptions(// 
    storeOpts).withPlacementDriverOptions(// 
    pdOpts).config();
    System.out.println(opts);
    final Node node = new Node(opts);
    node.start();
    Runtime.getRuntime().addShutdownHook(new Thread(node::stop));
    System.out.println("server1 start OK");
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) PlacementDriverOptions(com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) StoreEngineOptions(com.alipay.sofa.jraft.rhea.options.StoreEngineOptions)

Example 12 with RheaKVStoreOptions

use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.

the class Yaml method readConfig.

public static RheaKVStoreOptions readConfig(final String name) {
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    final RheaKVStoreOptions opts;
    try {
        opts = mapper.readValue(new File(name), RheaKVStoreOptions.class);
        System.out.println(opts);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return opts;
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 13 with RheaKVStoreOptions

use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.

the class Client method init.

public void init() {
    final List<RegionRouteTableOptions> regionRouteTableOptionsList = MultiRegionRouteTableOptionsConfigured.newConfigured().withInitialServerList(-1L, /* default id */
    Configs.ALL_NODE_ADDRESSES).config();
    final PlacementDriverOptions pdOpts = // 
    PlacementDriverOptionsConfigured.newConfigured().withFake(// 
    true).withRegionRouteTableOptionsList(// 
    regionRouteTableOptionsList).config();
    final RheaKVStoreOptions opts = // 
    RheaKVStoreOptionsConfigured.newConfigured().withClusterName(// 
    Configs.CLUSTER_NAME).withPlacementDriverOptions(// 
    pdOpts).config();
    System.out.println(opts);
    rheaKVStore.init(opts);
}
Also used : RegionRouteTableOptions(com.alipay.sofa.jraft.rhea.options.RegionRouteTableOptions) RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) PlacementDriverOptions(com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions)

Example 14 with RheaKVStoreOptions

use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.

the class YamlTest method parseStoreEngineOptionsTest.

@Test
public void parseStoreEngineOptionsTest() throws IOException {
    final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    final InputStream in = YamlTest.class.getResourceAsStream("/conf/rhea_test_cluster_1.yaml");
    final RheaKVStoreOptions opts = mapper.readValue(in, RheaKVStoreOptions.class);
    System.out.println(opts);
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) InputStream(java.io.InputStream) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 15 with RheaKVStoreOptions

use of com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions in project sofa-jraft by sofastack.

the class PlacementDriverServer method init.

@Override
public synchronized boolean init(final PlacementDriverServerOptions opts) {
    if (this.started) {
        LOG.info("[PlacementDriverServer] already started.");
        return true;
    }
    Requires.requireNonNull(opts, "opts");
    final RheaKVStoreOptions rheaOpts = opts.getRheaKVStoreOptions();
    Requires.requireNonNull(rheaOpts, "opts.rheaKVStoreOptions");
    this.rheaKVStore = new DefaultRheaKVStore();
    if (!this.rheaKVStore.init(rheaOpts)) {
        LOG.error("Fail to init [RheaKVStore].");
        return false;
    }
    this.placementDriverService = new DefaultPlacementDriverService(this.rheaKVStore);
    if (!this.placementDriverService.init(opts)) {
        LOG.error("Fail to init [PlacementDriverService].");
        return false;
    }
    final StoreEngine storeEngine = ((DefaultRheaKVStore) this.rheaKVStore).getStoreEngine();
    Requires.requireNonNull(storeEngine, "storeEngine");
    final List<RegionEngine> regionEngines = storeEngine.getAllRegionEngines();
    if (regionEngines.isEmpty()) {
        throw new IllegalArgumentException("Non region for [PlacementDriverServer]");
    }
    if (regionEngines.size() > 1) {
        throw new IllegalArgumentException("Only support single region for [PlacementDriverServer]");
    }
    this.regionEngine = regionEngines.get(0);
    this.rheaKVStore.addLeaderStateListener(this.regionEngine.getRegion().getId(), ((DefaultPlacementDriverService) this.placementDriverService));
    addPlacementDriverProcessor(storeEngine.getRpcServer());
    LOG.info("[PlacementDriverServer] start successfully, options: {}.", opts);
    return this.started = true;
}
Also used : RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)

Aggregations

RheaKVStoreOptions (com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions)15 DefaultRheaKVStore (com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)7 RheaKVStore (com.alipay.sofa.jraft.rhea.client.RheaKVStore)6 PlacementDriverOptions (com.alipay.sofa.jraft.rhea.options.PlacementDriverOptions)6 Endpoint (com.alipay.sofa.jraft.util.Endpoint)6 StoreEngineOptions (com.alipay.sofa.jraft.rhea.options.StoreEngineOptions)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)4 PlacementDriverClient (com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient)3 File (java.io.File)3 Configuration (com.alipay.sofa.jraft.conf.Configuration)2 BatchingOptions (com.alipay.sofa.jraft.rhea.options.BatchingOptions)2 RegionRouteTableOptions (com.alipay.sofa.jraft.rhea.options.RegionRouteTableOptions)2 InputStream (java.io.InputStream)2 Test (org.junit.Test)2 PeerId (com.alipay.sofa.jraft.entity.PeerId)1 Node (com.alipay.sofa.jraft.example.rheakv.Node)1 RegionEngineOptions (com.alipay.sofa.jraft.rhea.options.RegionEngineOptions)1 IOException (java.io.IOException)1 Date (java.util.Date)1