Skip to content

Commit

Permalink
Load: Fix locally load v3 tsfile with PlainDeviceTimeIndex (#14098)
Browse files Browse the repository at this point in the history
Co-authored-by: Steve Yurong Su <[email protected]>
  • Loading branch information
luoluoyuyu and SteveYurongSu authored Nov 21, 2024
1 parent e66f3a8 commit a7f2d6b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
import org.apache.iotdb.db.storageengine.dataregion.DataRegion;
import org.apache.iotdb.db.storageengine.dataregion.flush.MemTableFlushTask;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.TsFileResource;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.timeindex.ArrayDeviceTimeIndex;
import org.apache.iotdb.db.storageengine.dataregion.tsfile.timeindex.PlainDeviceTimeIndex;
import org.apache.iotdb.db.storageengine.load.memory.LoadTsFileDataCacheMemoryBlock;
import org.apache.iotdb.db.storageengine.load.memory.LoadTsFileMemoryManager;
import org.apache.iotdb.db.storageengine.load.metrics.LoadTsFileCostMetricsSet;
Expand All @@ -70,6 +72,7 @@

import io.airlift.units.Duration;
import org.apache.tsfile.file.metadata.IDeviceID;
import org.apache.tsfile.file.metadata.StringArrayDeviceID;
import org.apache.tsfile.utils.Pair;
import org.apache.tsfile.utils.PublicBAOS;
import org.slf4j.Logger;
Expand All @@ -89,6 +92,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -414,6 +418,24 @@ private boolean loadLocally(LoadSingleTsFileNode node) throws IoTDBException {
throw new LoadReadOnlyException();
}

// if the time index is PlainDeviceTimeIndex, convert it to ArrayDeviceTimeIndex
if (node.getTsFileResource().getTimeIndex() instanceof PlainDeviceTimeIndex) {
final PlainDeviceTimeIndex timeIndex =
(PlainDeviceTimeIndex) node.getTsFileResource().getTimeIndex();
final Map<IDeviceID, Integer> convertedDeviceToIndex = new ConcurrentHashMap<>();
for (final Map.Entry<IDeviceID, Integer> entry : timeIndex.getDeviceToIndex().entrySet()) {
convertedDeviceToIndex.put(
entry.getKey() instanceof StringArrayDeviceID
? entry.getKey()
: new StringArrayDeviceID(entry.getKey().toString()),
entry.getValue());
}
node.getTsFileResource()
.setTimeIndex(
new ArrayDeviceTimeIndex(
convertedDeviceToIndex, timeIndex.getStartTimes(), timeIndex.getEndTimes()));
}

try {
FragmentInstance instance =
new FragmentInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,9 @@ public ArrayDeviceTimeIndex buildDeviceTimeIndex() throws IOException {
}
}

/** Only used for compaction to validate tsfile. */
/**
* Used for compaction to verify tsfile, also used to verify TimeIndex version when loading tsfile
*/
public ITimeIndex getTimeIndex() {
return timeIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ public Set<IDeviceID> getDevices(String tsFilePath, TsFileResource tsFileResourc
return deviceToIndex.keySet();
}

public Map<IDeviceID, Integer> getDeviceToIndex() {
return deviceToIndex;
}

public long[] getEndTimes() {
return endTimes;
}

public long[] getStartTimes() {
return startTimes;
}

/**
* Deserialize TimeIndex and get devices only.
*
Expand Down

0 comments on commit a7f2d6b

Please sign in to comment.