You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@paimon.apache.org by ju...@apache.org on 2026/03/19 09:49:29 UTC
(paimon) branch master updated: [core][python] Add a version number in BtreeFileFooter (#7461)
This is an automated email from the ASF dual-hosted git repository.
junhao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new a19d81380e [core][python] Add a version number in BtreeFileFooter (#7461)
a19d81380e is described below
commit a19d81380e9fc717985888cfb1b5ff1d60dc7501
Author: Faiz <wx...@antgroup.com>
AuthorDate: Thu Mar 19 17:49:23 2026 +0800
[core][python] Add a version number in BtreeFileFooter (#7461)
---
.../paimon/globalindex/btree/BTreeFileFooter.java | 41 ++++++++++++++++------
.../globalindex/btree/btree_file_footer.py | 35 ++++++++++--------
.../globalindex/btree/btree_index_reader.py | 2 +-
3 files changed, 51 insertions(+), 27 deletions(-)
diff --git a/paimon-common/src/main/java/org/apache/paimon/globalindex/btree/BTreeFileFooter.java b/paimon-common/src/main/java/org/apache/paimon/globalindex/btree/BTreeFileFooter.java
index 84293fd127..19994921c3 100644
--- a/paimon-common/src/main/java/org/apache/paimon/globalindex/btree/BTreeFileFooter.java
+++ b/paimon-common/src/main/java/org/apache/paimon/globalindex/btree/BTreeFileFooter.java
@@ -31,9 +31,11 @@ import static org.apache.paimon.utils.Preconditions.checkArgument;
/** The Footer for BTree file. */
public class BTreeFileFooter {
- public static final int MAGIC_NUMBER = 198732882;
- public static final int ENCODED_LENGTH = 48;
+ public static final int MAGIC_NUMBER = 0x50425449;
+ public static final int CURRENT_VERSION = 1;
+ public static final int ENCODED_LENGTH = 52;
+ private final int version;
@Nullable private final BloomFilterHandle bloomFilterHandle;
private final BlockHandle indexBlockHandle;
@Nullable private final BlockHandle nullBitmapHandle;
@@ -42,11 +44,24 @@ public class BTreeFileFooter {
@Nullable BloomFilterHandle bloomFilterHandle,
BlockHandle indexBlockHandle,
BlockHandle nullBitmapHandle) {
+ this(CURRENT_VERSION, bloomFilterHandle, indexBlockHandle, nullBitmapHandle);
+ }
+
+ public BTreeFileFooter(
+ int version,
+ @Nullable BloomFilterHandle bloomFilterHandle,
+ BlockHandle indexBlockHandle,
+ BlockHandle nullBitmapHandle) {
+ this.version = version;
this.bloomFilterHandle = bloomFilterHandle;
this.indexBlockHandle = indexBlockHandle;
this.nullBitmapHandle = nullBitmapHandle;
}
+ public int getVersion() {
+ return version;
+ }
+
@Nullable
public BloomFilterHandle getBloomFilterHandle() {
return bloomFilterHandle;
@@ -62,6 +77,16 @@ public class BTreeFileFooter {
}
public static BTreeFileFooter readFooter(MemorySliceInput sliceInput) {
+ // read version and verify magic number
+ sliceInput.setPosition(ENCODED_LENGTH - 8);
+
+ int version = sliceInput.readInt();
+ int magicNumber = sliceInput.readInt();
+ checkArgument(
+ magicNumber == MAGIC_NUMBER, "File is not a btree index file (bad magic number)");
+
+ sliceInput.setPosition(0);
+
// read bloom filter and index handles
@Nullable
BloomFilterHandle bloomFilterHandle =
@@ -80,14 +105,7 @@ public class BTreeFileFooter {
nullBitmapHandle = null;
}
- // skip padding
- sliceInput.setPosition(ENCODED_LENGTH - 4);
-
- // verify magic number
- int magicNumber = sliceInput.readInt();
- checkArgument(magicNumber == MAGIC_NUMBER, "File is not a table (bad magic number)");
-
- return new BTreeFileFooter(bloomFilterHandle, indexBlockHandle, nullBitmapHandle);
+ return new BTreeFileFooter(version, bloomFilterHandle, indexBlockHandle, nullBitmapHandle);
}
public static MemorySlice writeFooter(BTreeFileFooter footer) {
@@ -119,7 +137,8 @@ public class BTreeFileFooter {
sliceOutput.writeInt(footer.nullBitmapHandle.size());
}
- // write magic number
+ // write version and magic number
+ sliceOutput.writeInt(footer.version);
sliceOutput.writeInt(MAGIC_NUMBER);
}
}
diff --git a/paimon-python/pypaimon/globalindex/btree/btree_file_footer.py b/paimon-python/pypaimon/globalindex/btree/btree_file_footer.py
index 7afa3694fd..f6056dcaa5 100644
--- a/paimon-python/pypaimon/globalindex/btree/btree_file_footer.py
+++ b/paimon-python/pypaimon/globalindex/btree/btree_file_footer.py
@@ -46,23 +46,27 @@ class BTreeFileFooter:
allowing efficient navigation of the B-tree index file.
"""
- MAGIC_NUMBER = 198732882
- ENCODED_LENGTH = 48
-
+ MAGIC_NUMBER = 0x50425449
+ CURRENT_VERSION = 1
+ ENCODED_LENGTH = 52
+
def __init__(
self,
bloom_filter_handle: Optional[BloomFilterHandle],
index_block_handle: BlockHandle,
- null_bitmap_handle: Optional[BlockHandle]
+ null_bitmap_handle: Optional[BlockHandle],
+ version: int = CURRENT_VERSION
):
"""
Initialize the BTree file footer.
-
+
Args:
bloom_filter_handle: Handle to the bloom filter block (maybe None)
index_block_handle: Handle to the index block
null_bitmap_handle: Handle to the null bitmap block (maybe None)
+ version: Footer version number
"""
+ self.version = version
self.bloom_filter_handle = bloom_filter_handle
self.index_block_handle = index_block_handle
self.null_bitmap_handle = null_bitmap_handle
@@ -81,6 +85,15 @@ class BTreeFileFooter:
Raises:
ValueError: If magic number doesn't match
"""
+ # Read version and verify magic number
+ offset = cls.ENCODED_LENGTH - 8
+
+ version = struct.unpack('<I', data[offset:offset + 4])[0]
+ offset += 4
+ magic_number = struct.unpack('<I', data[offset:offset + 4])[0]
+ if magic_number != cls.MAGIC_NUMBER:
+ raise ValueError("File is not a btree index file (bad magic number)")
+
offset = 0
# Read bloom filter handle
@@ -112,13 +125,5 @@ class BTreeFileFooter:
null_bitmap_handle = None
if not (nb_offset == 0 and nb_size == 0):
null_bitmap_handle = BlockHandle(nb_offset, nb_size)
-
- # Skip padding
- offset = cls.ENCODED_LENGTH - 4
-
- # Read and verify magic number
- magic_number = struct.unpack('<I', data[offset:offset + 4])[0]
- if magic_number != cls.MAGIC_NUMBER:
- raise ValueError("File is not a table (bad magic number)")
-
- return cls(bloom_filter_handle, index_block_handle, null_bitmap_handle)
+
+ return cls(bloom_filter_handle, index_block_handle, null_bitmap_handle, version)
diff --git a/paimon-python/pypaimon/globalindex/btree/btree_index_reader.py b/paimon-python/pypaimon/globalindex/btree/btree_index_reader.py
index 034e220108..65540f8c57 100644
--- a/paimon-python/pypaimon/globalindex/btree/btree_index_reader.py
+++ b/paimon-python/pypaimon/globalindex/btree/btree_index_reader.py
@@ -61,7 +61,7 @@ class BTreeIndexReader(GlobalIndexReader):
supporting various predicate operations like equality, range, and null checks.
"""
- FOOTER_ENCODED_LENGTH = 48
+ FOOTER_ENCODED_LENGTH = 52
def __init__(
self,