use of org.apache.ratis.conf.Parameters in project incubator-ratis by apache.
the class Client method run.
@Override
public void run() throws Exception {
RaftProperties raftProperties = new RaftProperties();
RaftGroup raftGroup = new RaftGroup(RaftGroupId.valueOf(ByteString.copyFromUtf8(raftGroupId)), parsePeers(peers));
RaftClient.Builder builder = RaftClient.newBuilder().setProperties(raftProperties);
builder.setRaftGroup(raftGroup);
builder.setClientRpc(new GrpcFactory(new Parameters()).newRaftClientRpc(ClientId.randomId(), raftProperties));
RaftClient client = builder.build();
operation(client);
}
use of org.apache.ratis.conf.Parameters in project alluxio by Alluxio.
the class RaftJournalSystem method createClient.
private RaftClient createClient() {
long timeoutMs = ServerConfiguration.getMs(PropertyKey.MASTER_EMBEDDED_JOURNAL_RAFT_CLIENT_REQUEST_TIMEOUT);
long retryBaseMs = ServerConfiguration.getMs(PropertyKey.MASTER_EMBEDDED_JOURNAL_RAFT_CLIENT_REQUEST_INTERVAL);
RaftProperties properties = new RaftProperties();
Parameters parameters = new Parameters();
RaftClientConfigKeys.Rpc.setRequestTimeout(properties, TimeDuration.valueOf(timeoutMs, TimeUnit.MILLISECONDS));
RetryPolicy retryPolicy = ExponentialBackoffRetry.newBuilder().setBaseSleepTime(TimeDuration.valueOf(retryBaseMs, TimeUnit.MILLISECONDS)).setMaxSleepTime(TimeDuration.valueOf(mConf.getMaxElectionTimeoutMs(), TimeUnit.MILLISECONDS)).build();
return RaftClient.newBuilder().setRaftGroup(mRaftGroup).setClientId(mClientId).setLeaderId(null).setProperties(properties).setParameters(parameters).setRetryPolicy(retryPolicy).build();
}
use of org.apache.ratis.conf.Parameters in project alluxio by Alluxio.
the class RaftJournalSystem method initServer.
private synchronized void initServer() throws IOException {
LOG.debug("Creating journal with max segment size {}", mConf.getMaxLogSize());
if (mStateMachine != null) {
mStateMachine.close();
}
mStateMachine = new JournalStateMachine(mJournals, this, mConf.getMaxConcurrencyPoolSize());
RaftProperties properties = new RaftProperties();
Parameters parameters = new Parameters();
// TODO(feng): implement a custom RpcType to integrate with Alluxio authentication service
RaftConfigKeys.Rpc.setType(properties, SupportedRpcType.GRPC);
// RPC port
GrpcConfigKeys.Server.setPort(properties, mConf.getLocalAddress().getPort());
// storage path
maybeMigrateOldJournal();
RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(RaftJournalUtils.getRaftJournalDir(mConf.getPath())));
// segment size
RaftServerConfigKeys.Log.setSegmentSizeMax(properties, SizeInBytes.valueOf(mConf.getMaxLogSize()));
// the following configurations need to be changed when the single journal entry
// is unexpectedly big.
RaftServerConfigKeys.Log.Appender.setBufferByteLimit(properties, SizeInBytes.valueOf(ServerConfiguration.global().getBytes(PropertyKey.MASTER_EMBEDDED_JOURNAL_ENTRY_SIZE_MAX)));
// this property defines the maximum allowed size of the concurrent journal flush requests.
// if the total size of the journal entries contained in the flush requests
// are bigger than the given threshold, Ratis may error out as
// `Log entry size 117146048 exceeds the max buffer limit of 104857600`
RaftServerConfigKeys.Write.setByteLimit(properties, SizeInBytes.valueOf(ServerConfiguration.global().getBytes(PropertyKey.MASTER_EMBEDDED_JOURNAL_FLUSH_SIZE_MAX)));
// this property defines the maximum allowed size of the concurrent journal write IO tasks.
// if the total size of the journal entries contained in the write IO tasks
// are bigger than the given threshold, ratis may error out as
// `SegmentedRaftLogWorker: elementNumBytes = 78215699 > byteLimit = 67108864`
RaftServerConfigKeys.Log.setQueueByteLimit(properties, (int) ServerConfiguration.global().getBytes(PropertyKey.MASTER_EMBEDDED_JOURNAL_FLUSH_SIZE_MAX));
// election timeout, heartbeat timeout is automatically 1/2 of the value
final TimeDuration leaderElectionMinTimeout = TimeDuration.valueOf(mConf.getMinElectionTimeoutMs(), TimeUnit.MILLISECONDS);
final TimeDuration leaderElectionMaxTimeout = TimeDuration.valueOf(mConf.getMaxElectionTimeoutMs(), TimeUnit.MILLISECONDS);
RaftServerConfigKeys.Rpc.setTimeoutMin(properties, leaderElectionMinTimeout);
RaftServerConfigKeys.Rpc.setTimeoutMax(properties, leaderElectionMaxTimeout);
// request timeout
RaftServerConfigKeys.Rpc.setRequestTimeout(properties, TimeDuration.valueOf(ServerConfiguration.global().getMs(PropertyKey.MASTER_EMBEDDED_JOURNAL_TRANSPORT_REQUEST_TIMEOUT_MS), TimeUnit.MILLISECONDS));
RaftServerConfigKeys.RetryCache.setExpiryTime(properties, TimeDuration.valueOf(ServerConfiguration.getMs(PropertyKey.MASTER_EMBEDDED_JOURNAL_RETRY_CACHE_EXPIRY_TIME), TimeUnit.MILLISECONDS));
// snapshot retention
RaftServerConfigKeys.Snapshot.setRetentionFileNum(properties, 3);
// snapshot interval
RaftServerConfigKeys.Snapshot.setAutoTriggerEnabled(properties, true);
long snapshotAutoTriggerThreshold = ServerConfiguration.global().getLong(PropertyKey.MASTER_JOURNAL_CHECKPOINT_PERIOD_ENTRIES);
RaftServerConfigKeys.Snapshot.setAutoTriggerThreshold(properties, snapshotAutoTriggerThreshold);
RaftServerConfigKeys.Log.Appender.setInstallSnapshotEnabled(properties, false);
/*
* Soft disable RPC level safety.
*
* Without these overrides, the leader will step down upon detecting a long running GC over
* 10sec. This is not desirable for a single master cluster. Additionally, reduced safety should
* be provided via standard leader election in clustered mode.
*/
RaftServerConfigKeys.Rpc.setSlownessTimeout(properties, TimeDuration.valueOf(Long.MAX_VALUE, TimeUnit.MILLISECONDS));
RaftServerConfigKeys.LeaderElection.setLeaderStepDownWaitTime(properties, TimeDuration.valueOf(Long.MAX_VALUE, TimeUnit.MILLISECONDS));
long messageSize = ServerConfiguration.global().getBytes(PropertyKey.MASTER_EMBEDDED_JOURNAL_TRANSPORT_MAX_INBOUND_MESSAGE_SIZE);
GrpcConfigKeys.setMessageSizeMax(properties, SizeInBytes.valueOf(messageSize));
RatisDropwizardExports.registerRatisMetricReporters(mRatisMetricsMap);
// TODO(feng): clean up embedded journal configuration
// build server
mServer = RaftServer.newBuilder().setServerId(mPeerId).setGroup(mRaftGroup).setStateMachine(mStateMachine).setProperties(properties).setParameters(parameters).build();
super.registerMetrics();
MetricsSystem.registerGaugeIfAbsent(MetricKey.CLUSTER_LEADER_INDEX.getName(), () -> getLeaderIndex());
MetricsSystem.registerGaugeIfAbsent(MetricKey.MASTER_ROLE_ID.getName(), () -> getRoleId());
MetricsSystem.registerGaugeIfAbsent(MetricKey.CLUSTER_LEADER_ID.getName(), () -> getLeaderId());
}
use of org.apache.ratis.conf.Parameters in project incubator-ratis by apache.
the class HadoopFactory method newRaftParameters.
public static Parameters newRaftParameters(Configuration conf) {
final Parameters p = new Parameters();
HadoopConfigKeys.setConf(p, conf);
return p;
}
Aggregations