dybyte commented on code in PR #10399: URL: https://github.com/apache/seatunnel/pull/10399#discussion_r2740407029
########## seatunnel-engine/seatunnel-engine-storage/imap-storage-plugins/imap-storage-file/src/main/java/org/apache/seatunnel/engine/imap/storage/file/disruptor/WALCompactionDisruptor.java: ########## @@ -0,0 +1,128 @@ +/* + * 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.seatunnel.engine.imap.storage.file.disruptor; + +import org.apache.seatunnel.engine.imap.storage.api.exception.IMapStorageException; +import org.apache.seatunnel.engine.imap.storage.file.bean.IMapFileData; +import org.apache.seatunnel.engine.imap.storage.file.common.WALLSMWriter; +import org.apache.seatunnel.engine.imap.storage.file.common.WALWriter; +import org.apache.seatunnel.engine.imap.storage.file.config.FileConfiguration; +import org.apache.seatunnel.engine.serializer.api.Serializer; + +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; + +import com.lmax.disruptor.BlockingWaitStrategy; +import com.lmax.disruptor.EventTranslatorOneArg; +import com.lmax.disruptor.TimeoutException; +import com.lmax.disruptor.dsl.Disruptor; +import com.lmax.disruptor.dsl.ProducerType; +import com.lmax.disruptor.util.DaemonThreadFactory; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; +import java.util.Map; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; + +@Slf4j +public class WALCompactionDisruptor extends AbstractWALDisruptor { + private static final EventTranslatorOneArg<FileWALEvent, WALEventType> COMPACTION_TRANSLATOR = + (event, sequence, status) -> { + event.setData(null); + event.setType(status); + event.setRequestId(0L); + }; + + private Disruptor<FileWALEvent> compactionDisruptor; + + public WALCompactionDisruptor( + FileSystem fs, + FileConfiguration fileConfiguration, + String parentPath, + Serializer serializer, + Map<String, Object> config) { + ThreadFactory threadFactory = DaemonThreadFactory.INSTANCE; + this.disruptor = + new Disruptor<>( + FileWALEvent.FACTORY, + DEFAULT_RING_BUFFER_SIZE, + threadFactory, + ProducerType.SINGLE, + new BlockingWaitStrategy()); + + WALWriter writer; + try { + writer = + new WALLSMWriter( + fs, fileConfiguration, new Path(parentPath), serializer, config); + } catch (IOException e) { + throw new IMapStorageException( + e, "create new current writer failed, parent path is %s", parentPath); + } + + disruptor.handleEventsWithWorkerPool(new WALWorkHandler(writer)); + + disruptor.start(); + + this.compactionDisruptor = + new Disruptor<>( + FileWALEvent.FACTORY, + DEFAULT_RING_BUFFER_SIZE, + threadFactory, + ProducerType.SINGLE, + new BlockingWaitStrategy()); + + compactionDisruptor.handleEventsWithWorkerPool( + new WALCompactionWorkHandler((WALLSMWriter) writer)); + + compactionDisruptor.start(); + } + + @Override + public boolean tryPublish(IMapFileData message, WALEventType status, long requestId) { + if (isClosed()) { + return false; + } + disruptor.getRingBuffer().publishEvent(TRANSLATOR, message, status, requestId); + compactionDisruptor.getRingBuffer().publishEvent(COMPACTION_TRANSLATOR, status); + return true; Review Comment: I have created the compaction scheduler in `AbstractLSMWriter` to decouple it from the write path, as suggested. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
