zhangshenghang commented on code in PR #10399:
URL: https://github.com/apache/seatunnel/pull/10399#discussion_r2736804603


##########
seatunnel-engine/seatunnel-engine-storage/imap-storage-plugins/imap-storage-file/src/main/java/org/apache/seatunnel/engine/imap/storage/file/wal/writer/lsm/AbstractLSMWriter.java:
##########
@@ -0,0 +1,291 @@
+/*
+ * 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.wal.writer.lsm;
+
+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.FileConstants;
+import org.apache.seatunnel.engine.imap.storage.file.common.WALDataUtils;
+import org.apache.seatunnel.engine.imap.storage.file.wal.IMapFileIterator;
+import org.apache.seatunnel.engine.imap.storage.file.wal.WALFileIterator;
+import org.apache.seatunnel.engine.imap.storage.file.wal.reader.DefaultReader;
+import org.apache.seatunnel.engine.imap.storage.file.wal.writer.CompactionFile;
+import org.apache.seatunnel.engine.imap.storage.file.wal.writer.IFileWriter;
+import org.apache.seatunnel.engine.serializer.api.Serializer;
+
+import org.apache.hadoop.fs.FSDataOutputStream;
+import org.apache.hadoop.fs.FileStatus;
+import org.apache.hadoop.fs.FileSystem;
+import org.apache.hadoop.fs.Path;
+
+import lombok.extern.slf4j.Slf4j;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.PriorityBlockingQueue;
+import java.util.concurrent.atomic.AtomicLong;
+
+@Slf4j
+public abstract class AbstractLSMWriter implements IFileWriter<IMapFileData> {
+
+    protected final AtomicLong index = new AtomicLong(0);
+    protected final AtomicLong tmpIndex = new AtomicLong(0);
+    protected long blockSize = 1L * 1024 * 1024;
+    protected long compactionThreshold = 512L * 1024 * 1024;
+    protected long maxSingleFileSize = 16L * 1024 * 1024;
+    protected long compactionBatchSize = 16L * 1024 * 1024;
+    protected long compactionInterval = 60L * 1000;
+
+    protected final AtomicLong totalBytes = new AtomicLong(0);
+    protected final BlockingQueue<CompactionFile> fileNames = new 
PriorityBlockingQueue<>();
+    protected long compactionIndex = 0;
+
+    protected List<IMapFileData> writeBatch = new ArrayList<>();
+
+    protected FileSystem fs;
+    protected Path parentPath;
+    protected Path finalPath;
+    protected Path currentTmpPath;
+    protected Serializer serializer;
+
+    protected volatile boolean isRunning = true;
+
+    protected AbstractLSMWriter(Map<String, Object> config) {
+        if (config.get(FileConstants.FileInitProperties.COMPACTION_THRESHOLD) 
!= null) {
+            long threshold =
+                    (long) 
config.get(FileConstants.FileInitProperties.COMPACTION_THRESHOLD);
+            if (threshold > 0) {
+                compactionThreshold = threshold;
+            }
+        }
+        if (config.get(FileConstants.FileInitProperties.MAX_SINGLE_FILE_SIZE) 
!= null) {
+            long maxSize = (long) 
config.get(FileConstants.FileInitProperties.MAX_SINGLE_FILE_SIZE);
+            if (maxSize > 0) {
+                maxSingleFileSize = maxSize;
+            }
+        }
+        if (config.get(FileConstants.FileInitProperties.COMPACTION_BATCH_SIZE) 
!= null) {
+            long batchSize =
+                    (long) 
config.get(FileConstants.FileInitProperties.COMPACTION_BATCH_SIZE);
+            if (batchSize > 0 && batchSize >= maxSingleFileSize) {
+                compactionBatchSize = batchSize;
+            } else {
+                throw new IllegalArgumentException(
+                        "compaction batch size must be >= max single file 
size");
+            }
+        }
+        if (config.get(FileConstants.FileInitProperties.COMPACTION_INTERVAL) 
!= null) {
+            long interval = (long) 
config.get(FileConstants.FileInitProperties.COMPACTION_INTERVAL);
+            if (interval > 0) {
+                compactionInterval = interval;
+            }
+        }
+    }

Review Comment:
   How about we convert it this way? That way, even if the user makes a wrong 
configuration, they can clearly perceive it.
   
   ```
   private long asLong(Object v, long defaultValue) {
     if (v == null) return defaultValue;
     if (v instanceof Number) return ((Number) v).longValue(); 
     if (v instanceof String) return Long.parseLong(((String) v).trim()); 
     throw new IllegalArgumentException("Expect number or string, but got: " + 
v.getClass());
   }
   ```



-- 
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]

Reply via email to