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

[FLINK-14672][sql-client] Make Executor stateful in sql client #10270

Closed
wants to merge 4 commits into from

Conversation

openinx
Copy link
Member

@openinx openinx commented Nov 20, 2019

What is the purpose of the change

Now we only have the embedded mode SQL to interact with Flink cluster, will support the multi-statement and DDL such create table, which means we need to store some state for the same session. On the other hande, it will support the gateway mode in future, means it will maitain multi-sessions at the server side.

So it's necessary to be stateful for the Executor (both LocalExecutor and GatewayExecutor).

The pull request provide two extra API in Executor interface to manage session life-cycle:

  1. String openSession(SessionContext context); it will create a new session based on the passed session context, the session will have the ExecutionContext/TableEnviroment/UDF informations (etc). and the openSession will return a uuid string which represent the session identification, the following operations of this session will attach the sessionId to request the Executor (both local and gateway).
  2. String closeSession(String sessionId); it will close the session(clear the session related resources) with given session identify.

For each session, we will openSesion firstly, then execute some DDL or DML, and closeSession finally. When executing the DDL or DML, it will share the same session context and execution context for the same session identifier.

Brief change log

  • 4b5c6f4 [FLINK-14672][sql-client] Make Executor stateful in sql client
  • e60ea8b [FLINK-14672][sql-client] Simplify the executor backend state for each session: The SessionContext is only used for frontend user to open session, all the backend informations are maintained in ExecutionContext.

Verifying this change

The LocalExecutorITCase addressed all the cases.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (no)
  • The serializers: (no)
  • The runtime per-record code paths (performance sensitive): (no)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)
  • The S3 file system connector: (no)

Documentation

  • Does this pull request introduce a new feature? (no)
  • If yes, how is the feature documented? (not documented)

@openinx
Copy link
Member Author

openinx commented Nov 20, 2019

FYI @twalthr @KurtYoung , please help the reviewing if have time. Thanks.

@flinkbot
Copy link
Collaborator

flinkbot commented Nov 20, 2019

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit e2f6d55 (Wed Dec 04 15:13:32 UTC 2019)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

Please see the Pull Request Review Guide for a full explanation of the review process.


The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@flinkbot
Copy link
Collaborator

flinkbot commented Nov 20, 2019

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run travis re-run the last Travis build

Copy link
Contributor

@KurtYoung KurtYoung left a comment

Choose a reason for hiding this comment

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

Thanks @openinx for working on this, the design looks good to me, I left some comments about code style.

private Executor executor;

public ExecutionContext(
Environment environment,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: indent 2 tabs here.
You might need to change your idea setting: Editor -> Code Stype -> Java -> Continuation Indent 8

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've set the checksytle in my ide, seems the Selection-format makes the indent happen again. Let me check.

Configuration flinkConfig,
Options commandLineOptions,
List<CustomCommandLine> availableCommandLines) throws FlinkException {
this(environment,
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: If you are already wrapping lines for parameter, also wrap the first parameter

Copy link
Member Author

Choose a reason for hiding this comment

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

OK.

Configuration flinkConfig,
CustomCommandLine commandLine,
ClusterClientServiceLoader clusterClientServiceLoader
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: align with other code format

Copy link
Member Author

Choose a reason for hiding this comment

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

OK

String sessionId = sessionContext.getSessionId();
ExecutionContext previousContext = this.contextMap.putIfAbsent(sessionId, createExecutionContext(sessionContext));
if (previousContext != null) {
throw new SqlExecutionException("Found another session with the same session identifier: " + sessionContext.getSessionId());
Copy link
Contributor

Choose a reason for hiding this comment

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

sessionContext.getSessionId() -> sessionId

Copy link
Member Author

Choose a reason for hiding this comment

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

OK

if (previousContext != null) {
throw new SqlExecutionException("Found another session with the same session identifier: " + sessionContext.getSessionId());
}
return sessionContext.getSessionId();
Copy link
Contributor

Choose a reason for hiding this comment

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

sessionContext.getSessionId() -> sessionId

Copy link
Member Author

Choose a reason for hiding this comment

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

OK.

final ExecutionContext<?> context = getOrCreateExecutionContext(session);
public void resetSessionProperties(String sessionId) throws SqlExecutionException {
// Renew the ExecutionContext by using the default environment.
this.contextMap.put(sessionId, createExecutionContext(defaultEnvironment));
Copy link
Contributor

Choose a reason for hiding this comment

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

reset session property should keep the content which read from session environment file? Now it looks we also git rid of this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I noticed here. I planed to not saving the session environment file in ExecutionContext before, so here seems no method to reset back to the session env. Let me re-think about the design , maybe we still need the session env..

Environment env = getExecutionContext(sessionId).getEnvironment();
Environment newEnv = Environment.enrich(env, ImmutableMap.of(key, value), ImmutableMap.of());
// Renew the ExecutionContext by merging the default environment and new environment.
this.contextMap.put(sessionId, createExecutionContext(defaultEnvironment, newEnv));
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 directly call createExecutionContext(newEnv) here, defaultEnvironment should be already covered by the env you got from current execution context

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, thanks for pointing it out.

ImmutableMap.of(),
ImmutableMap.of(name, ViewEntry.create(name, query)));
// Renew the ExecutionContext.
this.contextMap.put(sessionId, createExecutionContext(defaultEnvironment, newEnv));
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Member Author

Choose a reason for hiding this comment

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

Will also change this.

public TypedResult<List<Tuple2<Boolean, Row>>> retrieveResultChanges(
String sessionId,
String resultId
) throws SqlExecutionException {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: format

Copy link
Member Author

Choose a reason for hiding this comment

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

OK.

@tisonkun
Copy link
Member

tisonkun commented Nov 22, 2019

I think @aljoscha also works on this field. It is better to align works before merge one or the other.

@openinx
Copy link
Member Author

openinx commented Nov 22, 2019

Sync with @aljoscha on wednesday, he should know the issue I working. Of course, feel free to feedback if anything I missed, FYI @tisonkun , @aljoscha , Thanks.

@openinx openinx force-pushed the FLINK-14672 branch 2 times, most recently from 7be55c9 to 520c528 Compare November 22, 2019 13:38
Copy link
Contributor

@KurtYoung KurtYoung left a comment

Choose a reason for hiding this comment

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

LGTM, @twalthr do you want take a look?

@@ -63,7 +63,7 @@ public ResultStore(Configuration flinkConfig) {

if (env.getExecution().inStreamingMode()) {
// determine gateway address (and port if possible)
final InetAddress gatewayAddress = getGatewayAddress(env.getDeployment());
InetAddress gatewayAddress = getGatewayAddress(env.getDeployment());
Copy link
Contributor

Choose a reason for hiding this comment

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

why deleting final?

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 it's unintentional change, will revert it.

@twalthr
Copy link
Contributor

twalthr commented Nov 25, 2019

Thanks for pinging me @KurtYoung. I would like to take a look.

…h session: The SessionContext is only used for frontend user to open session, all the backend informations are maintained in ExecutionContext.
@KurtYoung
Copy link
Contributor

@twalthr do you have any comments on this? I will merge this if you don't mind.

Copy link
Member

@tisonkun tisonkun left a comment

Choose a reason for hiding this comment

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

A quick question: shall we introduce a type SessionID as wrapper of String instead of just using String? We can gain type safety & expressive code then.

@KurtYoung
Copy link
Contributor

A quick question: shall we introduce a type SessionID as wrapper of String instead of just using String? We can gain type safety & expressive code then.

We could revisit this when necessary, currently I don't see any strong reason to make it a Class instead of a String

@openinx
Copy link
Member Author

openinx commented Dec 2, 2019

bq. We could revisit this when necessary, currently I don't see any strong reason to make it a Class instead of a String
+1.

@KurtYoung
Copy link
Contributor

merging this now

@KurtYoung KurtYoung closed this in c4acb6f Dec 3, 2019
Li-Aihua pushed a commit to Li-Aihua/flink that referenced this pull request Jan 19, 2020
Simplify the executor backend state for each session: The SessionContext is only used for frontend user to open session, all the backend informations are maintained in ExecutionContext.

This closes apache#10270
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants