This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new aa3dcd83fe6 [HUDI-9571] Avoid scanning timeline to fetch
InternalSchema for schema evolution (#13525)
aa3dcd83fe6 is described below
commit aa3dcd83fe660daff4d061be7459ddf02d038696
Author: Shuo Cheng <[email protected]>
AuthorDate: Wed Jul 9 16:21:47 2025 +0800
[HUDI-9571] Avoid scanning timeline to fetch InternalSchema for schema
evolution (#13525)
---
.../hudi/common/util/InternalSchemaCache.java | 24 +++-------------------
1 file changed, 3 insertions(+), 21 deletions(-)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/common/util/InternalSchemaCache.java
b/hudi-common/src/main/java/org/apache/hudi/common/util/InternalSchemaCache.java
index 4ac5b65a96f..b62f7742b5a 100644
---
a/hudi-common/src/main/java/org/apache/hudi/common/util/InternalSchemaCache.java
+++
b/hudi-common/src/main/java/org/apache/hudi/common/util/InternalSchemaCache.java
@@ -79,18 +79,15 @@ public class InternalSchemaCache {
/**
* Search internalSchema based on versionID.
- * first step: try to get internalSchema from hoodie commit files, we no
need to add lock.
- * if we cannot get internalSchema by first step, then we try to get
internalSchema from cache.
+ *
+ * <p>The internalSchema is fetched from cache or history schema file
directly, and should not
+ * be fetched from commit meta file since the overhead of scanning timeline
is higher.
*
* @param versionID schema version_id need to search
* @param metaClient current hoodie metaClient
* @return internalSchema
*/
public static InternalSchema searchSchemaAndCache(long versionID,
HoodieTableMetaClient metaClient) {
- Option<InternalSchema> candidateSchema =
getSchemaByReadingCommitFile(versionID, metaClient);
- if (candidateSchema.isPresent()) {
- return candidateSchema.get();
- }
String tablePath = metaClient.getBasePath().toString();
// use segment lock to reduce competition.
synchronized (LOCK_LIST[tablePath.hashCode() & (LOCK_LIST.length - 1)]) {
@@ -119,21 +116,6 @@ public class InternalSchemaCache {
return result;
}
- private static Option<InternalSchema> getSchemaByReadingCommitFile(long
versionID, HoodieTableMetaClient metaClient) {
- try {
- HoodieTimeline timeline =
metaClient.getActiveTimeline().getCommitsTimeline().filterCompletedInstants();
- List<HoodieInstant> instants = timeline.getInstantsAsStream().filter(f
->
f.requestedTime().equals(String.valueOf(versionID))).collect(Collectors.toList());
- if (instants.isEmpty()) {
- return Option.empty();
- }
- HoodieCommitMetadata metadata =
timeline.readCommitMetadata(instants.get(0));
- String latestInternalSchemaStr =
metadata.getMetadata(SerDeHelper.LATEST_SCHEMA);
- return SerDeHelper.fromJson(latestInternalSchemaStr);
- } catch (Exception e) {
- throw new HoodieException("Failed to read schema from commit metadata",
e);
- }
- }
-
/**
* Get internalSchema and avroSchema for compaction/cluster operation.
*