Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.tsfile.write.writer;

import org.apache.tsfile.file.metadata.IChunkMetadata;
import org.apache.tsfile.read.common.Path;
import org.apache.tsfile.utils.Pair;

import java.util.List;

@FunctionalInterface
public interface FlushChunkMetadataListener {

// measurement id -> chunk metadata list
void onFlush(List<Pair<Path, List<IChunkMetadata>>> sortedChunkMetadataList);
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import java.util.Map.Entry;
import java.util.Queue;
import java.util.TreeMap;
import java.util.concurrent.CopyOnWriteArrayList;

import static org.apache.tsfile.file.metadata.MetadataIndexConstructor.addCurrentIndexNodeToQueue;
import static org.apache.tsfile.file.metadata.MetadataIndexConstructor.checkAndBuildLevelIndex;
Expand Down Expand Up @@ -131,6 +132,8 @@ public class TsFileIOWriter implements AutoCloseable {

protected String encryptKey;

private final List<FlushChunkMetadataListener> flushListeners = new CopyOnWriteArrayList<>();

/** empty construct function. */
protected TsFileIOWriter() {
if (TS_FILE_CONFIG.getEncryptFlag()) {
Expand Down Expand Up @@ -210,6 +213,10 @@ public void setEncryptParam(String encryptLevel, String encryptType, String encr
this.encryptKey = encryptKey;
}

public void addFlushListener(FlushChunkMetadataListener listener) {
flushListeners.add(listener);
}

/**
* Writes given bytes to output stream. This method is called when total memory size exceeds the
* chunk group size threshold.
Expand Down Expand Up @@ -723,6 +730,12 @@ protected int sortAndFlushChunkMetadata() throws IOException {
lastSerializePath = seriesPath;
logger.debug("Flushing {}", seriesPath);
}

// notify the listeners
for (final FlushChunkMetadataListener listener : flushListeners) {
listener.onFlush(sortedChunkMetadataList);
}

// clear the cache metadata to release the memory
chunkGroupMetadataList.clear();
if (chunkMetadataList != null) {
Expand Down
Loading