Skip to content

branch-4.1: (fix)[fe] pick some fe memory improve prs - #61455

Merged
yiguolei merged 13 commits into
apache:branch-4.1from
mymeiyi:branch-4.1-pick
Mar 18, 2026
Merged

branch-4.1: (fix)[fe] pick some fe memory improve prs#61455
yiguolei merged 13 commits into
apache:branch-4.1from
mymeiyi:branch-4.1-pick

Conversation

@mymeiyi

@mymeiyimymeiyi commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

mymeiyi added 11 commits March 18, 2026 11:12
…t used in CloudTablet (apache#59327)
1. some fields are not used in cloud mode, but `CloudTablet` extends
`Tablet` and inherits these fields, which consumes too much memory
2. this pr add `LocalTablet` subclass to keep these fields which are
only used in local mode
3. this pr only move cooldown related fileds, more fileds will be moved
later
in a cloud cluster with one million tablets, the test results are as
follows:
||before|after||
|--------|--------|--------|--------|
|total memory of `CloudTablet`|<img width="1280" height="351" alt="1-1"
src="https://github.com/user-attachments/assets/b20cb1dd-da76-420d-8093-53891bbd5063"
/>|<img width="1280" height="358" alt="2-1"
src="https://github.com/user-attachments/assets/00791566-83b7-4605-b7ac-1e25d7274223"
/>| reduce 272.93 MB |
|memory of one `CloudTablet`|<img width="1386" height="762" alt="1-2"
src="https://github.com/user-attachments/assets/424a01eb-d276-463d-9a8d-ff3a9ed185b2"
/>|<img width="1396" height="692" alt="2-2"
src="https://github.com/user-attachments/assets/2bedff14-7bcc-42ab-bf7b-d5a8f993b8dd"
/>|reduce 272 B|
|fields of `CloudTablet`|<img width="1388" height="620" alt="1-3"
src="https://github.com/user-attachments/assets/cbc7fca3-5e39-4a44-b1c2-1e21d8328769"
/>|<img width="1388" height="512" alt="2-3"
src="https://github.com/user-attachments/assets/cfc094f9-46e1-4fc3-8f1d-37dad0d04a8a"
/>||
||old FE upgrade to new FE| new FE downgrade to old FE|
|--------|--------|--------|
|cloud mode| supported | supported|
|local mode| supported | unsupported (need modify code in old FE to
support it) |
None
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
apache/doris-website#1214 -->
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
…nsactionMgr when drop table (apache#59757)
### What problem does this PR solve?
1. `CloudGlobalTransactionMgr` does not remove `waitToCommitTxnCountMap`
if table is dropped.
2. simplify `lastTxnIdMap` and `txnLastSignatureMap`
### What problem does this PR solve?
for about 1340000 tablets in cloud mode, the fe memory is:
before:
<img width="1834" height="174" alt="image"
src="https://github.com/user-attachments/assets/f2392442-bb4c-4a85-b506-559400932b8e"
/>
after:
<img width="1842" height="312" alt="image"
src="https://github.com/user-attachments/assets/f3e1351f-3bc8-4994-89fb-8e423f77aff9"
/>
Issue Number: close #xxx
Related PR: #xxx
Problem Summary:
### Release note
None
### Check List (For Author)
- Test <!-- At least one of them must be included. -->
- [ ] Regression test
- [ ] Unit Test
- [ ] Manual test (add detailed scripts or steps below)
- [ ] No need to test or manual test. Explain why:
- [ ] This is a refactor/code format and no logic has been changed.
- [ ] Previous test can cover this change.
- [ ] No code files have been changed.
- [ ] Other reason <!-- Add your reason? -->
- Behavior changed:
- [ ] No.
- [ ] Yes. <!-- Explain the behavior change -->
- Does this need documentation?
- [ ] No.
- [ ] Yes. <!-- Add document PR link here. eg:
apache/doris-website#1214 -->
### Check List (For Reviewer who merge this PR)
- [ ] Confirm the release note
- [ ] Confirm test cases
- [ ] Confirm document
- [ ] Add branch pick label <!-- Add branch pick label that this PR
should merge into -->
@mymeiyi
mymeiyi requested a review from yiguolei as a code ownerMarch 18, 2026 03:39
CopilotAI review requested due to automatic review settings March 18, 2026 03:39
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@mymeiyi

Copy link
Copy Markdown
ContributorAuthor

run buildall

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This branch-pick aggregates several upstream FE changes primarily aimed at reducing memory usage in cloud mode by splitting “local” vs “cloud” metadata representations and switching to more memory-efficient primitive collections.

Changes:

  • Introduce LocalTablet/LocalReplica and refactor Tablet/Replica into abstract bases with mode-specific implementations.
  • Split TabletInvertedIndex into LocalTabletInvertedIndex and CloudTabletInvertedIndex, and wire selection via EnvFactory / CloudEnvFactory.
  • Add fastutil-core and adopt fastutil primitive maps in hot metadata structures; adjust cloud table stats storage and related metric export.

Reviewed changes

Copilot reviewed 51 out of 52 changed files in this pull request and generated 4 comments.

Show a summary per file
FileDescription
fe/pom.xmlAdds fastutil.version and manages fastutil-core dependency.
fe/fe-core/pom.xmlAdds fastutil-core as a module dependency.
dist/LICENSE-dist.txtUpdates fastutil entry (needs alignment with actual artifact).
fe/fe-core/src/main/java/org/apache/doris/persist/gson/GsonUtils.javaUpdates Gson runtime subtype adapters for Tablet/Replica local vs cloud classes and compatibility.
fe/fe-core/src/main/java/org/apache/doris/metric/PrometheusMetricVisitor.javaSwitches cloud table stats iteration to new getCloudTableStats() API.
fe/fe-core/src/main/java/org/apache/doris/master/ReportHandler.javaUses LocalReplica when creating replicas from BE reports (local mode).
fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.javaUses LocalReplica for local catalog tablet/replica creation paths; updates cloud drop-table hook.
fe/fe-core/src/main/java/org/apache/doris/consistency/ConsistencyChecker.javaRefactors tablet selection queue typing; adds tablet comparator.
fe/fe-core/src/main/java/org/apache/doris/common/proc/TabletsProcDir.javaProc output switches cooldown replica id accessor.
fe/fe-core/src/main/java/org/apache/doris/common/proc/ReplicasProcNode.javaProc output switches cooldown replica id accessor.
fe/fe-core/src/main/java/org/apache/doris/cloud/transaction/CloudGlobalTransactionMgr.javaSimplifies tracking maps; adds afterDropTable() cleanup hook.
fe/fe-core/src/main/java/org/apache/doris/cloud/datasource/CloudInternalCatalog.javaAvoids getReplicas() in cloud tablet paths by using CloudTablet.getCloudReplica().
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletRebalancer.javaAvoids getReplicas() in cloud balancing paths by using CloudTablet.getCloudReplica().
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTabletInvertedIndex.javaNew cloud-specific inverted index using fastutil map and single-replica assumption.
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudTablet.javaRefactors cloud tablet to store a single replica (with backward-compatible replicas field).
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudReplica.javaRefactors primary BE mapping and adds in-memory segment/rowset counters.
fe/fe-core/src/main/java/org/apache/doris/cloud/catalog/CloudEnvFactory.javaCreates CloudTabletInvertedIndex via factory override.
fe/fe-core/src/main/java/org/apache/doris/clone/TabletSchedCtx.javaUses LocalReplica for clone replica creation (local mode).
fe/fe-core/src/main/java/org/apache/doris/catalog/TabletStatMgr.javaSwitches wrapper Long counters to primitive long for less overhead.
fe/fe-core/src/main/java/org/apache/doris/catalog/TabletInvertedIndex.javaMakes base class abstract; moves local implementation out; uses fastutil for tablet meta map.
fe/fe-core/src/main/java/org/apache/doris/catalog/Tablet.javaMakes base class abstract; moves local-only fields/behaviors to LocalTablet.
fe/fe-core/src/main/java/org/apache/doris/catalog/Replica.javaMakes base class abstract; moves local-only fields/behaviors to LocalReplica.
fe/fe-core/src/main/java/org/apache/doris/catalog/OlapTable.javaUses LocalReplica where applicable; converts Statistics fields/ctor to primitive long.
fe/fe-core/src/main/java/org/apache/doris/catalog/LocalTabletInvertedIndex.javaNew local inverted index implementation (includes async tablet report processing).
fe/fe-core/src/main/java/org/apache/doris/catalog/LocalTablet.javaNew local tablet implementation containing replicas/cooldown/health timing state.
fe/fe-core/src/main/java/org/apache/doris/catalog/LocalReplica.javaNew local replica implementation containing backend id, version tracking, cooldown, etc.
fe/fe-core/src/main/java/org/apache/doris/catalog/EnvFactory.javaCentralizes creation of tablets/replicas/inverted index for local mode.
fe/fe-core/src/main/java/org/apache/doris/catalog/Env.javaUses EnvFactory.createTabletInvertedIndex() for initialization.
fe/fe-core/src/main/java/org/apache/doris/catalog/CloudTabletStatMgr.javaRefactors stat collection flow and stores per-table stats in a list for lower overhead.
fe/fe-core/src/main/java/org/apache/doris/backup/RestoreJob.javaUses LocalReplica for restore reset paths (local mode).
fe/fe-core/src/test/java/org/apache/doris/statistics/OlapAnalysisTaskTest.javaUpdates mocks to use LocalTablet.
fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/CreateTableCommandTest.javaRemoves tablet meta table assertions and unused imports.
fe/fe-core/src/test/java/org/apache/doris/http/DorisHttpTestCase.javaUpdates test fixtures to use LocalTablet/LocalReplica/LocalTabletInvertedIndex.
fe/fe-core/src/test/java/org/apache/doris/cooldown/CooldownConfHandlerTest.javaUses LocalTablet and casts retrieved tablet accordingly.
fe/fe-core/src/test/java/org/apache/doris/common/util/UnitTestUtil.javaUses LocalTablet/LocalReplica in helper table creation.
fe/fe-core/src/test/java/org/apache/doris/cluster/SystemInfoServiceTest.javaUses LocalTabletInvertedIndex in setup.
fe/fe-core/src/test/java/org/apache/doris/cluster/DecommissionBackendTest.javaUses LocalReplica for fake replica creation.
fe/fe-core/src/test/java/org/apache/doris/cloud/cache/CacheHotspotManagerTest.javaUses CloudTablet for cloud-mode tablet fixture.
fe/fe-core/src/test/java/org/apache/doris/clone/TabletSchedCtxTest.javaUses LocalReplica in comparator test.
fe/fe-core/src/test/java/org/apache/doris/clone/TabletReplicaTooSlowTest.javaUses LocalTabletInvertedIndex.
fe/fe-core/src/test/java/org/apache/doris/clone/TabletHealthTest.javaUses LocalReplica when adding a replica in tests.
fe/fe-core/src/test/java/org/apache/doris/clone/RebalancerTestUtil.javaUses LocalTablet/LocalReplica in rebalancer test utilities.
fe/fe-core/src/test/java/org/apache/doris/clone/RebalanceTest.javaUses LocalTabletInvertedIndex.
fe/fe-core/src/test/java/org/apache/doris/clone/DiskRebalanceTest.javaUses LocalTabletInvertedIndex.
fe/fe-core/src/test/java/org/apache/doris/clone/DecommissionTest.javaUses LocalTabletInvertedIndex.
fe/fe-core/src/test/java/org/apache/doris/clone/ClusterLoadStatisticsTest.javaUses LocalTabletInvertedIndex and LocalReplica fixtures.
fe/fe-core/src/test/java/org/apache/doris/catalog/TabletTest.javaUses LocalTabletInvertedIndex, LocalTablet, and LocalReplica; removes clearReplica() assertion.
fe/fe-core/src/test/java/org/apache/doris/catalog/ReplicaTest.javaUses LocalReplica in serialization/version tests.
fe/fe-core/src/test/java/org/apache/doris/catalog/CreateTableTest.javaRemoves tablet meta table assertions and unused imports.
fe/fe-core/src/test/java/org/apache/doris/catalog/CatalogTestUtil.javaUses LocalTablet/LocalReplica for non-cloud test DB creation.
fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.javaUses LocalTablet/LocalReplica in backup/restore mocks.
fe/fe-core/src/test/java/org/apache/doris/backup/BackupHandlerTest.javaUses LocalTabletInvertedIndex in test setup.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines 58 to +60
(first, second) -> Long.signum(first.getLastCheckTime() - second.getLastCheckTime());
private static final Comparator<Tablet> TABLET_COMPARATOR =
(first, second) -> Long.signum(first.getLastCheckTime() - second.getLastCheckTime());
Comment on lines +186 to +206
CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
for (int j = start; j < end; j++) {
Map.Entry<Long, Replica> entry = entries.get(j);
processTabletEntry(backendId, backendTablets, storageMediumMap, tabletSyncMap,
tabletDeleteFromMeta, tabletFoundInMeta, tabletMigrationMap,
transactionsToPublish, transactionsToClear, tabletRecoveryMap,
tabletToUpdate, cooldownTablets, entry);
}
}, taskPool);

tabletFutures.add(future);
}

// Process partition versions in parallel
CompletableFuture<Void> partitionFuture = CompletableFuture.runAsync(() -> {
processPartitionVersions(backendPartitionsVersion, partitionVersionSyncMap);
}, taskPool);

// Wait for all tasks to complete
CompletableFuture.allOf(tabletFutures.toArray(new CompletableFuture[0])).join();
partitionFuture.join();
}
}
// return replica with max remoteDataSize
return replicas.stream().max(Comparator.comparing(Replica::getRemoteDataSize)).get().getRemoteDataSize();
Comment on lines +472 to +476
if (memClusterToBackends == null) {
synchronized (this) {
if (memClusterToBackends == null) {
memClusterToBackends = new ConcurrentHashMap<>();
}
@mymeiyimymeiyi changed the title branch-4.1: pick some fe memory improves prsbranch-4.1: (fix)[fe] pick some fe memory improves prsMar 18, 2026
@mymeiyimymeiyi changed the title branch-4.1: (fix)[fe] pick some fe memory improves prsbranch-4.1: (fix)[fe] pick some fe memory improve prsMar 18, 2026
@mymeiyi

Copy link
Copy Markdown
ContributorAuthor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

FE UT Coverage Report

Increment line coverage 52.13% (623/1195) 🎉
Increment coverage report
Complete coverage report

@mymeiyi

Copy link
Copy Markdown
ContributorAuthor

run cloud_p0

@yiguolei
yiguolei merged commit f7a4908 into apache:branch-4.1Mar 18, 2026
25 of 31 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@mymeiyi@hello-stephen@yiguolei@deardeng