Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hdds.conf;

import org.apache.ratis.conf.RaftProperties;
import org.apache.ratis.grpc.GrpcConfigKeys;
import org.apache.ratis.server.RaftServerConfigKeys;
import org.apache.ratis.util.Preconditions;
import org.apache.ratis.util.SizeInBytes;

/**
* Utilities for Ratis configurations.
*/
public class RatisConfUtils {
/** For {@link GrpcConfigKeys}. */
public static class Grpc {
/** For setting {@link GrpcConfigKeys#setMessageSizeMax(RaftProperties, SizeInBytes)}. */
public static void setMessageSizeMax(RaftProperties properties, int max) {
Preconditions.assertTrue(max > 0, () -> "max = " + max + " <= 0");

final long logAppenderBufferByteLimit = RaftServerConfigKeys.Log.Appender.bufferByteLimit(properties).getSize();
Preconditions.assertTrue(max >= logAppenderBufferByteLimit,
() -> "max = " + max + " < logAppenderBufferByteLimit = " + logAppenderBufferByteLimit);

// Need an 1MB gap; see RATIS-2135
GrpcConfigKeys.setMessageSizeMax(properties, SizeInBytes.valueOf(max + SizeInBytes.ONE_MB.getSize()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.hadoop.hdds.conf;

import org.apache.ratis.conf.RaftProperties;
import org.apache.ratis.grpc.GrpcConfigKeys;
import org.apache.ratis.server.RaftServerConfigKeys;
import org.apache.ratis.util.SizeInBytes;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Test {@link RatisConfUtils}.
*/
public class TestRatisConfUtils {
private static final Logger LOG = LoggerFactory.getLogger(TestRatisConfUtils.class);

@Test
void testGrpcSetMessageSizeMax() {
final RaftProperties properties = new RaftProperties();

final int logAppenderBufferByteLimit = 1000;

// setMessageSizeMax without setBufferByteLimit
Assertions.assertThrows(IllegalStateException.class,
() -> RatisConfUtils.Grpc.setMessageSizeMax(properties, logAppenderBufferByteLimit));

RaftServerConfigKeys.Log.Appender.setBufferByteLimit(properties, SizeInBytes.valueOf(logAppenderBufferByteLimit));

// setMessageSizeMax with a value smaller than logAppenderBufferByteLimit
Assertions.assertThrows(IllegalStateException.class,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this API does not throw exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I need to update the test.

() -> RatisConfUtils.Grpc.setMessageSizeMax(properties, logAppenderBufferByteLimit - 1));

// setMessageSizeMax with the correct logAppenderBufferByteLimit
RatisConfUtils.Grpc.setMessageSizeMax(properties, logAppenderBufferByteLimit);

final SizeInBytes max = GrpcConfigKeys.messageSizeMax(properties, LOG::info);
Assertions.assertEquals(SizeInBytes.ONE_MB.getSize(), max.getSize() - logAppenderBufferByteLimit);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.DatanodeRatisServerConfig;
import org.apache.hadoop.hdds.conf.RatisConfUtils;
import org.apache.hadoop.hdds.conf.StorageUnit;
import org.apache.hadoop.hdds.HddsConfigKeys;
import org.apache.hadoop.hdds.protocol.DatanodeDetails;
Expand Down Expand Up @@ -279,11 +280,14 @@ public RaftProperties newRaftProperties() {
final RpcType rpc = setRpcType(properties);

// set raft segment size
setRaftSegmentAndWriteBufferSize(properties);
final int logAppenderBufferByteLimit = setRaftSegmentAndWriteBufferSize(properties);

// set grpc message size max
final int max = Math.max(OzoneConsts.OZONE_SCM_CHUNK_MAX_SIZE, logAppenderBufferByteLimit);
RatisConfUtils.Grpc.setMessageSizeMax(properties, max);

// set raft segment pre-allocated size
final long raftSegmentPreallocatedSize =
setRaftSegmentPreallocatedSize(properties);
setRaftSegmentPreallocatedSize(properties);

// setup ratis stream if datastream is enabled
if (streamEnable) {
Expand Down Expand Up @@ -314,11 +318,6 @@ public RaftProperties newRaftProperties() {

RaftServerConfigKeys.setStorageDir(properties, storageDirs);

// For grpc set the maximum message size
GrpcConfigKeys.setMessageSizeMax(properties,
SizeInBytes.valueOf(OzoneConsts.OZONE_SCM_CHUNK_MAX_SIZE
+ raftSegmentPreallocatedSize));

// Set the ratis port number
if (rpc == SupportedRpcType.GRPC) {
GrpcConfigKeys.Admin.setPort(properties, adminPort);
Expand Down Expand Up @@ -407,17 +406,16 @@ private void setTimeoutForRetryCache(RaftProperties properties) {
.setExpiryTime(properties, retryCacheTimeout);
}

private long setRaftSegmentPreallocatedSize(RaftProperties properties) {
private void setRaftSegmentPreallocatedSize(RaftProperties properties) {
final long raftSegmentPreallocatedSize = (long) conf.getStorageSize(
OzoneConfigKeys.HDDS_CONTAINER_RATIS_SEGMENT_PREALLOCATED_SIZE_KEY,
OzoneConfigKeys.HDDS_CONTAINER_RATIS_SEGMENT_PREALLOCATED_SIZE_DEFAULT,
StorageUnit.BYTES);
RaftServerConfigKeys.Log.setPreallocatedSize(properties,
SizeInBytes.valueOf(raftSegmentPreallocatedSize));
return raftSegmentPreallocatedSize;
}

private void setRaftSegmentAndWriteBufferSize(RaftProperties properties) {
private int setRaftSegmentAndWriteBufferSize(RaftProperties properties) {
final int logAppenderQueueNumElements = conf.getInt(
HDDS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS,
HDDS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS_DEFAULT);
Expand Down Expand Up @@ -446,6 +444,7 @@ private void setRaftSegmentAndWriteBufferSize(RaftProperties properties) {
SizeInBytes.valueOf(raftSegmentSize));
RaftServerConfigKeys.Log.setWriteBufferSize(properties,
SizeInBytes.valueOf(raftSegmentBufferSize));
return logAppenderQueueByteLimit;
}

private void setStateMachineDataConfigurations(RaftProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.google.common.base.Preconditions;
import com.google.protobuf.ServiceException;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.RatisConfUtils;
import org.apache.hadoop.hdds.conf.StorageUnit;
import org.apache.hadoop.hdds.ratis.RatisHelper;
import org.apache.hadoop.hdds.ratis.ServerNotLeaderException;
Expand Down Expand Up @@ -69,8 +70,9 @@ public static RaftProperties newRaftProperties(
// TODO: Check the default values.
final RaftProperties properties = new RaftProperties();
setRaftStorageDir(properties, conf);
setRaftRpcProperties(properties, conf);
setRaftLogProperties(properties, conf);

final int logAppenderBufferByteLimit = setRaftLogProperties(properties, conf);
setRaftRpcProperties(properties, conf, logAppenderBufferByteLimit);
setRaftRetryCacheProperties(properties, conf);
setRaftSnapshotProperties(properties, conf);
setRaftLeadElectionProperties(properties, conf);
Expand Down Expand Up @@ -100,15 +102,14 @@ public static void setRaftStorageDir(final RaftProperties properties,
* @param ozoneConf ConfigurationSource
*/
private static void setRaftRpcProperties(final RaftProperties properties,
ConfigurationSource ozoneConf) {
ConfigurationSource ozoneConf, int logAppenderBufferByteLimit) {
RatisHelper.setRpcType(properties,
RpcType.valueOf(ozoneConf.get(ScmConfigKeys.OZONE_SCM_HA_RATIS_RPC_TYPE,
ScmConfigKeys.OZONE_SCM_HA_RATIS_RPC_TYPE_DEFAULT)));
GrpcConfigKeys.Server.setPort(properties, ozoneConf
.getInt(ScmConfigKeys.OZONE_SCM_RATIS_PORT_KEY,
ScmConfigKeys.OZONE_SCM_RATIS_PORT_DEFAULT));
GrpcConfigKeys.setMessageSizeMax(properties,
SizeInBytes.valueOf("32m"));
RatisConfUtils.Grpc.setMessageSizeMax(properties, logAppenderBufferByteLimit);
long ratisRequestTimeout = ozoneConf.getTimeDuration(
ScmConfigKeys.OZONE_SCM_HA_RATIS_REQUEST_TIMEOUT,
ScmConfigKeys.OZONE_SCM_HA_RATIS_REQUEST_TIMEOUT_DEFAULT,
Expand Down Expand Up @@ -161,7 +162,7 @@ private static void setRaftLeadElectionProperties(
* @param properties RaftProperties instance which will be updated
* @param ozoneConf ConfigurationSource
*/
private static void setRaftLogProperties(final RaftProperties properties,
private static int setRaftLogProperties(final RaftProperties properties,
final ConfigurationSource ozoneConf) {
Log.setSegmentSizeMax(properties, SizeInBytes.valueOf((long)
ozoneConf.getStorageSize(
Expand Down Expand Up @@ -195,6 +196,7 @@ private static void setRaftLogProperties(final RaftProperties properties,
ozoneConf.getInt(ScmConfigKeys.OZONE_SCM_HA_RAFT_LOG_PURGE_GAP,
ScmConfigKeys.OZONE_SCM_HA_RAFT_LOG_PURGE_GAP_DEFAULT));
Log.setSegmentCacheNumMax(properties, 2);
return logAppenderQueueByteLimit;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

import org.apache.hadoop.hdds.HddsUtils;
import org.apache.hadoop.hdds.conf.ConfigurationSource;
import org.apache.hadoop.hdds.conf.RatisConfUtils;
import org.apache.hadoop.hdds.conf.StorageUnit;
import org.apache.hadoop.hdds.ratis.RatisHelper;
import org.apache.hadoop.hdds.security.SecurityConfig;
Expand Down Expand Up @@ -624,17 +625,16 @@ public static RaftProperties newRaftProperties(ConfigurationSource conf,
// Set Ratis storage directory
RaftServerConfigKeys.setStorageDir(properties, Collections.singletonList(new File(ratisStorageDir)));

final int logAppenderQueueByteLimit = (int) conf.getStorageSize(
final int logAppenderBufferByteLimit = (int) conf.getStorageSize(
OMConfigKeys.OZONE_OM_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT,
OMConfigKeys.OZONE_OM_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT_DEFAULT, StorageUnit.BYTES);
setRaftLogProperties(properties, logAppenderBufferByteLimit, conf);

// For grpc config
setGrpcConfig(properties, logAppenderQueueByteLimit);
RatisConfUtils.Grpc.setMessageSizeMax(properties, logAppenderBufferByteLimit);

setRaftLeaderElectionProperties(properties, conf);

setRaftLogProperties(properties, logAppenderQueueByteLimit, conf);

setRaftRpcProperties(properties, conf);

setRaftRetryCacheProperties(properties, conf);
Expand Down Expand Up @@ -693,12 +693,6 @@ private static void setRaftLogProperties(RaftProperties properties,
RaftServerConfigKeys.Log.setSegmentCacheNumMax(properties, 2);
}

private static void setGrpcConfig(RaftProperties properties, int logAppenderQueueByteLimit) {
// For grpc set the maximum message size
// TODO: calculate the optimal max message size
GrpcConfigKeys.setMessageSizeMax(properties, SizeInBytes.valueOf(logAppenderQueueByteLimit));
}

private static void setRaftRpcProperties(RaftProperties properties, ConfigurationSource conf) {
// Set the server request timeout
TimeUnit serverRequestTimeoutUnit = OMConfigKeys.OZONE_OM_RATIS_SERVER_REQUEST_TIMEOUT_DEFAULT.getUnit();
Expand Down