Example #1
0
  protected Shard(AbstractBuilder<?, ?> builder) {
    super(
        builder.getId().toString(),
        builder.getPeerAddresses(),
        Optional.of(builder.getDatastoreContext().getShardRaftConfig()),
        DataStoreVersions.CURRENT_VERSION);

    this.name = builder.getId().toString();
    this.datastoreContext = builder.getDatastoreContext();
    this.restoreFromSnapshot = builder.getRestoreFromSnapshot();

    setPersistence(datastoreContext.isPersistent());

    LOG.info("Shard created : {}, persistent : {}", name, datastoreContext.isPersistent());

    store = new ShardDataTree(builder.getSchemaContext(), builder.getTreeType());

    shardMBean =
        ShardMBeanFactory.getShardStatsMBean(
            name.toString(), datastoreContext.getDataStoreMXBeanType());
    shardMBean.setShard(this);

    if (isMetricsCaptureEnabled()) {
      getContext().become(new MeteringBehavior(this));
    }

    commitCoordinator =
        new ShardCommitCoordinator(
            store,
            datastoreContext.getShardCommitQueueExpiryTimeoutInMillis(),
            datastoreContext.getShardTransactionCommitQueueCapacity(),
            LOG,
            this.name);

    setTransactionCommitTimeout();

    // create a notifier actor for each cluster member
    roleChangeNotifier = createRoleChangeNotifier(name.toString());

    appendEntriesReplyTracker =
        new MessageTracker(
            AppendEntriesReply.class,
            getRaftActorContext().getConfigParams().getIsolatedCheckIntervalInMillis());

    transactionActorFactory =
        new ShardTransactionActorFactory(
            store,
            datastoreContext,
            new Dispatchers(context().system().dispatchers())
                .getDispatcherPath(Dispatchers.DispatcherType.Transaction),
            self(),
            getContext(),
            shardMBean);

    snapshotCohort = new ShardSnapshotCohort(transactionActorFactory, store, LOG, this.name);

    messageRetrySupport = new ShardTransactionMessageRetrySupport(this);
  }