Github user bhupeshchawda commented on a diff in the pull request: https://github.com/apache/apex-malhar/pull/358#discussion_r73828043 --- Diff: library/src/main/java/com/datatorrent/lib/db/jdbc/AbstractJdbcPollInputOperator.java --- @@ -286,149 +141,117 @@ public AbstractJdbcPollInputOperator() public void setup(OperatorContext context) { super.setup(context); - spinMillis = context.getValue(Context.OperatorContext.SPIN_MILLIS); + intializeDSLContext(); + if (scanService == null) { + scanService = Executors.newScheduledThreadPool(1); + } execute = true; - cause = new AtomicReference<Throwable>(); - emitQueue = new ArrayBlockingQueue<List<T>>(queueCapacity); - this.context = context; + emitQueue = new LinkedBlockingDeque<>(queueCapacity); operatorId = context.getId(); + windowManager.setup(context); + } - try { + private void intializeDSLContext() + { + create = DSL.using(store.getConnection(), JDBCUtils.dialect(store.getDatabaseUrl())); + } - //If its a range query pass upper and lower bounds - //If its a polling query pass only the lower bound - if (getRangeQueryPair().getValue() != null) { - ps = store.getConnection() - .prepareStatement( - JdbcMetaDataUtility.buildRangeQuery(getTableName(), getKey(), rangeQueryPair.getKey(), - rangeQueryPair.getValue()), - java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); + @Override + public void activate(OperatorContext context) + { + initializePreparedStatement(); + long largestRecoveryWindow = windowManager.getLargestRecoveryWindow(); + if (largestRecoveryWindow == Stateless.WINDOW_ID + || context.getValue(Context.OperatorContext.ACTIVATION_WINDOW_ID) > largestRecoveryWindow) { + scanService.scheduleAtFixedRate(new DBPoller(), 0, pollInterval, TimeUnit.MILLISECONDS); + } + } + + protected void initializePreparedStatement() + { + try { + // If its a range query pass upper and lower bounds, If its a polling query pass only the lower bound + if (isPollerPartition) { + ps = store.getConnection().prepareStatement(buildRangeQuery(rangeQueryPair.getKey(), Integer.MAX_VALUE), + TYPE_FORWARD_ONLY, CONCUR_READ_ONLY); } else { ps = store.getConnection().prepareStatement( - JdbcMetaDataUtility.buildPollableQuery(getTableName(), getKey(), rangeQueryPair.getKey()), - java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); - isPollable = true; + buildRangeQuery(rangeQueryPair.getKey(), (rangeQueryPair.getValue() - rangeQueryPair.getKey())), + TYPE_FORWARD_ONLY, CONCUR_READ_ONLY); } - } catch (SQLException e) { LOG.error("Exception in initializing the range query for a given partition", e); throw new RuntimeException(e); } - windowManager.setup(context); - LOG.debug("super setup done..."); } @Override public void beginWindow(long windowId) { currentWindowId = windowId; - - isReplayed = false; - if (currentWindowId <= windowManager.getLargestRecoveryWindow()) { try { replay(currentWindowId); + return; } catch (SQLException e) { LOG.error("Exception in replayed windows", e); throw new RuntimeException(e); } } - - if (isReplayed && currentWindowId == windowManager.getLargestRecoveryWindow()) { - try { - if (!isPollable && rangeQueryPair.getValue() != null) { - - ps = store.getConnection().prepareStatement( - JdbcMetaDataUtility.buildGTRangeQuery(getTableName(), getKey(), previousUpperBound, - rangeQueryPair.getValue()), - java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); - } else { - String bound = null; - if (previousUpperBound == null) { - bound = getRangeQueryPair().getKey(); - } else { - bound = previousUpperBound; - } - ps = store.getConnection().prepareStatement( - JdbcMetaDataUtility.buildPollableQuery(getTableName(), getKey(), bound), - java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_READ_ONLY); - isPollable = true; - } - isReplayed = false; - LOG.debug("Prepared statement after re-initialization - {} ", ps.toString()); - } catch (SQLException e) { - // TODO Auto-generated catch block - throw new RuntimeException(e); - } + if (isPollerPartition) { + updatePollQuery(); + isPolled = false; --- End diff -- Shouldn't ```isPolled``` be false irrespective of whether it is a poller partition or not?
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. ---