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-10748] Decouple RestServerEndpoint from Dispatcher #7295

Merged
merged 2 commits into from
Dec 20, 2018

Conversation

tillrohrmann
Copy link
Contributor

What is the purpose of the change

This commits decouples the RestServerEndpoint from the Dispatcher by converting the
RedirectHandler into LeaderRetrievalHandler which only retrieves the gateway of the
current leader instead of redirecting the client. This is possible since the serving
RestServerEndpoint no longer needs to be colocated with the Dispatcher and JobMaster
after all RPC requests are serializable (e.g. no direct access on the ExecutionGraph
is needed).

With this change every RestServerEndpoint will automatically proxy to the current leader
without needing to redirect the requesting client.

Brief change log

  • Remove redirection logic from RedirectHandler
  • Rename RedirectHandler into LeaderRetrievalHandler
  • Remove restAddressFuture from all REST handlers except for the JarListHandler

Verifying this change

  • Tested manually
  • Adapted former RedirectHandlerTest which is now called LeaderRetrievalHandlerTest

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 applicable)

This commits decouples the RestServerEndpoint from the Dispatcher by converting the
RedirectHandler into LeaderRetrievalHandler which only retrieves the gateway of the
current leader instead of redirecting the client. This is possible since the serving
RestServerEndpoint no longer needs to be colocated with the Dispatcher and JobMaster
after all RPC requests are serializable (e.g. no direct access on the ExecutionGraph
is needed).

With this change every RestServerEndpoint will automatically proxy to the current leader
without needing to redirect the requesting client.
@tillrohrmann tillrohrmann requested a review from zentol December 12, 2018 16:20
@zentol zentol self-assigned this Dec 12, 2018
public static HttpResponse getRedirectResponse(String redirectAddress, String path) {
return getRedirectResponse(redirectAddress, path, HttpResponseStatus.TEMPORARY_REDIRECT);
}

public static HttpResponse getRedirectResponse(String redirectAddress, String path, HttpResponseStatus code) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I supposed the remaining ones are used for the SSL redirection?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly.

try {
respondAsLeader(channelHandlerContext, routedRequest, gateway);
} catch (Exception e) {
logger.error("Error while responding as leader.", e);
Copy link
Contributor

Choose a reason for hiding this comment

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

this isn't quite correct is it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you suggest to log a different error message? This is the same message as it was before. We could change it to Error occurred while processing http request.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd prefer that. It's a bit....well we just aren't really the leader (in a way this concept no longer exists on the REST handler level), so it seems a bid misleading.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, will change it.

Assert.assertEquals(expectedRedirection, response.getLocation());

// 4. with local REST endpoint
// 2. with leader
Copy link
Contributor

Choose a reason for hiding this comment

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

help me out here, why is the leader now suddenly available?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

with the removal of the redirection logic, there are only two cases:

  1. Leader could not be retrieved yet
  2. Leader has been retrieved

These two cases are tested.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh i get that, but this test only executes

httpClient.sendGetRequest(restPath, FutureUtils.toFiniteDuration(timeout));

HttpTestClient.SimpleHttpResponse response = httpClient.getNextResponse(FutureUtils.toFiniteDuration(timeout));

twice, with each getting a different response. What causes the response to be different? I don't see any modifications being made to the state of the rest server / futures between the 2 requests. This isn't just a timing thing, is it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it is the setup of the test with the gatewayRetriever mock in line 73. First we return an empty Optional and then an Optional.of(gateway).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually removed the mocking completely. This should make things a bit clearer.

Copy link
Contributor

@zentol zentol left a comment

Choose a reason for hiding this comment

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

+1

@tillrohrmann
Copy link
Contributor Author

Thanks for the review @zentol. Merging this PR.

@tillrohrmann tillrohrmann merged commit bab9699 into apache:master Dec 20, 2018
tisonkun pushed a commit to tisonkun/flink that referenced this pull request Jan 17, 2019
This commits decouples the RestServerEndpoint from the Dispatcher by converting the
RedirectHandler into LeaderRetrievalHandler which only retrieves the gateway of the
current leader instead of redirecting the client. This is possible since the serving
RestServerEndpoint no longer needs to be colocated with the Dispatcher and JobMaster
after all RPC requests are serializable (e.g. no direct access on the ExecutionGraph
is needed).

With this change every RestServerEndpoint will automatically proxy to the current leader
without needing to redirect the requesting client.
@tillrohrmann tillrohrmann deleted the removeRedirectHandler branch June 6, 2019 14:40
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.

3 participants