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 58D05200B59 for ; Mon, 8 Aug 2016 09:06:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 5783D160A91; Mon, 8 Aug 2016 07:06:57 +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 9BC43160A8F for ; Mon, 8 Aug 2016 09:06:56 +0200 (CEST) Received: (qmail 1857 invoked by uid 500); 8 Aug 2016 07:06:55 -0000 Mailing-List: contact dev-help@apex.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@apex.apache.org Delivered-To: mailing list dev@apex.apache.org Received: (qmail 1842 invoked by uid 99); 8 Aug 2016 07:06:55 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2016 07:06:55 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 287C1C7B27 for ; Mon, 8 Aug 2016 07:06:55 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.474 X-Spam-Level: X-Spam-Status: No, score=-4.474 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.454] autolearn=disabled Received: from mx2-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id vjZOY9B3FCQa for ; Mon, 8 Aug 2016 07:06:53 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-us.apache.org (ASF Mail Server at mx2-lw-us.apache.org) with SMTP id 0CB495FAFB for ; Mon, 8 Aug 2016 07:06:52 +0000 (UTC) Received: (qmail 1834 invoked by uid 99); 8 Aug 2016 07:06:52 -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; Mon, 08 Aug 2016 07:06:52 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 474B1EE68D; Mon, 8 Aug 2016 07:06:52 +0000 (UTC) From: bhupeshchawda To: dev@apex.incubator.apache.org Reply-To: dev@apex.incubator.apache.org References: In-Reply-To: Subject: [GitHub] apex-malhar pull request #358: [review only]APEXMALHAR-2172: Updates to JDBC... Content-Type: text/plain Message-Id: <20160808070652.474B1EE68D@git1-us-west.apache.org> Date: Mon, 8 Aug 2016 07:06:52 +0000 (UTC) archived-at: Mon, 08 Aug 2016 07:06:57 -0000 Github user bhupeshchawda commented on a diff in the pull request: https://github.com/apache/apex-malhar/pull/358#discussion_r73830019 --- Diff: library/src/main/java/com/datatorrent/lib/db/jdbc/AbstractJdbcPollInputOperator.java --- @@ -438,119 +261,110 @@ public void endWindow() currentWindowRecoveryState = new MutablePair<>(); } - public int getPartitionCount() - { - return partitionCount; - } - - public void setPartitionCount(int partitionCount) + @Override + public void deactivate() { - this.partitionCount = partitionCount; + scanService.shutdownNow(); + store.disconnect(); } - @Override - public void activate(Context cntxt) + protected void pollRecords() { - if (context.getValue(OperatorContext.ACTIVATION_WINDOW_ID) != Stateless.WINDOW_ID - && context.getValue(OperatorContext.ACTIVATION_WINDOW_ID) < windowManager.getLargestRecoveryWindow()) { - // If it is a replay state, don't start any threads here + if (isPolled) { return; } - } - - @Override - public void deactivate() - { try { - if (dbPoller != null && dbPoller.isAlive()) { - dbPoller.interrupt(); - dbPoller.join(); + ps.setFetchSize(getFetchSize()); + ResultSet result = ps.executeQuery(); + if (result.next()) { + do { + emitQueue.add(getTuple(result)); + } while (result.next()); } - } catch (InterruptedException ex) { - // log and ignore, ending execution anyway - LOG.error("exception in poller thread: ", ex); + isPolled = true; + } catch (SQLException ex) { + throw new RuntimeException(String.format("Error while running query"), ex); + } finally { + store.disconnect(); } - } - @Override - public void handleIdleTime() - { - if (execute) { - try { - Thread.sleep(spinMillis); - } catch (InterruptedException ie) { - throw new RuntimeException(ie); - } - } else { - LOG.error("Exception: ", cause); - DTThrowable.rethrow(cause.get()); - } } + public abstract T getTuple(ResultSet result); + protected void replay(long windowId) throws SQLException { - isReplayed = true; - MutablePair recoveredData = new MutablePair(); try { - recoveredData = (MutablePair)windowManager.load(operatorId, windowId); + MutablePair recoveredData = (MutablePair)windowManager.load(operatorId, + windowId); - if (recoveredData != null) { - //skip the window and return if there was no incoming data in the window - if (recoveredData.left == null || recoveredData.right == null) { - return; - } - - if (recoveredData.right.equals(rangeQueryPair.getValue()) || recoveredData.right.equals(previousUpperBound)) { - LOG.info("Matched so returning"); - return; - } + if (recoveredData != null && shouldReplayWindow(recoveredData)) { + LOG.debug("[Recovering Window ID - {} for record range: {}, {}]", windowId, recoveredData.left, + recoveredData.right); - JdbcPollInputOperator jdbcPoller = new JdbcPollInputOperator(); - jdbcPoller.setStore(store); - jdbcPoller.setKey(getKey()); - jdbcPoller.setPartitionCount(getPartitionCount()); - jdbcPoller.setPollInterval(getPollInterval()); - jdbcPoller.setTableName(getTableName()); - jdbcPoller.setBatchSize(getBatchSize()); - isPollable = false; - - LOG.debug("[Window ID -" + windowId + "," + recoveredData.left + "," + recoveredData.right + "]"); + ps = store.getConnection().prepareStatement( + buildRangeQuery(rangeQueryPair.getKey(), (rangeQueryPair.getValue() - rangeQueryPair.getKey())), --- End diff -- Should this fetch data from ```recoveredData.left``` to ```recoveredData.right```? --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---