Skip to content

[RatisConsensus] Cache group id in the write/read critical path#11615

Merged
OneSizeFitsQuorum merged 2 commits intoapache:masterfrom
SzyWilliam:cache_group_id
Nov 29, 2023
Merged

[RatisConsensus] Cache group id in the write/read critical path#11615
OneSizeFitsQuorum merged 2 commits intoapache:masterfrom
SzyWilliam:cache_group_id

Conversation

@SzyWilliam
Copy link
Member

We need to compute the consensus group id to raft group id mapping every time. This is cpu-consuming and we can avoid them simply by adding a weak-value cache.

private static final String SCHEMA_REGION_GROUP = "group-0002";
private static final CommonConfig config = CommonDescriptor.getInstance().getConfig();
private static final Cache<ConsensusGroupId, RaftGroupId> cache =
CacheBuilder.newBuilder().weakValues().build();
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the default expiration time of 5min? This will also work in the future with region migrations

Copy link
Member Author

Choose a reason for hiding this comment

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

Captain, oh my captain!

Copy link
Contributor

@OneSizeFitsQuorum OneSizeFitsQuorum left a comment

Choose a reason for hiding this comment

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

LGTM~
Thanks William for this detailed optimization

@OneSizeFitsQuorum OneSizeFitsQuorum merged commit bb20b5f into apache:master Nov 29, 2023
Sign up for free to 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.

2 participants