ic4y commented on code in PR #3418: URL: https://github.com/apache/incubator-seatunnel/pull/3418#discussion_r1028712330
########## seatunnel-engine/seatunnel-engine-storage/imap-storage-file/src/main/java/org/apache/seatunnel/engine/imap/storage/file/IMapFileStorage.java: ########## @@ -0,0 +1,442 @@ +/* + * 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; + +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.DEFAULT_ARCHIVE_SCHEDULER_TIME_IN_SECONDS; +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.DEFAULT_IMAP_FILE_PATH_SPLIT; +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.DEFAULT_IMAP_NAMESPACE; +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.FileInitProperties.ARCHIVE_SCHEDULER_TIME_IN_SECONDS_KEY; +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.FileInitProperties.BUSINESS_KEY; +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.FileInitProperties.CLUSTER_NAME; +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.FileInitProperties.HDFS_CONFIG_KEY; +import static org.apache.seatunnel.engine.imap.storage.file.common.FileConstants.FileInitProperties.NAMESPACE_KEY; +import static org.apache.seatunnel.engine.imap.storage.file.common.OrcConstants.ORC_FILE_ARCHIVE_PATH; + +import org.apache.seatunnel.engine.imap.storage.api.IMapStorage; +import org.apache.seatunnel.engine.imap.storage.api.common.ProtoStuffSerializer; +import org.apache.seatunnel.engine.imap.storage.api.common.Serializer; +import org.apache.seatunnel.engine.imap.storage.api.exception.IMapStorageException; +import org.apache.seatunnel.engine.imap.storage.file.bean.IMapData; +import org.apache.seatunnel.engine.imap.storage.file.bean.IMapFileData; +import org.apache.seatunnel.engine.imap.storage.file.common.FileConstants; +import org.apache.seatunnel.engine.imap.storage.file.disruptor.WALDisruptor; +import org.apache.seatunnel.engine.imap.storage.file.disruptor.WALEventType; +import org.apache.seatunnel.engine.imap.storage.file.future.RequestFuture; +import org.apache.seatunnel.engine.imap.storage.file.future.RequestFutureCache; +import org.apache.seatunnel.engine.imap.storage.file.orc.OrcReader; +import org.apache.seatunnel.engine.imap.storage.file.scheduler.ArchiveFileTask; + +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.ClassUtils; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.LocatedFileStatus; +import org.apache.hadoop.fs.Path; +import org.apache.hadoop.fs.RemoteIterator; +import org.apache.hadoop.mapred.JobConf; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * IMapFileStorage + * Please notice : + * Only applicable to big data (kv) storage. Otherwise, there may be a lot of fragmented files + * This is not suitable for frequently updated scenarios because all data is stored as an appended file. + * There is no guarantee that all files will be up-to-date when a query is made, and this delay depends on the archive cycle. + * If you write large amounts of data in batches, it is best to archive immediately. + * Some design detail: + * base on file, use orc file to store data + * use disruptor to write data to file + * use orc reader to read data from file + * use wal to ensure data consistency + * use request future to ensure data consistency + */ +@Slf4j +public class IMapFileStorage implements IMapStorage { + + public FileSystem fs; + + public String namespace; + + /** + * virtual region, Randomly generate a region name + */ + public String region; + + /** + * like OSS bucket name + * It is used to distinguish data storage locations of different business. + */ + public String businessName; + + /** + * This parameter is primarily used for cluster isolation + * we can use this to distinguish different cluster, like cluster1, cluster2 + * and this is also used to distinguish different business + */ + public String clusterName; + + /** + * We used disruptor to implement the asynchronous write. + */ + WALDisruptor walDisruptor; + + /** + * serializer, default is ProtoStuffSerializer + */ + Serializer serializer; + + private String businessRootPath = null; + + public static final int DEFAULT_ARCHIVE_WAIT_TIME_MILLISECONDS = 1000 * 60; Review Comment: Can `DEFAULT_ARCHIVE_WAIT_TIME_MILLISECONDS` be set to 0 manually, Most usage scenarios need to write files synchronously -- 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]
