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 56235200B59 for ; Mon, 8 Aug 2016 10:53:25 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 54E00160AB3; Mon, 8 Aug 2016 08:53:25 +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 71B0A160A8F for ; Mon, 8 Aug 2016 10:53:24 +0200 (CEST) Received: (qmail 8455 invoked by uid 500); 8 Aug 2016 08:53:23 -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 8444 invoked by uid 99); 8 Aug 2016 08:53:23 -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 08:53:23 +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 3372AC7C8D for ; Mon, 8 Aug 2016 08:53:23 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -3.674 X-Spam-Level: X-Spam-Status: No, score=-3.674 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, 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 mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id Dnfi8W-jA6Ez for ; Mon, 8 Aug 2016 08:53:22 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 6656A5FE69 for ; Mon, 8 Aug 2016 08:53:21 +0000 (UTC) Received: (qmail 7940 invoked by uid 99); 8 Aug 2016 08:53:20 -0000 Received: from arcas.apache.org (HELO arcas) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2016 08:53:20 +0000 Received: from arcas.apache.org (localhost [127.0.0.1]) by arcas (Postfix) with ESMTP id 834772C0003 for ; Mon, 8 Aug 2016 08:53:20 +0000 (UTC) Date: Mon, 8 Aug 2016 08:53:20 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: dev@apex.incubator.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (APEXMALHAR-2172) Update JDBC poll input operator to fix issues MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Mon, 08 Aug 2016 08:53:25 -0000 [ https://issues.apache.org/jira/browse/APEXMALHAR-2172?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15411521#comment-15411521 ] ASF GitHub Bot commented on APEXMALHAR-2172: -------------------------------------------- Github user DT-Priyanka commented on a diff in the pull request: https://github.com/apache/apex-malhar/pull/358#discussion_r73841414 --- 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 -- right, would update. > Update JDBC poll input operator to fix issues > --------------------------------------------- > > Key: APEXMALHAR-2172 > URL: https://issues.apache.org/jira/browse/APEXMALHAR-2172 > Project: Apache Apex Malhar > Issue Type: Improvement > Reporter: Priyanka Gugale > Assignee: Priyanka Gugale > > Update JDBCPollInputOperator to: > 1. Fix small bugs > 2. Use jooq query dsl library to construct sql queries > 3. Make code more readable > 4. Use row counts rather than key column values to partition reads -- This message was sent by Atlassian JIRA (v6.3.4#6332)