yihua commented on code in PR #13166: URL: https://github.com/apache/hudi/pull/13166#discussion_r2052024407
########## hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileLeafIndexBlock.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.hudi.io.hfile; + +import org.apache.hudi.common.util.Option; + +import java.util.ArrayList; +import java.util.List; + +import static org.apache.hudi.io.util.IOUtils.copy; +import static org.apache.hudi.io.util.IOUtils.readInt; +import static org.apache.hudi.io.util.IOUtils.readLong; + +public class HFileLeafIndexBlock extends HFileBlock { Review Comment: Fixed. ########## hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileRootIndexBlock.java: ########## @@ -74,4 +74,24 @@ public TreeMap<Key, BlockIndexEntry> readBlockIndex(int numEntries, boolean cont } return blockIndexEntryMap; } + + /** + * Returns the block index entries contained in the root index block. + */ + public List<BlockIndexEntry> readBlockIndexForMultiLevelIndex(int numEntries, + boolean contentKeyOnly) { + List<BlockIndexEntry> indexEntries = new ArrayList<>(); + int buffOffset = startOffsetInBuff + HFILEBLOCK_HEADER_SIZE; + for (int i = 0; i < numEntries; i++) { + long offset = readLong(byteBuff, buffOffset); + int size = readInt(byteBuff, buffOffset + 8); + int varLongSizeOnDist = decodeVarLongSizeOnDisk(byteBuff, buffOffset + 12); + int keyLength = (int) readVarLong(byteBuff, buffOffset + 12, varLongSizeOnDist); + byte[] keyBytes = copy(byteBuff, buffOffset + 12 + varLongSizeOnDist, keyLength); + Key key = contentKeyOnly ? new UTF8StringKey(keyBytes) : new Key(keyBytes); Review Comment: Fixed. ########## hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileReaderImpl.java: ########## @@ -75,7 +78,12 @@ public synchronized void initializeMetadata() throws IOException { fileSize - HFileTrailer.getTrailerSize()); HFileRootIndexBlock dataIndexBlock = (HFileRootIndexBlock) blockReader.nextBlock(HFileBlockType.ROOT_INDEX); - this.dataBlockIndexEntryMap = dataIndexBlock.readBlockIndex(trailer.getDataIndexCount(), false); + if (trailer.getNumDataIndexLevels() == 1) { + this.dataBlockIndexEntryMap = dataIndexBlock.readBlockIndex(trailer.getDataIndexCount(), false); + } else { + this.dataBlockIndexEntryMap = readBlockIndexForMultiLevelIndex( + trailer.getDataIndexCount(), false, trailer.getNumDataIndexLevels()); + } Review Comment: Consolidated into a new method `HFileReaderImpl#readDataBlockIndex` ########## hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileLeafIndexBlock.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.hudi.io.hfile; + +import org.apache.hudi.common.util.Option; + +import java.util.ArrayList; +import java.util.List; + +import static org.apache.hudi.io.util.IOUtils.copy; +import static org.apache.hudi.io.util.IOUtils.readInt; +import static org.apache.hudi.io.util.IOUtils.readLong; + +public class HFileLeafIndexBlock extends HFileBlock { Review Comment: Fixed. ########## hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileIntermediateIndexBlock.java: ########## @@ -0,0 +1,28 @@ +/* + * 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.hudi.io.hfile; + +public class HFileIntermediateIndexBlock extends HFileLeafIndexBlock { Review Comment: Fixed. ########## hudi-io/src/main/java/org/apache/hudi/io/hfile/HFileReaderImpl.java: ########## @@ -299,4 +307,69 @@ private boolean isAtFirstKey() { } return false; } + + /** + * Read multiple-level indexes, and load all data block information into memory in BFS fashion. + * + * @param numEntries The number of entries in the root index block. + * @param contentKeyOnly Only need the key content. + * @param levels The level of the indexes. + * @return + */ + public TreeMap<Key, BlockIndexEntry> readBlockIndexForMultiLevelIndex(int numEntries, + boolean contentKeyOnly, + int levels) throws IOException { + // Stores next patch of leaf index entries in order. + List<BlockIndexEntry> indexEntries; + + // Parse root index block. + HFileBlockReader blockReader = new HFileBlockReader( + context, stream, trailer.getLoadOnOpenDataOffset(), fileSize - HFileTrailer.getTrailerSize()); + HFileBlock block = blockReader.nextBlock(HFileBlockType.ROOT_INDEX); Review Comment: Fixed with `HFileReaderImpl#readDataBlockIndex` -- 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]
