Loknath Priyatham Teja Singamsetty  created PHOENIX-3083:
------------------------------------------------------------

             Summary: Avoid additional handling of concurrency control inside 
timertask of BuildIndexScheduleTask when ScheduledThreadPoolExecutor 
executeAtFixedRate does it internally
                 Key: PHOENIX-3083
                 URL: https://issues.apache.org/jira/browse/PHOENIX-3083
             Project: Phoenix
          Issue Type: Improvement
    Affects Versions: 4.8.0, 4.8.1
            Reporter: Loknath Priyatham Teja Singamsetty 
            Assignee: Loknath Priyatham Teja Singamsetty 
            Priority: Trivial


MetaDataRegionObserver codesnippet where inprogress AtomicInteger is used for 
concurrency control:
-----------------------------------------------------------------
    /**
     * Task runs periodically to build indexes whose 
INDEX_NEED_PARTIALLY_REBUILD is set true
     *
     */
    public static class BuildIndexScheduleTask extends TimerTask {
        // inProgress is to prevent timer from invoking a new task while 
previous one is still
        // running
        private final static AtomicInteger inProgress = new AtomicInteger(0);
        RegionCoprocessorEnvironment env;

        public BuildIndexScheduleTask(RegionCoprocessorEnvironment env) {
            this.env = env;
        }

        @Override
        public void run() {
            // FIXME: we should replay the data table Put, as doing a partial 
index build would only add
            // the new rows and not delete the previous index value. Also, we 
should restrict the scan
            // to only data within this region (as otherwise *every* region 
will be running this code
            // separately, all updating the same data.
            RegionScanner scanner = null;
            PhoenixConnection conn = null;
            if (inProgress.get() > 0) {
                LOG.debug("New ScheduledBuildIndexTask skipped as there is 
already one running");
                return;
            }
            try {
                inProgress.incrementAndGet();

----------------------------------------------------

JAVADOC:
-------------- 
public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
                                     long initialDelay,
                                     long period,
                                     TimeUnit unit)
Description copied from interface: ScheduledExecutorService
Creates and executes a periodic action that becomes enabled first after the 
given initial delay, and subsequently with the given period; that is executions 
will commence after initialDelay then initialDelay+period, then initialDelay + 
2 * period, and so on. If any execution of the task encounters an exception, 
subsequent executions are suppressed. Otherwise, the task will only terminate 
via cancellation or termination of the executor. If any execution of this task 
takes longer than its period, then subsequent executions may start late, but 
will not concurrently execute.




--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to