Skip to content

Commit

Permalink
HDDS-9818. Ensure valid Raft log write buffer size
Browse files Browse the repository at this point in the history
  • Loading branch information
adoroszlai committed Dec 1, 2023
1 parent 40a8e67 commit ded0cf3
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public final class ScmConfigKeys {
"dfs.container.ratis.segment.size";
public static final String DFS_CONTAINER_RATIS_SEGMENT_SIZE_DEFAULT =
"64MB";
public static final String DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_KEY =
"dfs.container.ratis.segment.buffer.size";
public static final String DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_DEFAULT =
"2MB";
public static final String DFS_CONTAINER_RATIS_SEGMENT_PREALLOCATED_SIZE_KEY =
"dfs.container.ratis.segment.preallocated.size";
public static final String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,6 @@ public final class OzoneConfigKeys {
= ScmConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_SIZE_KEY;
public static final String DFS_CONTAINER_RATIS_SEGMENT_SIZE_DEFAULT
= ScmConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_SIZE_DEFAULT;
public static final String DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_KEY
= ScmConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_KEY;
public static final String DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_DEFAULT
= ScmConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_DEFAULT;
public static final String DFS_CONTAINER_RATIS_SEGMENT_PREALLOCATED_SIZE_KEY
= ScmConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_PREALLOCATED_SIZE_KEY;
public static final String
Expand Down
8 changes: 0 additions & 8 deletions hadoop-hdds/common/src/main/resources/ozone-default.xml
Original file line number Diff line number Diff line change
Expand Up @@ -320,14 +320,6 @@
by Apache Ratis on datanodes. (64 MB by default)
</description>
</property>
<property>
<name>dfs.container.ratis.segment.buffer.size</name>
<value>2MB</value>
<tag>OZONE, RATIS, PERFORMANCE</tag>
<description>The size of the raft segment buffer used
by Apache Ratis on datanodes. (2 MB by default)
</description>
</property>
<property>
<name>dfs.container.ratis.segment.preallocated.size</name>
<value>4MB</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,20 @@
import org.apache.ratis.server.RaftServerRpc;
import org.apache.ratis.server.protocol.TermIndex;
import org.apache.ratis.server.storage.RaftStorage;
import org.apache.ratis.util.Preconditions;
import org.apache.ratis.util.SizeInBytes;
import org.apache.ratis.util.TimeDuration;
import org.apache.ratis.util.TraditionalBinaryPrefix;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.hadoop.hdds.DatanodeVersion.SEPARATE_RATIS_PORTS_AVAILABLE;
import static org.apache.hadoop.ozone.OzoneConfigKeys.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS;
import static org.apache.hadoop.ozone.OzoneConfigKeys.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_SIZE_DEFAULT;
import static org.apache.hadoop.ozone.OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_SIZE_KEY;
import static org.apache.ratis.util.Preconditions.assertTrue;

/**
* Creates a ratis server endpoint that acts as the communication layer for
Expand Down Expand Up @@ -428,40 +434,40 @@ private long setRaftSegmentPreallocatedSize(RaftProperties properties) {
OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_PREALLOCATED_SIZE_KEY,
OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_PREALLOCATED_SIZE_DEFAULT,
StorageUnit.BYTES);
int logAppenderQueueNumElements = conf.getInt(
OzoneConfigKeys.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS,
OzoneConfigKeys
.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS_DEFAULT);
final int logAppenderQueueByteLimit = (int) conf.getStorageSize(
OzoneConfigKeys.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT,
OzoneConfigKeys
.DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT_DEFAULT,
StorageUnit.BYTES);
RaftServerConfigKeys.Log.Appender
.setBufferElementLimit(properties, logAppenderQueueNumElements);
RaftServerConfigKeys.Log.Appender.setBufferByteLimit(properties,
SizeInBytes.valueOf(logAppenderQueueByteLimit));
RaftServerConfigKeys.Log.setPreallocatedSize(properties,
SizeInBytes.valueOf(raftSegmentPreallocatedSize));
return raftSegmentPreallocatedSize;
}

private void setRaftSegmentAndWriteBufferSize(RaftProperties properties) {
final int logAppenderQueueNumElements = conf.getInt(
DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS,
DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_NUM_ELEMENTS_DEFAULT);
final int logAppenderQueueByteLimit = (int) conf.getStorageSize(
DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT,
DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT_DEFAULT,
StorageUnit.BYTES);

final long raftSegmentSize = (long) conf.getStorageSize(
OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_SIZE_KEY,
OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_SIZE_DEFAULT,
DFS_CONTAINER_RATIS_SEGMENT_SIZE_KEY,
DFS_CONTAINER_RATIS_SEGMENT_SIZE_DEFAULT,
StorageUnit.BYTES);
final long raftSegmentBufferSize = logAppenderQueueByteLimit + 8;

assertTrue(raftSegmentBufferSize <= raftSegmentSize,
() -> DFS_CONTAINER_RATIS_LOG_APPENDER_QUEUE_BYTE_LIMIT + " = "
+ logAppenderQueueByteLimit
+ " must be <= (" + DFS_CONTAINER_RATIS_SEGMENT_SIZE_KEY + " - 8"
+ " = " + (raftSegmentSize - 8) + ")");

RaftServerConfigKeys.Log.Appender.setBufferElementLimit(properties,
logAppenderQueueNumElements);
RaftServerConfigKeys.Log.Appender.setBufferByteLimit(properties,
SizeInBytes.valueOf(logAppenderQueueByteLimit));
RaftServerConfigKeys.Log.setSegmentSizeMax(properties,
SizeInBytes.valueOf(raftSegmentSize));
final long raftSegmentBufferSize = (long) conf.getStorageSize(
OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_KEY,
OzoneConfigKeys.DFS_CONTAINER_RATIS_SEGMENT_BUFFER_SIZE_DEFAULT,
StorageUnit.BYTES);
RaftServerConfigKeys.Log.setWriteBufferSize(properties,
SizeInBytes.valueOf(raftSegmentBufferSize));
Preconditions.assertTrue(raftSegmentBufferSize <= raftSegmentSize,
() -> "raftSegmentBufferSize = " + raftSegmentBufferSize
+ " > raftSegmentSize = " + raftSegmentSize);
SizeInBytes.valueOf(raftSegmentBufferSize));
}

private RpcType setRpcType(RaftProperties properties) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ private static void setRaftLogProperties(final RaftProperties properties,
ScmConfigKeys.OZONE_SCM_HA_RAFT_LOG_APPENDER_QUEUE_NUM,
ScmConfigKeys.
OZONE_SCM_HA_RAFT_LOG_APPENDER_QUEUE_NUM_DEFAULT));
Log.Appender.setBufferByteLimit(properties, SizeInBytes.valueOf(
(long) ozoneConf.getStorageSize(
ScmConfigKeys.OZONE_SCM_HA_RAFT_LOG_APPENDER_QUEUE_BYTE_LIMIT,
ScmConfigKeys.
OZONE_SCM_HA_RAFT_LOG_APPENDER_QUEUE_BYTE_LIMIT_DEFAULT,
StorageUnit.BYTES)));
final int logAppenderQueueByteLimit = (int) ozoneConf.getStorageSize(
ScmConfigKeys.OZONE_SCM_HA_RAFT_LOG_APPENDER_QUEUE_BYTE_LIMIT,
ScmConfigKeys.OZONE_SCM_HA_RAFT_LOG_APPENDER_QUEUE_BYTE_LIMIT_DEFAULT,
StorageUnit.BYTES);
Log.Appender.setBufferByteLimit(properties,
SizeInBytes.valueOf(logAppenderQueueByteLimit));
Log.setWriteBufferSize(properties,
SizeInBytes.valueOf(logAppenderQueueByteLimit + 8));
Log.setPreallocatedSize(properties, SizeInBytes.valueOf(
(long) ozoneConf.getStorageSize(
ScmConfigKeys.OZONE_SCM_HA_RAFT_SEGMENT_PRE_ALLOCATED_SIZE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,8 @@ public static RaftProperties newRaftProperties(ConfigurationSource conf,
logAppenderQueueNumElements);
RaftServerConfigKeys.Log.Appender.setBufferByteLimit(properties,
SizeInBytes.valueOf(logAppenderQueueByteLimit));
RaftServerConfigKeys.Log.setWriteBufferSize(properties,
SizeInBytes.valueOf(logAppenderQueueByteLimit + 8));
RaftServerConfigKeys.Log.setPreallocatedSize(properties,
SizeInBytes.valueOf(raftSegmentPreallocatedSize));
RaftServerConfigKeys.Log.Appender.setInstallSnapshotEnabled(properties,
Expand Down

0 comments on commit ded0cf3

Please sign in to comment.