Skip to content
Open
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
Expand Up @@ -25,6 +25,11 @@
*/
public final class IoTConsensusMessages {


public static final String EXCEPTION_INVALID_IOTCONSENSUS_COMPRESSED_LOG_ARG_EXPECTED_ARG_ACTUAL_ARG_4986175E = "Invalid IoTConsensus compressed log (%s, expected %d, actual %d)";

public static final String EXCEPTION_UNSUPPORTED_IOTCONSENSUS_LOG_COMPRESSION_TYPE_ARG_4008DA9A = "Unsupported IoTConsensus log compression type: %s";

private IoTConsensusMessages() {}

// ===================== IoTConsensus lifecycle =====================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@
*/
public final class IoTConsensusMessages {


public static final String EXCEPTION_INVALID_IOTCONSENSUS_COMPRESSED_LOG_ARG_EXPECTED_ARG_ACTUAL_ARG_4986175E = "无效的 IoTConsensus 压缩日志(%s,预期 %d,实际 %d)";

public static final String EXCEPTION_UNSUPPORTED_IOTCONSENSUS_LOG_COMPRESSION_TYPE_ARG_4008DA9A = "不支持的 IoTConsensus 日志压缩类型:%s";

private IoTConsensusMessages() {}

// ===================== IoTConsensus 生命周期 =====================
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import org.apache.iotdb.commons.client.property.ClientPoolProperty.DefaultProperty;
import org.apache.iotdb.commons.memory.AtomicLongMemoryBlock;
import org.apache.iotdb.commons.memory.IMemoryBlock;
import org.apache.iotdb.consensus.i18n.IoTConsensusMessages;

import org.apache.tsfile.file.metadata.enums.CompressionType;

import java.util.Optional;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -310,6 +313,7 @@ public static class Replication {

private final int maxLogEntriesNumPerBatch;
private final int maxSizePerBatch;
private final CompressionType logCompressionType;
private final int maxPendingBatchesNum;

private final int maxQueueLength;
Expand All @@ -330,6 +334,7 @@ public static class Replication {
private Replication(
int maxLogEntriesNumPerBatch,
int maxSizePerBatch,
CompressionType logCompressionType,
int maxPendingBatchesNum,
int maxQueueLength,
long maxWaitingTimeForWaitBatchInMs,
Expand All @@ -347,6 +352,7 @@ private Replication(
long snapshotTransmissionProgressLogIntervalMs) {
this.maxLogEntriesNumPerBatch = maxLogEntriesNumPerBatch;
this.maxSizePerBatch = maxSizePerBatch;
this.logCompressionType = logCompressionType;
this.maxPendingBatchesNum = maxPendingBatchesNum;
this.maxQueueLength = maxQueueLength;
this.maxWaitingTimeForWaitBatchInMs = maxWaitingTimeForWaitBatchInMs;
Expand All @@ -372,6 +378,10 @@ public int getMaxSizePerBatch() {
return maxSizePerBatch;
}

public CompressionType getLogCompressionType() {
return logCompressionType;
}

public int getMaxPendingBatchesNum() {
return maxPendingBatchesNum;
}
Expand Down Expand Up @@ -440,6 +450,7 @@ public static class Builder {

private int maxLogEntriesNumPerBatch = 1024;
private int maxSizePerBatch = 16 * 1024 * 1024;
private CompressionType logCompressionType = CompressionType.UNCOMPRESSED;
private int maxPendingBatchesNum = 5;
private int maxQueueLength = 4096;
private long maxWaitingTimeForWaitBatchInMs = 10 * 1000L;
Expand Down Expand Up @@ -473,6 +484,24 @@ public Builder setMaxSizePerBatch(int maxSizePerBatch) {
return this;
}

public Builder setLogCompressionType(CompressionType type) {
switch (type) {
case UNCOMPRESSED:
case LZ4:
case SNAPPY:
case ZSTD:
break;
default:
throw new IllegalArgumentException(
String.format(
IoTConsensusMessages
.EXCEPTION_UNSUPPORTED_IOTCONSENSUS_LOG_COMPRESSION_TYPE_ARG_4008DA9A,
type));
}
this.logCompressionType = type;
return this;
}

public Replication.Builder setMaxPendingBatchesNum(int maxPendingBatchesNum) {
this.maxPendingBatchesNum = maxPendingBatchesNum;
return this;
Expand Down Expand Up @@ -557,6 +586,7 @@ public Replication build() {
return new Replication(
maxLogEntriesNumPerBatch,
maxSizePerBatch,
logCompressionType,
maxPendingBatchesNum,
maxQueueLength,
maxWaitingTimeForWaitBatchInMs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class IoTConsensusServerMetrics implements IMetricSet {
private Timer offerRequestToQueueTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
private Timer consensusWriteTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
private static final String IOT_RECEIVE_LOG = Metric.IOT_RECEIVE_LOG.toString();
private Timer decompressTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
private Timer deserializeTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
private Timer sortTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
private Timer applyTimer = DoNothingMetricManager.DO_NOTHING_TIMER;
Expand All @@ -50,6 +51,10 @@ public IoTConsensusServerMetrics(IoTConsensusServerImpl impl) {

private static final String IMPL = "ioTConsensusServerImpl";

public void recordDecompressCost(long nanos) {
decompressTimer.updateNanos(nanos);
}

public void recordDeserializeCost(long costTimeInNanos) {
deserializeTimer.updateNanos(costTimeInNanos);
}
Expand Down Expand Up @@ -190,6 +195,14 @@ private void bindStageTimer(AbstractMetricService metricService) {

private void bindSyncLogTimer(AbstractMetricService metricService) {
// bind sync log timers
decompressTimer =
metricService.getOrCreateTimer(
IOT_RECEIVE_LOG,
MetricLevel.IMPORTANT,
Tag.STAGE.toString(),
"decompress",
Tag.REGION.toString(),
impl.getConsensusGroupId());
deserializeTimer =
metricService.getOrCreateTimer(
IOT_RECEIVE_LOG,
Expand Down Expand Up @@ -319,6 +332,13 @@ private void unbindStageTimer(AbstractMetricService metricService) {

private void unbindSyncLogTimer(AbstractMetricService metricService) {
// unbind sync log timers
metricService.remove(
MetricType.TIMER,
IOT_RECEIVE_LOG,
Tag.STAGE.toString(),
"decompress",
Tag.REGION.toString(),
impl.getConsensusGroupId());
metricService.remove(
MetricType.TIMER,
IOT_RECEIVE_LOG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
Expand All @@ -53,6 +54,7 @@ public class DispatchLogHandler implements AsyncMethodCallback<TSyncLogEntriesRe
private final LogDispatcherThreadMetrics logDispatcherThreadMetrics;
private int retryCount;
private long retryInterval;
private volatile boolean hasCompressedAttempt;

public DispatchLogHandler(
LogDispatcherThread thread,
Expand All @@ -65,8 +67,17 @@ public DispatchLogHandler(
this.retryInterval = thread.getConfig().getReplication().getBasicRetryWaitTimeMs();
}

public void markCompressedAttempt() {
hasCompressedAttempt = true;
}

@Override
public void onComplete(TSyncLogEntriesRes response) {
if (response.isSetLogCompressionError()) {
// Decoding failed before application, regardless of the ordinary status retry classification.
onError(new IOException(response.getLogCompressionError().getMessage()));
return;
}
recordTransferAttempt(response);
if (response.getStatuses().stream()
.anyMatch(status -> RetryUtils.needRetryForWrite(status.getCode()))) {
Expand Down Expand Up @@ -138,7 +149,7 @@ public void onError(Exception exception) {
actualCause.toString());
}
// skip TApplicationException caused by follower
if (actualCause instanceof TApplicationException) {
if (actualCause instanceof TApplicationException && !hasCompressedAttempt) {
completeBatch(batch);
LOGGER.warn(IoTConsensusMessages.SKIP_RETRY_TAPPLICATION_EXCEPTION, batch);
logDispatcherThreadMetrics.recordSyncLogTimePerRequest(System.nanoTime() - createTime);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ public void free(IndexedConsensusRequest request) {
}
}

/** Non-blocking reservation for the additional arrays held by an encoded RPC attempt. */
public boolean reserveLogCompression(long size) {
return reserve(size, false);
}

public void freeLogCompression(long size) {
free(size, false);
}

public void free(Batch batch) {
free(batch.getMemorySize(), false);
if (logger.isDebugEnabled()) {
Expand Down
Loading
Loading