Search in sources :

Example 6 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() throws IOException, InterruptedException {
    System.out.println("RheaKVTestCluster init ...");
    File file = new File("rhea_pd_db");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("rhea_pd_db");
    if (file.mkdir()) {
        this.tempDbPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempDbPath);
    }
    file = new File("rhea_pd_raft");
    if (file.exists()) {
        FileUtils.forceDelete(file);
    }
    file = new File("rhea_pd_raft");
    if (file.mkdir()) {
        this.tempRaftPath = file.getAbsolutePath();
        System.out.println("make dir: " + this.tempRaftPath);
    }
    final Set<Long> regionIds = new HashSet<>();
    for (final String c : CONF) {
        final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        final InputStream in = RheaKVTestCluster.class.getResourceAsStream(c);
        final RheaKVStoreOptions opts = mapper.readValue(in, RheaKVStoreOptions.class);
        for (final RegionEngineOptions rOpts : opts.getStoreEngineOptions().getRegionEngineOptionsList()) {
            regionIds.add(rOpts.getRegionId());
        }
        final RheaKVStore rheaKVStore = new DefaultRheaKVStore();
        if (rheaKVStore.init(opts)) {
            stores.add(rheaKVStore);
        } else {
            System.err.println("Fail to init rhea kv store witch conf: " + c);
        }
    }
    final PlacementDriverClient pdClient = stores.get(0).getPlacementDriverClient();
    for (final Long regionId : regionIds) {
        final Endpoint leader = pdClient.getLeader(regionId, true, 10000);
        System.out.println("The region " + regionId + " leader is: " + leader);
    }
}
Also used : DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStore(com.alipay.sofa.jraft.rhea.client.RheaKVStore) InputStream(java.io.InputStream) PlacementDriverClient(com.alipay.sofa.jraft.rhea.client.pd.PlacementDriverClient) RegionEngineOptions(com.alipay.sofa.jraft.rhea.options.RegionEngineOptions) DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore) RheaKVStoreOptions(com.alipay.sofa.jraft.rhea.options.RheaKVStoreOptions) Endpoint(com.alipay.sofa.jraft.util.Endpoint) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) HashSet(java.util.HashSet)

Example 7 with DefaultRheaKVStore

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

the class Node method start.

public void start() {
    this.rheaKVStore = new DefaultRheaKVStore();
    this.rheaKVStore.init(this.options);
}
Also used : DefaultRheaKVStore(com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore)

Example 8 with DefaultRheaKVStore

use of com.alipay.sofa.jraft.rhea.client.DefaultRheaKVStore 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

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