samperson1997 commented on a change in pull request #1100:
URL: https://github.com/apache/incubator-iotdb/pull/1100#discussion_r415345210
##########
File path:
tsfile/src/main/java/org/apache/iotdb/tsfile/write/writer/TsFileIOWriter.java
##########
@@ -304,22 +311,120 @@ public void endFile() throws IOException {
deviceTimeseriesMetadataMap.computeIfAbsent(device, k -> new
ArrayList<>())
.add(timeseriesMetaData);
}
- // create DeviceMetaDataMap device -> Pair<TimeseriesMetaDataOffset,
TimeseriesMetaDataLength>
- Map<String, Pair<Long, Integer>> deviceMetadataMap = new HashMap<>();
+
+ // create TsFileMetadata
+ Map<String, Queue<MetadataIndex>> deviceMetadataIndexMap = new TreeMap<>();
+ int maxNumOfIndexItems = config.getMaxNumberOfIndexItemsInNode();
+
+ // for timeseriesMetadata of each device
for (Map.Entry<String, List<TimeseriesMetadata>> entry :
deviceTimeseriesMetadataMap
.entrySet()) {
- String device = entry.getKey();
- List<TimeseriesMetadata> timeseriesMetadataList = entry.getValue();
- long offsetOfFirstTimeseriesMetaDataInDevice = out.getPosition();
- int size = 0;
- for (TimeseriesMetadata timeseriesMetaData : timeseriesMetadataList) {
- size += timeseriesMetaData.serializeTo(out.wrapAsStream());
+ if (entry.getValue().isEmpty()) {
+ continue;
+ }
+ Queue<MetadataIndex> measurementMetadataIndexQueue = new ArrayDeque<>();
+ TimeseriesMetadata timeseriesMetadata;
+ for (int i = 0; i < entry.getValue().size(); i++) {
+ timeseriesMetadata = entry.getValue().get(i);
+ if (i % maxNumOfIndexItems == 0) {
+ measurementMetadataIndexQueue
+ .add(new MetadataIndex(timeseriesMetadata.getMeasurementId(),
out.getPosition(),
+ ChildMetadataIndexType.MEASUREMENT));
+ }
+ timeseriesMetadata.serializeTo(out.wrapAsStream());
+ }
+ measurementMetadataIndexQueue
+ .add(new MetadataIndex("", out.getPosition(),
ChildMetadataIndexType.MEASUREMENT));
+
+ int queueSize = measurementMetadataIndexQueue.size();
+ MetadataIndex metadataIndex;
+ while (queueSize > maxNumOfIndexItems) {
+ for (int i = 0; i < queueSize; i++) {
+ metadataIndex = measurementMetadataIndexQueue.poll();
+ if (i % maxNumOfIndexItems == 0) {
+ if (i != 0) {
+ addEmptyMetadataIndex(ChildMetadataIndexType.MEASUREMENT_INDEX);
Review comment:
Renamed
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]