You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by "EMsnap (via GitHub)" <gi...@apache.org> on 2023/04/23 02:59:07 UTC

[GitHub] [inlong] EMsnap commented on a diff in pull request #7878: [INLONG-7831][Sort] Using Spilling disk map to reduce memory loss for buffer per parititon data in iceberg ingesting

EMsnap commented on code in PR #7878:
URL: https://github.com/apache/inlong/pull/7878#discussion_r1174497008


##########
inlong-sort/sort-connectors/iceberg/src/test/java/org/apache/inlong/sort/iceberg/sink/TestRocksDBKVBuffer.java:
##########
@@ -0,0 +1,56 @@
+/*
+ * 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.inlong.sort.iceberg.sink;
+
+import org.apache.flink.api.common.typeutils.base.StringSerializer;
+import org.apache.inlong.sort.iceberg.sink.collections.RocksDBKVBuffer;
+import org.junit.Test;
+
+import java.io.File;
+import java.util.UUID;
+
+public class TestRocksDBKVBuffer {
+
+    @Test
+    public void testRepeatputAndClear() {
+        RocksDBKVBuffer<String, String> buffer = new RocksDBKVBuffer<>(
+                StringSerializer.INSTANCE,
+                StringSerializer.INSTANCE,
+                System.getProperty("java.io.tmpdir") + File.separator + "mini_batch");
+        for (int i = 0; i < 10; i++) {
+            repeatPutAndClear(buffer);
+        }
+        buffer.close();
+    }
+
+    public void repeatPutAndClear(RocksDBKVBuffer<String, String> buffer) {
+        System.out.println("---------------------------------------------------------------");

Review Comment:
   could you please use the same org.slf4j as in other test cases? 



##########
inlong-sort/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/collections/SortedHeapKVBuffer.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * 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.inlong.sort.iceberg.sink.collections;
+
+import org.apache.flink.api.java.tuple.Tuple2;
+
+import java.io.Serializable;
+import java.util.NavigableMap;
+import java.util.TreeMap;
+import java.util.stream.Stream;
+
+public class SortedHeapKVBuffer<T, R> implements KVBuffer<T, R>, Serializable {
+
+    private static final long serialVersionUID = 1L;
+    private final NavigableMap<T, R> map;
+    private final KVBuffer.Convertor<T> convertor;
+
+    public SortedHeapKVBuffer(KVBuffer.Convertor<T> convertor) {
+        this.convertor = convertor;
+        this.map = new TreeMap<>(convertor::compare);

Review Comment:
   can be simplified to TreeMap<>(convertor)



##########
inlong-sort/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/collections/FileIOUtils.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.inlong.sort.iceberg.sink.collections;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
+/**
+ * A tool class for safely creating and deleting directories that wraps exception information.
+ */
+public class FileIOUtils {
+
+    public static void deleteDirectory(File directory) throws IOException {
+        if (directory != null && directory.exists()) {
+            Files.walk(directory.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+            directory.delete();

Review Comment:
   can be simplified to if(!dir.delete()) throw 



##########
inlong-sort/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/collections/FileIOUtils.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.inlong.sort.iceberg.sink.collections;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
+/**
+ * A tool class for safely creating and deleting directories that wraps exception information.
+ */
+public class FileIOUtils {
+
+    public static void deleteDirectory(File directory) throws IOException {
+        if (directory != null && directory.exists()) {
+            Files.walk(directory.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
+            directory.delete();
+            if (directory.exists()) {
+                throw new IOException("Unable to delete directory " + directory);
+            }
+        }
+    }
+
+    public static void mkdir(File directory) throws IOException {
+        if (directory != null && !directory.exists()) {
+            directory.mkdirs();

Review Comment:
   ditto 



##########
inlong-sort/sort-connectors/iceberg/src/main/java/org/apache/inlong/sort/iceberg/sink/collections/FileIOUtils.java:
##########
@@ -0,0 +1,50 @@
+/*
+ * 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.inlong.sort.iceberg.sink.collections;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Comparator;
+
+/**
+ * A tool class for safely creating and deleting directories that wraps exception information.
+ */
+public class FileIOUtils {
+
+    public static void deleteDirectory(File directory) throws IOException {
+        if (directory != null && directory.exists()) {
+            Files.walk(directory.toPath()).sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);

Review Comment:
   walk returns a Stream so it should be surrounded by a try-with-resources for the sake of resource leak



-- 
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: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org