Search in sources :

Example 26 with RaftProperties

use of org.apache.ratis.conf.RaftProperties 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();
}
Also used : Parameters(org.apache.ratis.conf.Parameters) RaftProperties(org.apache.ratis.conf.RaftProperties) RetryPolicy(org.apache.ratis.retry.RetryPolicy)

Example 27 with RaftProperties

use of org.apache.ratis.conf.RaftProperties 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());
}
Also used : Parameters(org.apache.ratis.conf.Parameters) RaftProperties(org.apache.ratis.conf.RaftProperties) TimeDuration(org.apache.ratis.util.TimeDuration)

Example 28 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class TestRestartRaftPeer method data.

@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
    RaftProperties prop = new RaftProperties();
    prop.setClass(MiniRaftCluster.STATEMACHINE_CLASS_KEY, SimpleStateMachine4Testing.class, StateMachine.class);
    RaftServerConfigKeys.Log.setSegmentSizeMax(prop, SizeInBytes.valueOf("8KB"));
    return ParameterizedBaseTest.getMiniRaftClusters(prop, 3);
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties)

Example 29 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class TestRaftServerWithGrpc method testServerRestartOnException.

@Test
public void testServerRestartOnException() throws Exception {
    RaftProperties properties = new RaftProperties();
    final MiniRaftClusterWithGRpc cluster = MiniRaftClusterWithGRpc.FACTORY.newCluster(1, properties);
    cluster.start();
    RaftPeerId leaderId = RaftTestUtil.waitForLeader(cluster).getId();
    GrpcConfigKeys.Server.setPort(properties, cluster.getLeader().getServerRpc().getInetSocketAddress().getPort());
    // Create a raft server proxy with server rpc bound to a different address
    // compared to leader. This helps in locking the raft storage directory to
    // be used by next raft server proxy instance.
    RaftServerTestUtil.getRaftServerProxy(leaderId, cluster.getLeader().getStateMachine(), cluster.getGroup(), new RaftProperties(), null);
    // Close the server rpc for leader so that new raft server can be bound to it.
    cluster.getLeader().getServerRpc().close();
    try {
        // Create a raft server proxy with server rpc bound to same address as
        // the leader. This step would fail as the raft storage has been locked by
        // the raft server proxy created earlier. Raft server proxy should close
        // the rpc server on failure.
        RaftServerTestUtil.getRaftServerProxy(leaderId, cluster.getLeader().getStateMachine(), cluster.getGroup(), properties, null);
    } catch (Exception e) {
    }
    // Try to start a raft server rpc at the leader address.
    cluster.getServer(leaderId).getFactory().newRaftServerRpc(cluster.getServer(leaderId));
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) RaftPeerId(org.apache.ratis.protocol.RaftPeerId) Test(org.junit.Test)

Example 30 with RaftProperties

use of org.apache.ratis.conf.RaftProperties in project incubator-ratis by apache.

the class TestRaftLogSegment method setup.

@Before
public void setup() throws Exception {
    RaftProperties properties = new RaftProperties();
    storageDir = getTestDir();
    RaftServerConfigKeys.setStorageDir(properties, storageDir);
    this.segmentMaxSize = RaftServerConfigKeys.Log.segmentSizeMax(properties).getSize();
    this.preallocatedSize = RaftServerConfigKeys.Log.preallocatedSize(properties).getSize();
    this.bufferSize = RaftServerConfigKeys.Log.writeBufferSize(properties).getSizeInt();
}
Also used : RaftProperties(org.apache.ratis.conf.RaftProperties) Before(org.junit.Before)

Aggregations

RaftProperties (org.apache.ratis.conf.RaftProperties)54 Test (org.junit.Test)22 BaseTest (org.apache.ratis.BaseTest)14 Before (org.junit.Before)12 RaftPeerId (org.apache.ratis.protocol.RaftPeerId)9 RaftServer (org.apache.ratis.server.RaftServer)8 File (java.io.File)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 RaftClient (org.apache.ratis.client.RaftClient)7 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Parameters (org.apache.ratis.conf.Parameters)4 LogEntryProto (org.apache.ratis.proto.RaftProtos.LogEntryProto)4 RaftGroupId (org.apache.ratis.protocol.RaftGroupId)4 RaftGroupMemberId (org.apache.ratis.protocol.RaftGroupMemberId)4 RaftGroup (org.apache.ratis.protocol.RaftGroup)3 StateMachine (org.apache.ratis.statemachine.StateMachine)3 TimeDuration (org.apache.ratis.util.TimeDuration)3 List (java.util.List)2 UUID (java.util.UUID)2