From dev-return-37859-apmail-drill-dev-archive=drill.apache.org@drill.apache.org Wed May 2 06:53:36 2018 Return-Path: X-Original-To: apmail-drill-dev-archive@www.apache.org Delivered-To: apmail-drill-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A0BEA18D4C for ; Wed, 2 May 2018 06:53:36 +0000 (UTC) Received: (qmail 65736 invoked by uid 500); 2 May 2018 06:53:35 -0000 Delivered-To: apmail-drill-dev-archive@drill.apache.org Received: (qmail 65377 invoked by uid 500); 2 May 2018 06:53:35 -0000 Mailing-List: contact dev-help@drill.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@drill.apache.org Delivered-To: mailing list dev@drill.apache.org Received: (qmail 64916 invoked by uid 99); 2 May 2018 06:53:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 May 2018 06:53:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6AC1FF5ECD; Wed, 2 May 2018 06:53:34 +0000 (UTC) From: sohami To: dev@drill.apache.org Reply-To: dev@drill.apache.org References: In-Reply-To: Subject: [GitHub] drill pull request #1241: DRILL-6364: Handle Cluster Info in WebUI when exis... Content-Type: text/plain Message-Id: <20180502065334.6AC1FF5ECD@git1-us-west.apache.org> Date: Wed, 2 May 2018 06:53:34 +0000 (UTC) Github user sohami commented on a diff in the pull request: https://github.com/apache/drill/pull/1241#discussion_r185403838 --- Diff: exec/java-exec/src/main/resources/rest/index.ftl --- @@ -252,37 +257,139 @@ timeout = setTimeout(reloadStatus, refreshTime); } - function fillStatus(data,size) { - var status_map = (data.responseJSON); - for (i = 1; i <= size; i++) { - var address = $("#row-"+i).find("#address").contents().get(0).nodeValue; - address = address.trim(); - var port = $("#row-"+i).find("#port").html(); - var key = address+"-"+port; + //Fill the Status table for all the listed drillbits + function fillStatus(dataResponse,size) { + let status_map = (dataResponse.responseJSON); + //In case localhost has gone down (i.e. we don't know status from ZK) + if (typeof status_map == 'undefined') { + let rxUpdateCount = 0; + let statusRespList = []; + //Query other nodes for state details + for (j = 1; j <= size; j++) { + let currentRow = $("#row-"+j); + if (currentRow.find("#current").html() == "Current") { + continue; //Skip LocalHost + } + let address = currentRow.find("#address").contents().get(0).nodeValue.trim(); + let restPort = currentRow.find("#httpPort").contents().get(0).nodeValue.trim(); + let altStateUrl = location.protocol + "//" + address+":"+restPort + "/state"; + let altResponse = $.getJSON(altStateUrl) + .done(function(stateDataJson) { + //Update Status & Buttons for alternate stateData + if (rxUpdateCount == 0) { --- End diff -- I am not an expert on javascript but little surprised to see how it's allowing reference of `rxUpdateCount` and `statusRespList` inside the callback function `done`, since these variables are defined local to `fillStatus` function. However there is still a race condition here, you cannot avoid it without a lock or a sync call. Please see [.when in jQuery](http://api.jquery.com/jQuery.when/) and this [stackoverflow](https://stackoverflow.com/questions/3709597/wait-until-all-jquery-ajax-requests-are-done) post for example. Also when the size of Drillbit in cluster is in hundreds then you will end up making that many requests which is an overkill, why not try say 3 Drillbits at max ? If you still get undefined then treat them as status is not available. ---