Repository navigation
Rebuild each account once when adding a batch of containers - #3324
Merged
mayur040993 merged 3 commits intoDec 3, 2026
Merged
mayur040993 merged 3 commits into
mayur040993 merged 3 commits into
Conversation
AccountInfoMap.addOrUpdateContainers rebuilt the parent Account once per container. Each rebuild copies and validates every container already in the account, so loading N containers into one account is O(N^2). On a full sync (service startup) with ~64k containers this took ~220 s on a single thread. Group the containers by parent account and rebuild each account once. A later update of the same container in the batch still wins. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3324 +/- ##
=============================================
- Coverage 64.24% 15.59% -48.65%
+ Complexity 10398 3256 -7142
=============================================
Files 840 941 +101
Lines 71755 81376 +9621
Branches 8611 9879 +1268
=============================================
- Hits 46099 12694 -33405
- Misses 23004 67716 +44712
+ Partials 2652 966 -1686 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Rebuild every affected account before publishing any of them, so a batch with an unknown parent account (or one that fails account validation) leaves the map unchanged instead of partially applied. Exercise migrationConfigs in the large-account test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
mayur040993
reviewed
Dec 3, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AccountInfoMap.addOrUpdateContainersrebuilt the parentAccountonce per container. Each rebuild copies the account's existing containers into anAccountBuilder, iterates them inbuild(), and re-validates them in theAccountconstructor. Adding N containers to one account was therefore O(N²).This matters on a full sync, which
CachedAccountServicedoes at every service start (lastModifiedTime = 0). In a LinkedIn frontend with 805 accounts and 64,186 containers, the MySQL fetch took ~1 s and the cache update took ~222 s on the main thread. That is about a third of the frontend's ~10 min startup.This change groups the containers by parent account and rebuilds each account once.
AccountBuilder.addOrUpdateContainerkeys by id andLinkedHashMapkeeps input order.IllegalArgumentExceptionand the map is unchanged. Before, the batch was partially applied up to the failing container.The only caller is
CachedAccountService.updateContainersInCache, which holds theinfoMapLockwrite lock.Testing Done
AccountInfoMapTest.testAddOrUpdateContainersLargeAccountadds 30,000 containers to one account with a 20 s timeout. It passes in ~0.04 s with this change and times out onmaster../gradlew :ambry-account:test --tests AccountInfoMapTest --tests MySqlAccountServiceTest: 32 tests pass.