Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server: Introduce proxy state machine #9856

Merged
merged 24 commits into from
Feb 10, 2025
Merged

Conversation

CalvinNeo
Copy link
Member

@CalvinNeo CalvinNeo commented Feb 8, 2025

What problem does this PR solve?

Issue Number: close #9857 ref #9855

Problem Summary:

This is a trivial refinement of code to make proxy codes not so tangled with in Server::main.

This endeavor is to start TiFlash storage layer alone without Proxy and KVStore module, and make further cp easy.

We'd like to cp this PR into release-8.5 in order to keep compatible with cse TiFlash.

What is changed and how it works?


Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

Signed-off-by: Calvin Neo <[email protected]>
@ti-chi-bot ti-chi-bot bot added release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Feb 8, 2025
Signed-off-by: Calvin Neo <[email protected]>
@CalvinNeo
Copy link
Member Author

Signed-off-by: Calvin Neo <[email protected]>
Signed-off-by: Calvin Neo <[email protected]>
@CalvinNeo
Copy link
Member Author

/check-issue-triage

@CalvinNeo
Copy link
Member Author

/check-issue-triage-complete

CalvinNeo and others added 5 commits February 10, 2025 11:04
Signed-off-by: Calvin Neo <[email protected]>
Signed-off-by: Calvin Neo <[email protected]>
Signed-off-by: Calvin Neo <[email protected]>
@JaySon-Huang
Copy link
Contributor

And we can Move function getKeyManager to ProxyStateMachine to simplify the code in Server.cpp. Checkout this PR please CalvinNeo#14

Signed-off-by: Calvin Neo <[email protected]>
@CalvinNeo
Copy link
Member Author

CalvinNeo commented Feb 10, 2025

getKeyManager

And we can Move function getKeyManager to ProxyStateMachine to simplify the code in Server.cpp. Checkout this PR please CalvinNeo#14

It seems to me that the creation of the KeyManager is not strongly related to the proxy's lifetime. Here are the reasons:

  • The ProxyStateMachine is a state machine that manages the lifetime of Proxy and KVStore, so we can just call corresponding methods of this state machine when we want to bootstrap/restore/run/stop/destroy/join proxy. It is not a wrapper of ProxyHelper and KVStore's functionality.
  • KeyManager is neither part of Proxy nor KVStore. It just relies on checkEncryptionEnabled and ProxyHelper(The dependency of EngineStoreServerWrap is not necessary, could be addressed later). Both of these are the functionalities that proxy provides, rather than what proxy relies or what could affect how proxy would bootstrap or be destroyed.

So, instead, I think this could be extracted into a function like setOpenFileLimit. Or even more we can create a state machine for the storage layer if it is necessary. Neither cases IMO show enough importance that we should address in this PR, since these changes seem not necessary to be cherry-picked into release-8.5.

@JaySon-Huang
Copy link
Contributor

If Encryption-at-rest is enable, then DataKeyManager rely on the ProxyHelper lifetime to get the encryption key. So I think it should belong to ProxyStateMachine

@CalvinNeo
Copy link
Member Author

CalvinNeo commented Feb 10, 2025

If Encryption-at-rest is enable, then DataKeyManager rely on the ProxyHelper lifetime to get the encryption key. So I think it should belong to ProxyStateMachine

Yes it does, and so do TMTContext, KVStore and Context. The lifetime and functionality of Proxy can affect all these modules. Currently some modules related to each other in a complicated pattern.

So although the ProxyStateMachine is designed to manage the lifetime of Proxy, it is really Server::main that drives the state machine thus eventually controlling the lifetime of Proxy(/KVStore/TMTContext/...). In fact, it controls all lifetimes, like Context, TMTContext and so on. The ProxyStateMachine manages the lifetime of the Proxy, by exposing methods that should be correctly executed at different timepoints.

Moving this utilities into a ProxyStateMachine, so:

  • Server::main is responsible for calling those methods at the right time.
  • ProxyStateMachine is responsible for implementing those methods in a right way.

Signed-off-by: Calvin Neo <[email protected]>
is_proxy_runnable = tryParseFromConfig(config, disaggregated_mode, use_autoscaler, log);

args.push_back("TiFlash Proxy");
for (const auto & v : val_map)
Copy link
Contributor

@JinheLin JinheLin Feb 10, 2025

Choose a reason for hiding this comment

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

We use val_map to update args here, but val_map and args will be update simultaneously in addExtraArgs. It looks a bit chaotic.

Why need val_map in TiFlashProxyConfig?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh...args contains raw pointer to val_map.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think val_map is for ownership, and args is for view

Copy link
Contributor

@JinheLin JinheLin Feb 10, 2025

Choose a reason for hiding this comment

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

I have refined the code of args in this PR: CalvinNeo#15

Only maintain val_map and generate args by calling getArgs to avoid maintains val_map and args simultaneously.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it is clearer, thx. Merged.

Comment on lines 268 to 272
else
{
// Could be a auto-scaled compute node.
LOG_INFO(log, "KVStore is not initialized because no store_ident is provided");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove this branch. Now for non-disagg mode, the UniPS is not enabled so the store_ident is nullopt.

And for non-disagg mode, the StoreIdnet will be set by the FFI fn_set_store. Outputing this logging could be misleading.

Copy link
Member Author

Choose a reason for hiding this comment

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

removed

Copy link
Contributor

@JaySon-Huang JaySon-Huang left a comment

Choose a reason for hiding this comment

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

LGTM

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Feb 10, 2025
@CalvinNeo CalvinNeo requested a review from JinheLin February 10, 2025 09:35
@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Feb 10, 2025
Copy link
Contributor

ti-chi-bot bot commented Feb 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JaySon-Huang, JinheLin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JaySon-Huang,JinheLin]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Contributor

ti-chi-bot bot commented Feb 10, 2025

[LGTM Timeline notifier]

Timeline:

  • 2025-02-10 09:34:01.041150183 +0000 UTC m=+262683.437372230: ☑️ agreed by JaySon-Huang.
  • 2025-02-10 14:44:08.941860844 +0000 UTC m=+281291.338082905: ☑️ agreed by JinheLin.

@ti-chi-bot ti-chi-bot bot merged commit 0001db3 into pingcap:master Feb 10, 2025
5 checks passed
@CalvinNeo
Copy link
Member Author

/cherry-pick release-8.5

ti-chi-bot pushed a commit to ti-chi-bot/tiflash that referenced this pull request Feb 11, 2025
@ti-chi-bot
Copy link
Member

@CalvinNeo: new pull request created to branch release-8.5: #9861.
But this PR has conflicts, please resolve them!

In response to this:

/cherry-pick release-8.5

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the ti-community-infra/tichi repository.

JaySon-Huang pushed a commit to CalvinNeo/tiflash that referenced this pull request Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Server: refine Server(proxy state machine)
5 participants