Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix non-latest partition last flush time cannot recover #11999

Merged
merged 2 commits into from
Jan 29, 2024
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
Expand Up @@ -524,20 +524,12 @@ private void recover() throws DataRegionException {
}
for (Entry<Long, List<TsFileResource>> partitionFiles : partitionTmpSeqTsFiles.entrySet()) {
recoverFilesInPartition(
partitionFiles.getKey(),
dataRegionRecoveryContext,
partitionFiles.getValue(),
true,
partitionFiles.getKey() == latestPartitionId);
partitionFiles.getKey(), dataRegionRecoveryContext, partitionFiles.getValue(), true);
}
for (Entry<Long, List<TsFileResource>> partitionFiles :
partitionTmpUnseqTsFiles.entrySet()) {
recoverFilesInPartition(
partitionFiles.getKey(),
dataRegionRecoveryContext,
partitionFiles.getValue(),
false,
partitionFiles.getKey() == latestPartitionId);
partitionFiles.getKey(), dataRegionRecoveryContext, partitionFiles.getValue(), false);
}
if (config.isEnableSeparateData()) {
TimePartitionManager.getInstance()
Expand Down Expand Up @@ -763,7 +755,7 @@ private void recoverUnsealedTsFileCallBack(UnsealedTsFileRecoverPerformer recove
dataRegionInfo,
tsFileResource,
this::closeUnsealedTsFileProcessorCallBack,
isSeq ? this::sequenceFlushCallback : this::unsequenceFlushCallback,
this::flushCallback,
isSeq,
writer);
if (workSequenceTsFileProcessors.get(tsFileProcessor.getTimeRangeId()) == null
Expand Down Expand Up @@ -825,12 +817,11 @@ private void recoverFilesInPartition(
long partitionId,
DataRegionRecoveryContext context,
List<TsFileResource> resourceList,
boolean isSeq,
boolean isLatestPartition) {
boolean isSeq) {
for (TsFileResource tsFileResource : resourceList) {
recoverSealedTsFiles(tsFileResource, context, isSeq);
}
if (isLatestPartition && config.isEnableSeparateData()) {
if (config.isEnableSeparateData()) {
lastFlushTimeMap.checkAndCreateFlushedTimePartition(partitionId);
for (TsFileResource tsFileResource : resourceList) {
updateLastFlushTime(tsFileResource, isSeq);
Expand Down Expand Up @@ -1405,26 +1396,14 @@ private TsFileProcessor newTsFileProcessor(boolean sequence, long timePartitionI

private TsFileProcessor getTsFileProcessor(
boolean sequence, String filePath, long timePartitionId) throws IOException {
TsFileProcessor tsFileProcessor;
if (sequence) {
tsFileProcessor =
new TsFileProcessor(
databaseName + FILE_NAME_SEPARATOR + dataRegionId,
fsFactory.getFileWithParent(filePath),
dataRegionInfo,
this::closeUnsealedTsFileProcessorCallBack,
this::sequenceFlushCallback,
true);
} else {
tsFileProcessor =
new TsFileProcessor(
databaseName + FILE_NAME_SEPARATOR + dataRegionId,
fsFactory.getFileWithParent(filePath),
dataRegionInfo,
this::closeUnsealedTsFileProcessorCallBack,
this::unsequenceFlushCallback,
false);
}
TsFileProcessor tsFileProcessor =
new TsFileProcessor(
databaseName + FILE_NAME_SEPARATOR + dataRegionId,
fsFactory.getFileWithParent(filePath),
dataRegionInfo,
this::closeUnsealedTsFileProcessorCallBack,
this::flushCallback,
sequence);

if (enableMemControl) {
TsFileProcessorInfo tsFileProcessorInfo = new TsFileProcessorInfo(dataRegionInfo);
Expand Down Expand Up @@ -2338,26 +2317,7 @@ private void separateTsFileToDelete(
}
}

private void unsequenceFlushCallback(
TsFileProcessor processor, Map<String, Long> updateMap, long systemFlushTime) {
if (!config.isEnableSeparateData()
&& CommonDescriptor.getInstance().getConfig().isLastCacheEnable()) {
// update globalLastFlushTime if and only if isEnableSeparateData is false and
// isLastCacheEnable is true
lastFlushTimeMap.updateMultiDeviceGlobalFlushedTime(updateMap);
}
if (config.isEnableSeparateData()) {
TimePartitionManager.getInstance()
.updateAfterFlushing(
new DataRegionId(Integer.valueOf(dataRegionId)),
processor.getTimeRangeId(),
systemFlushTime,
lastFlushTimeMap.getMemSize(processor.getTimeRangeId()),
workSequenceTsFileProcessors.get(processor.getTimeRangeId()) != null);
}
}

private void sequenceFlushCallback(
private void flushCallback(
TsFileProcessor processor, Map<String, Long> updateMap, long systemFlushTime) {
if (config.isEnableSeparateData()
&& CommonDescriptor.getInstance().getConfig().isLastCacheEnable()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.apache.iotdb.commons.consensus.DataRegionId;
import org.apache.iotdb.commons.exception.IllegalPathException;
import org.apache.iotdb.db.exception.DataRegionException;
import org.apache.iotdb.db.exception.WriteProcessException;
import org.apache.iotdb.db.storageengine.StorageEngine;
import org.apache.iotdb.db.storageengine.dataregion.compaction.schedule.CompactionTaskManager;
Expand Down Expand Up @@ -129,6 +130,42 @@ record = new TSRecord(j, "root.vehicle.d0");
10000, dataRegion.getLastFlushTimeMap().getFlushedTime(0, "root.vehicle.d1"));
}

@Test
public void testRecoverLastFlushTimeMap()
throws IOException, IllegalPathException, WriteProcessException, DataRegionException {
TSRecord record = new TSRecord(604_800_000, "root.vehicle.d0");
record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(1000)));
dataRegion.insert(DataRegionTest.buildInsertRowNodeByTSRecord(record));
dataRegion.syncCloseAllWorkingTsFileProcessors();

record = new TSRecord(604_799_999, "root.vehicle.d0");
record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(1000)));
dataRegion.insert(DataRegionTest.buildInsertRowNodeByTSRecord(record));
dataRegion.syncCloseAllWorkingTsFileProcessors();

for (int j = 1; j <= 10; j++) {
record = new TSRecord(j, "root.vehicle.d0");
record.addTuple(DataPoint.getDataPoint(TSDataType.INT32, measurementId, String.valueOf(j)));
dataRegion.insert(DataRegionTest.buildInsertRowNodeByTSRecord(record));
}

for (TsFileProcessor tsfileProcessor : dataRegion.getWorkUnsequenceTsFileProcessors()) {
tsfileProcessor.syncFlush();
}
dataRegion.syncCloseAllWorkingTsFileProcessors();
Assert.assertEquals(
604_800_000, dataRegion.getLastFlushTimeMap().getFlushedTime(1, "root.vehicle.d0"));
Assert.assertEquals(
604_799_999, dataRegion.getLastFlushTimeMap().getFlushedTime(0, "root.vehicle.d0"));

// recover from disk
dataRegion = new DataRegionTest.DummyDataRegion(systemDir, storageGroup);
Assert.assertEquals(
604_800_000, dataRegion.getLastFlushTimeMap().getFlushedTime(1, "root.vehicle.d0"));
Assert.assertEquals(
604_799_999, dataRegion.getLastFlushTimeMap().getFlushedTime(0, "root.vehicle.d0"));
}

@Test
public void testLastFlushedTimeWhenLargestTimestampInUnSeqSpace()
throws IllegalPathException, WriteProcessException {
Expand Down
Loading