MarcosZyk commented on code in PR #8619:
URL: https://github.com/apache/iotdb/pull/8619#discussion_r1059865519


##########
schema-engine-tag/src/main/java/org/apache/iotdb/lsm/sstable/fileIO/FileOutput.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iotdb.lsm.sstable.fileIO;
+
+import org.apache.iotdb.lsm.sstable.bplustree.entry.IEntry;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * a FileOutput implementation with FileOutputStream. If the file is not 
existed, it will be
+ * created. Otherwise the file will be written from position 0.
+ */
+public class FileOutput extends OutputStream implements IFileOutput {
+
+  private static final int DEFAULT_BUFFER_SIZE = 1024 * 1024;
+
+  private FileOutputStream outputStream;
+  private DataOutputStream dataOutputStream;
+  private ByteBuffer byteBuffer;

Review Comment:
   These two can be combined as ```new DataOutputStream(new 
BufferedOutputStream(.....))```.



##########
schema-engine-tag/src/main/java/org/apache/iotdb/lsm/sstable/fileIO/FileOutput.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iotdb.lsm.sstable.fileIO;
+
+import org.apache.iotdb.lsm.sstable.bplustree.entry.IEntry;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * a FileOutput implementation with FileOutputStream. If the file is not 
existed, it will be
+ * created. Otherwise the file will be written from position 0.
+ */
+public class FileOutput extends OutputStream implements IFileOutput {
+
+  private static final int DEFAULT_BUFFER_SIZE = 1024 * 1024;
+
+  private FileOutputStream outputStream;
+  private DataOutputStream dataOutputStream;
+  private ByteBuffer byteBuffer;
+  private long position;

Review Comment:
   ```RecordableOutputStream``` can be implemented and applied.



##########
schema-engine-tag/src/main/java/org/apache/iotdb/lsm/sstable/bplustree/writer/IBPlusTreeWriter.java:
##########
@@ -0,0 +1,121 @@
+/*
+ * 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.iotdb.lsm.sstable.bplustree.writer;
+
+import org.apache.iotdb.lsm.sstable.bplustree.entry.BPlusTreeEntry;
+import org.apache.iotdb.lsm.sstable.bplustree.entry.BPlusTreeHeader;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.Queue;
+
+/** Used to generate a b+ tree for records and write to disk */
+public interface IBPlusTreeWriter {
+
+  /**
+   * generate a b+ tree and header for records and write to disk
+   *
+   * @param records a map that holds all records, the map can be unordered
+   * @param ordered whether the queue is in order
+   * @return start offset of the b+ tree
+   * @throws IOException
+   */
+  long write(Map<String, Long> records, boolean ordered) throws IOException;
+
+  /**
+   * generate a b+ tree for records and write to disk
+   *
+   * @param records a map that holds all records, the map can be unordered
+   * @param ordered whether the queue is in order
+   * @return b+ tree header
+   * @throws IOException
+   */
+  BPlusTreeHeader writeBPlusTree(Map<String, Long> records, boolean ordered) 
throws IOException;
+
+  /**
+   * generate a b+ tree and header for records and write to disk
+   *
+   * @param records a queue that holds all records, the queue can be unordered
+   * @param ordered whether the queue is in order
+   * @return start offset of the b+ tree
+   * @throws IOException
+   */
+  long write(Queue<BPlusTreeEntry> records, boolean ordered) throws 
IOException;
+
+  /**
+   * generate a b+ tree for records and write to disk
+   *
+   * @param records a queue that holds all records, the queue can be unordered
+   * @param ordered whether the queue is in order
+   * @return b+ tree header
+   * @throws IOException
+   */
+  BPlusTreeHeader writeBPlusTree(Queue<BPlusTreeEntry> records, boolean 
ordered) throws IOException;
+
+  /**
+   * collect the records to be written to the disk, and only call write or 
writeBPlusTree to
+   * actually write to the disk, if the written records are ordered, you can 
directly call the write
+   * or writeBPlusTree methods to write to disk, otherwise call the 
sortAndWrite and
+   * sortAndWriteBPlusTree methods
+   *
+   * @param name name of the record
+   * @param offset offset of the record
+   * @return this
+   */
+  IBPlusTreeWriter collectRecord(String name, long offset);

Review Comment:
   Add a class like ```BPlusTreeBuilder```.



##########
schema-engine-tag/src/main/java/org/apache/iotdb/lsm/sstable/fileIO/FileOutput.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * 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.iotdb.lsm.sstable.fileIO;
+
+import org.apache.iotdb.lsm.sstable.bplustree.entry.IEntry;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * a FileOutput implementation with FileOutputStream. If the file is not 
existed, it will be
+ * created. Otherwise the file will be written from position 0.
+ */
+public class FileOutput extends OutputStream implements IFileOutput {

Review Comment:
   Rename to ```TiFileOutputStream```.



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