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 88CEA200B59 for ; Mon, 8 Aug 2016 10:55:11 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 87837160A91; Mon, 8 Aug 2016 08:55:11 +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 A4CB7160A8F for ; Mon, 8 Aug 2016 10:55:10 +0200 (CEST) Received: (qmail 13607 invoked by uid 500); 8 Aug 2016 08:55:09 -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 13596 invoked by uid 99); 8 Aug 2016 08:55:09 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2016 08:55:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id 29E53C0957 for ; Mon, 8 Aug 2016 08:55:09 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -5.446 X-Spam-Level: X-Spam-Status: No, score=-5.446 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=-1.426] autolearn=disabled Received: from mx2-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id WYuPAtb1ZWiz for ; Mon, 8 Aug 2016 08:55:06 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx2-lw-eu.apache.org (ASF Mail Server at mx2-lw-eu.apache.org) with SMTP id EEE5D5F230 for ; Mon, 8 Aug 2016 08:55:05 +0000 (UTC) Received: (qmail 13323 invoked by uid 99); 8 Aug 2016 08:55:05 -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 08:55:05 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 1DE6DDFB87; Mon, 8 Aug 2016 08:55:05 +0000 (UTC) From: DT-Priyanka 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: <20160808085505.1DE6DDFB87@git1-us-west.apache.org> Date: Mon, 8 Aug 2016 08:55:05 +0000 (UTC) archived-at: Mon, 08 Aug 2016 08:55:11 -0000 Github user DT-Priyanka commented on a diff in the pull request: https://github.com/apache/apex-malhar/pull/358#discussion_r73841763 --- 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())), + TYPE_FORWARD_ONLY, CONCUR_READ_ONLY); + LOG.info("Query formed to recover data - {}", ps.toString()); - jdbcPoller.setRangeQueryPair(new KeyValPair(recoveredData.left, recoveredData.right)); + emitReplayedTuples(ps); - jdbcPoller.ps = jdbcPoller.store.getConnection().prepareStatement( - JdbcMetaDataUtility.buildRangeQuery(jdbcPoller.getTableName(), jdbcPoller.getKey(), - jdbcPoller.getRangeQueryPair().getKey(), jdbcPoller.getRangeQueryPair().getValue()), - java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); - LOG.info("Query formed for recovered data - {}", jdbcPoller.ps.toString()); + } - emitReplayedTuples(jdbcPoller.ps); + if (currentWindowId == windowManager.getLargestRecoveryWindow()) { + try { + if (!isPollerPartition && rangeQueryPair.getValue() != null) { + ps = store.getConnection().prepareStatement( + buildRangeQuery(lastEmittedRecord, (rangeQueryPair.getValue() - lastEmittedRecord)), TYPE_FORWARD_ONLY, + CONCUR_READ_ONLY); + } else { + Integer bound = null; + if (lastEmittedRecord == null) { + bound = rangeQueryPair.getKey(); + } else { + bound = lastEmittedRecord; + } + ps = store.getConnection().prepareStatement(buildRangeQuery(bound, Integer.MAX_VALUE), TYPE_FORWARD_ONLY, + CONCUR_READ_ONLY); + } + scanService.scheduleAtFixedRate(new DBPoller(), 0, pollInterval, TimeUnit.MILLISECONDS); --- End diff -- If we don't start threads in "activate" method we want to do it in beginWindow once "reply" is done. --- 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. ---