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 @@ -757,6 +757,8 @@ private StorageEngineMessages() {}
"{}: {} is closed during flush, abandon flush task";
public static final String STORAGE_LOG_THE_COMPRESSION_RATIO_OF_TSFILE_IS_TOTALMEMTABLESIZE_THE_8CE66BE3 =
"The compression ratio of tsfile {} is {}, totalMemTableSize: {}, the file size: {}";
public static final String STORAGE_LOG_THE_COMPRESSION_RATIO_OF_TSFILE_IS_TOTALMEMTABLESIZE_THE_FILE_SIZE_NULL_VALUE_RATIO_46F3B1F7 =
"The compression ratio of tsfile {} is {}, totalMemTableSize: {}, the file size: {}, null value ratio: {}";
public static final String STORAGE_LOG_STORAGE_GROUP_CLOSE_AND_REMOVE_EMPTY_FILE_72D42293 =
"Storage group {} close and remove empty file {}";
public static final String STORAGE_LOG_PUT_THE_MEMTABLE_SIGNAL_OUT_OF_FLUSHINGMEMTABLES_BUT_IT_D78AF257 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,8 @@ private StorageEngineMessages() {}
"{}:{} 在 flush 期间已关闭,放弃 flush 任务";
public static final String STORAGE_LOG_THE_COMPRESSION_RATIO_OF_TSFILE_IS_TOTALMEMTABLESIZE_THE_8CE66BE3 =
"TsFile {} 的压缩率为 {},totalMemTableSize:{},文件大小:{}";
public static final String STORAGE_LOG_THE_COMPRESSION_RATIO_OF_TSFILE_IS_TOTALMEMTABLESIZE_THE_FILE_SIZE_NULL_VALUE_RATIO_46F3B1F7 =
"TsFile {} 的压缩率为 {},totalMemTableSize:{},文件大小:{},空值比例:{}";
public static final String STORAGE_LOG_STORAGE_GROUP_CLOSE_AND_REMOVE_EMPTY_FILE_72D42293 =
"Storage group {} 关闭并移除空文件 {}";
public static final String STORAGE_LOG_PUT_THE_MEMTABLE_SIGNAL_OUT_OF_FLUSHINGMEMTABLES_BUT_IT_D78AF257 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ private void unbindWALCostMetrics(AbstractMetricService metricService) {
public static final String SERIES_NUM = "series_num";
public static final String AVG_SERIES_POINT_NUM = "avg_series_points_num";
public static final String COMPRESSION_RATIO = "compression_ratio";
public static final String NULL_VALUE_RATIO = "null_value_ratio";
public static final String EFFECTIVE_RATIO_INFO = "effective_ratio_info";
public static final String OLDEST_MEM_TABLE_RAM_WHEN_CAUSE_SNAPSHOT =
"oldest_mem_table_ram_when_cause_snapshot";
Expand Down Expand Up @@ -598,7 +599,13 @@ public void removeWALNodeInfoMetrics(String walNodeId) {
}

public void createFlushingMemTableStatusMetrics(DataRegionId dataRegionId) {
Arrays.asList(MEM_TABLE_SIZE, SERIES_NUM, POINTS_NUM, COMPRESSION_RATIO, FLUSH_TSFILE_SIZE)
Arrays.asList(
MEM_TABLE_SIZE,
SERIES_NUM,
POINTS_NUM,
COMPRESSION_RATIO,
NULL_VALUE_RATIO,
FLUSH_TSFILE_SIZE)
.forEach(
name ->
MetricService.getInstance()
Expand Down Expand Up @@ -727,6 +734,7 @@ public void removeFlushingMemTableStatusMetrics(DataRegionId dataRegionId) {
POINTS_NUM,
AVG_SERIES_POINT_NUM,
COMPRESSION_RATIO,
NULL_VALUE_RATIO,
FLUSH_TSFILE_SIZE)
.forEach(
name ->
Expand Down Expand Up @@ -790,6 +798,19 @@ public void recordTsFileCompressionRatioOfFlushingMemTable(
new DataRegionId(Integer.parseInt(dataRegionId)).toString());
}

public void recordTsFileNullValueRatioOfFlushingMemTable(
String dataRegionId, double nullValueRatio) {
MetricService.getInstance()
.histogram(
(long) (nullValueRatio * 100),
Metric.FLUSHING_MEM_TABLE_STATUS.toString(),
MetricLevel.IMPORTANT,
Tag.NAME.toString(),
NULL_VALUE_RATIO,
Tag.REGION.toString(),
new DataRegionId(Integer.parseInt(dataRegionId)).toString());
}

public void recordFlushingMemTableStatus(
String storageGroup, long memSize, long seriesNum, long totalPointsNum, long avgSeriesNum) {
DataRegionId dataRegionId = getDataRegionIdFromStorageGroupStr(storageGroup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.apache.iotdb.db.utils.EncryptDBUtils;
import org.apache.iotdb.db.utils.MemUtils;
import org.apache.iotdb.db.utils.ModificationUtils;
import org.apache.iotdb.rpc.TSStatusCode;

import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.file.metadata.ChunkMetadata;
Expand Down Expand Up @@ -104,6 +105,10 @@ public abstract class AbstractMemTable implements IMemTable {

private long totalPointsNum = 0;

private long totalValueCount = 0;

private long nullValueCount = 0;

private long totalPointsNumThreshold = 0;

private long maxPlanIndex = Long.MIN_VALUE;
Expand Down Expand Up @@ -222,13 +227,16 @@ public int insert(InsertRowNode insertRowNode) {
MemUtils.getRowRecordSize(dataTypes, writableValues, insertRowNode.getColumnCategories());
write(insertRowNode.getDeviceID(), schemaList, insertRowNode.getTime(), writableValues);

int validValueCount = insertRowNode.getValidMeasurementNumber(true);
int pointsInserted =
insertRowNode.getValidMeasurementNumber(true)
validValueCount
- (IoTDBDescriptor.getInstance().getConfig().isIncludeNullValueInWriteThroughputMetric()
? 0
: nullPointsNumber);

totalPointsNum += pointsInserted;
totalValueCount += validValueCount;
nullValueCount += nullPointsNumber;
return pointsInserted;
}

Expand Down Expand Up @@ -266,30 +274,37 @@ public int insertAlignedRow(InsertRowNode insertRowNode) {
dataTypes, writableValues, insertRowNode.getColumnCategories());
writeAlignedRow(
insertRowNode.getDeviceID(), schemaList, insertRowNode.getTime(), writableValues);
int validValueCount = insertRowNode.getValidMeasurementNumber(true);
int pointsInserted =
insertRowNode.getValidMeasurementNumber(true)
validValueCount
- (IoTDBDescriptor.getInstance().getConfig().isIncludeNullValueInWriteThroughputMetric()
? 0
: nullPointsNumber);
totalPointsNum += pointsInserted;
totalValueCount += validValueCount;
nullValueCount += nullPointsNumber;
return pointsInserted;
}

@Override
public int insertTablet(InsertTabletNode insertTabletNode, int start, int end)
throws WriteProcessException {
try {
int nullPointsNumber = computeTabletNullPointsNumber(insertTabletNode, start, end, true);
int nullPointsNumber =
computeTabletNullPointsNumber(insertTabletNode, start, end, true, null);
writeTabletNode(insertTabletNode, start, end);
memSize += MemUtils.getTabletSize(insertTabletNode, start, end);
int validValueCount = insertTabletNode.getValidMeasurementNumber(true) * (end - start);
int pointsInserted =
(insertTabletNode.getValidMeasurementNumber(true) * (end - start))
validValueCount
- (IoTDBDescriptor.getInstance()
.getConfig()
.isIncludeNullValueInWriteThroughputMetric()
? 0
: nullPointsNumber);
totalPointsNum += pointsInserted;
totalValueCount += validValueCount;
nullValueCount += nullPointsNumber;
return pointsInserted;
} catch (RuntimeException e) {
throw new WriteProcessException(e);
Expand All @@ -301,26 +316,36 @@ public int insertAlignedTablet(
InsertTabletNode insertTabletNode, int start, int end, TSStatus[] results)
throws WriteProcessException {
try {
int nullPointsNumber = computeTabletNullPointsNumber(insertTabletNode, start, end, true);
int nullPointsNumber =
computeTabletNullPointsNumber(insertTabletNode, start, end, true, results);
writeAlignedTablet(insertTabletNode, start, end, results);
// TODO-Table: what is the relation between this and TsFileProcessor.checkMemCost
memSize += MemUtils.getAlignedTabletSize(insertTabletNode, start, end, results);
int validValueCount =
insertTabletNode.getValidMeasurementNumber(true)
* computeSuccessfulRowCount(results, start, end);
int pointsInserted =
(insertTabletNode.getValidMeasurementNumber(true) * (end - start))
validValueCount
- (IoTDBDescriptor.getInstance()
.getConfig()
.isIncludeNullValueInWriteThroughputMetric()
? 0
: nullPointsNumber);
totalPointsNum += pointsInserted;
totalValueCount += validValueCount;
nullValueCount += nullPointsNumber;
return pointsInserted;
} catch (RuntimeException e) {
throw new WriteProcessException(e);
}
}

private static int computeTabletNullPointsNumber(
InsertTabletNode insertTabletNode, int start, int end, boolean countFieldOnly) {
InsertTabletNode insertTabletNode,
int start,
int end,
boolean countFieldOnly,
TSStatus[] results) {
Object[] values = insertTabletNode.getBitMaps();
int nullPointsNumber = 0;
if (values != null) {
Expand All @@ -339,7 +364,7 @@ private static int computeTabletNullPointsNumber(
BitMap bitMap = i < values.length ? (BitMap) values[i] : null;
if (bitMap != null && !bitMap.isAllUnmarked()) {
for (int j = start; j < end; j++) {
if (bitMap.isMarked(j)) {
if (!isFailedRow(results, j) && bitMap.isMarked(j)) {
nullPointsNumber++;
}
}
Expand All @@ -349,6 +374,22 @@ private static int computeTabletNullPointsNumber(
return nullPointsNumber;
}

private static int computeSuccessfulRowCount(TSStatus[] results, int start, int end) {
int successfulRowCount = 0;
for (int i = start; i < end; i++) {
if (!isFailedRow(results, i)) {
successfulRowCount++;
}
}
return successfulRowCount;
}

private static boolean isFailedRow(TSStatus[] results, int index) {
return results != null
&& results[index] != null
&& results[index].getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode();
}

@Override
public void write(
IDeviceID deviceId,
Expand Down Expand Up @@ -481,6 +522,21 @@ public long getTotalPointsNum() {
return totalPointsNum;
}

@Override
public long getTotalValueCount() {
return totalValueCount;
}

@Override
public long getNullValueCount() {
return nullValueCount;
}

@Override
public double getNullValueRatio() {
return totalValueCount == 0 ? 0 : (double) nullValueCount / totalValueCount;
}

@Override
public long size() {
long sum = 0;
Expand All @@ -501,6 +557,8 @@ public void clear() {
memSize = 0;
seriesNumber = 0;
totalPointsNum = 0;
totalValueCount = 0;
nullValueCount = 0;
totalPointsNumThreshold = 0;
tvListRamCost = 0;
maxPlanIndex = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ void writeAlignedRow(

long getTotalPointsNum();

long getTotalValueCount();

long getNullValueCount();

/**
* @return the ratio of null values to all valid values written into this MemTable
*/
double getNullValueRatio();

/**
* insert into this memtable
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ public class TsFileProcessor {
/** Total memtable size for mem control. */
private long totalMemTableSize;

private long totalValueCount;

private long nullValueCount;

private final AtomicBoolean isTotallyGeneratedByPipe = new AtomicBoolean(true);

private static final String FLUSH_QUERY_WRITE_LOCKED = "{}: {} get flushQueryLock write lock";
Expand Down Expand Up @@ -1652,6 +1656,8 @@ private Future<?> addAMemtableIntoFlushingList(IMemTable tobeFlushed) throws IOE

if (!(tobeFlushed.isSignalMemTable() || tobeFlushed.isEmpty())) {
totalMemTableSize += tobeFlushed.memSize();
totalValueCount += tobeFlushed.getTotalValueCount();
nullValueCount += tobeFlushed.getNullValueCount();
}
WritingMetrics.getInstance()
.recordMemTableLiveDuration(System.currentTimeMillis() - getWorkMemTableCreatedTime());
Expand Down Expand Up @@ -1942,16 +1948,20 @@ public void flushOneMemTable() {
private void updateCompressionRatio() {
try {
double compressionRatio = ((double) totalMemTableSize) / writer.getPos();
double nullValueRatio = totalValueCount == 0 ? 0 : (double) nullValueCount / totalValueCount;
logger.info(
StorageEngineMessages
.STORAGE_LOG_THE_COMPRESSION_RATIO_OF_TSFILE_IS_TOTALMEMTABLESIZE_THE_8CE66BE3,
.STORAGE_LOG_THE_COMPRESSION_RATIO_OF_TSFILE_IS_TOTALMEMTABLESIZE_THE_FILE_SIZE_NULL_VALUE_RATIO_46F3B1F7,
writer.getFile().getAbsolutePath(),
String.format("%.2f", compressionRatio),
totalMemTableSize,
writer.getPos());
writer.getPos(),
nullValueRatio);
String dataRegionId = dataRegionInfo.getDataRegion().getDataRegionIdString();
WritingMetrics.getInstance()
.recordTsFileCompressionRatioOfFlushingMemTable(dataRegionId, compressionRatio);
WritingMetrics.getInstance()
.recordTsFileNullValueRatioOfFlushingMemTable(dataRegionId, nullValueRatio);
CompressionRatio.getInstance().updateRatio(totalMemTableSize, writer.getPos(), dataRegionId);
} catch (IOException e) {
logger.error(
Expand Down
Loading
Loading