Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4A518200BBD for ; Mon, 24 Oct 2016 15:41:00 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 490CE160AE1; Mon, 24 Oct 2016 13:41:00 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 67836160AEB for ; Mon, 24 Oct 2016 15:40:59 +0200 (CEST) Received: (qmail 14387 invoked by uid 500); 24 Oct 2016 13:40:58 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 14353 invoked by uid 99); 24 Oct 2016 13:40:58 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 24 Oct 2016 13:40:58 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 728882C0D55 for ; Mon, 24 Oct 2016 13:40:58 +0000 (UTC) Date: Mon, 24 Oct 2016 13:40:58 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-4853) Clean up JobManager registration at the ResourceManager MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 24 Oct 2016 13:41:00 -0000 [ https://issues.apache.org/jira/browse/FLINK-4853?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15602007#comment-15602007 ] ASF GitHub Bot commented on FLINK-4853: --------------------------------------- Github user mxm commented on a diff in the pull request: https://github.com/apache/flink/pull/2657#discussion_r84689078 --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/resourcemanager/ResourceManager.java --- @@ -202,101 +205,125 @@ public void shutDown() throws Exception { // RPC methods // ------------------------------------------------------------------------ - /** - * Register a {@link JobMaster} at the resource manager. - * - * @param resourceManagerLeaderId The fencing token for the ResourceManager leader - * @param jobMasterAddress The address of the JobMaster that registers - * @param jobID The Job ID of the JobMaster that registers - * @return Future registration response - */ @RpcMethod - public Future registerJobMaster( - final UUID resourceManagerLeaderId, final UUID jobMasterLeaderId, - final String jobMasterAddress, final JobID jobID) { + public Future registerJobManager( + final UUID resourceManagerLeaderId, + final UUID jobManagerLeaderId, + final String jobManagerAddress, + final JobID jobId) { + + checkNotNull(resourceManagerLeaderId); + checkNotNull(jobManagerLeaderId); + checkNotNull(jobManagerAddress); + checkNotNull(jobId); + + if (isValid(resourceManagerLeaderId)) { + if (!jobLeaderIdService.containsJob(jobId)) { + try { + jobLeaderIdService.addJob(jobId); + } catch (Exception e) { + // This should actually never happen because, it should always be possible to add a new job + ResourceManagerException exception = new ResourceManagerException("Could not add the job " + + jobId + " to the job id leader service. This should never happen.", e); + + onFatalErrorAsync(exception); + + log.debug("Could not add job {} to job leader id service.", jobId, e); + return FlinkCompletableFuture.completedExceptionally(exception); + } + } - checkNotNull(jobMasterAddress); - checkNotNull(jobID); + log.info("Registering job manager {}@{} for job {}.", jobManagerLeaderId, jobManagerAddress, jobId); + + Future jobLeaderIdFuture; - // create a leader retriever in case it doesn't exist - final JobIdLeaderListener jobIdLeaderListener; - if (leaderListeners.containsKey(jobID)) { - jobIdLeaderListener = leaderListeners.get(jobID); - } else { try { - LeaderRetrievalService jobMasterLeaderRetriever = - highAvailabilityServices.getJobManagerLeaderRetriever(jobID); - jobIdLeaderListener = new JobIdLeaderListener(jobID, jobMasterLeaderRetriever); + jobLeaderIdFuture = jobLeaderIdService.getLeaderId(jobId); } catch (Exception e) { - log.warn("Failed to start JobMasterLeaderRetriever for job id {}", jobID, e); + // we cannot check the job leader id so let's fail + // TODO: Maybe it's also ok to skip this check in case that we cannot check the leader id + ResourceManagerException exception = new ResourceManagerException("Cannot obtain the " + + "job leader id future to verify the correct job leader.", e); + + onFatalErrorAsync(exception); - return FlinkCompletableFuture.completed( - new RegistrationResponse.Decline("Failed to retrieve JobMasterLeaderRetriever")); + log.debug("Could not obtain the job leader id future to verify the correct job leader."); + return FlinkCompletableFuture.completedExceptionally(exception); } - leaderListeners.put(jobID, jobIdLeaderListener); - } + Future jobMasterGatewayFuture = getRpcService().connect(jobManagerAddress, JobMasterGateway.class); - return getRpcService() - .execute(new Callable() { + Future registrationResponseFuture = jobMasterGatewayFuture.thenCombineAsync(jobLeaderIdFuture, new BiFunction() { @Override - public JobMasterGateway call() throws Exception { + public RegistrationResponse apply(JobMasterGateway jobMasterGateway, UUID jobLeaderId) { + if (isValid(resourceManagerLeaderId)) { + if (jobLeaderId.equals(jobManagerLeaderId)) { + if (jobManagerRegistrations.containsKey(jobId)) { + JobManagerRegistration oldJobManagerRegistration = jobManagerRegistrations.get(jobId); + + if (oldJobManagerRegistration.getLeaderID().equals(jobLeaderId)) { + // same registration + log.debug("Job manager {}@{} was already registered.", jobManagerLeaderId, jobManagerAddress); + } else { + // tell old job manager that he is no longer the job leader + disconnectJobManager( + oldJobManagerRegistration.getJobID(), + new Exception("New job leader for job " + jobId + " found.")); --- End diff -- I see. That seems like the only way to resolve the leader id in a non-blocking fashion while ensuring eventually correct registration. > Clean up JobManager registration at the ResourceManager > ------------------------------------------------------- > > Key: FLINK-4853 > URL: https://issues.apache.org/jira/browse/FLINK-4853 > Project: Flink > Issue Type: Sub-task > Components: ResourceManager > Reporter: Till Rohrmann > Assignee: Till Rohrmann > > The current {{JobManager}} registration at the {{ResourceManager}} blocks threads in the {{RpcService.execute}} pool. This is not ideal and can be avoided by not waiting on a {{Future}} in this call. > I propose to encapsulate the leader id retrieval operation in a distinct service so that it can be separated from the {{ResourceManager}}. This will reduce the complexity of the {{ResourceManager}} and make the individual components easier to test. -- This message was sent by Atlassian JIRA (v6.3.4#6332)