Package org.apache.oozie.lock

Examples of org.apache.oozie.lock.LockToken


                if (value.postValue() < maxSequence) {
                    return;
                }
            }
            // Acquire ZK lock, so that other host doesn't reset sequence.
            LockToken lock = null;
            try {
                lock = Services.get().get(MemoryLocksService.class)
                        .getWriteLock(ZKUUIDService.class.getName(), lockTimeout);
            }
            catch (InterruptedException e1) {
                //ignore
            }
            try {
                if (lock == null) {
                    LOG.info("Lock is held by other system, will sleep and try again");
                    Thread.sleep(1000);
                    continue;
                }
                else {
                    value = atomicIdGenerator.get();
                    if (value.succeeded()) {
                        if (value.postValue() < maxSequence) {
                            return;
                        }
                    }
                    try {
                        atomicIdGenerator.forceSet(RESET_VALUE);
                    }
                    catch (Exception e) {
                        LOG.info("Exception while resetting sequence, will try again");
                        continue;
                    }
                    resetStartTime();
                    return;
                }
            }
            finally {
                if (lock != null) {
                    lock.release();
                }
            }
        }
        throw new Exception("Can't reset ID sequence in ZK. Retried " + RETRY_COUNT + " times");
    }
View Full Code Here


        Services.get().getConf().set(ZKLocksService.REAPING_THRESHOLD, "1");
        ZKLocksService zkls = new ZKLocksService();
        try {
            zkls.init(Services.get());
            for (int i = 0; i < 10; ++i) {
                LockToken l = zkls.getReadLock(String.valueOf(i), 1);
                l.release();

            }
            sleep(2000);
            Stat stat = getClient().checkExists().forPath(ZKLocksService.LOCKS_NODE);
            assertEquals(stat.getNumChildren(), 0);
View Full Code Here

        @Override
        public void run() {
            try {
                log.info("Getting lock [{0}]", nameIndex);
                LockToken token = getLock();
                if (token != null) {
                    log.info("Got lock [{0}]", nameIndex);
                    sb.append(nameIndex).append("-L ");
                    synchronized (this) {
                        wait();
                    }
                    sb.append(nameIndex).append("-U ");
                    token.release();
                    log.info("Release lock [{0}]", nameIndex);
                }
                else {
                    sb.append(nameIndex).append("-N ");
                    log.info("Did not get lock [{0}]", nameIndex);
View Full Code Here

        // ZKLocksService will use ZKUtils which will start advertising on the service discovery.  We can also acquire a lock so
        // it will create a lock znode.
        ZKLocksService zkls = new ZKLocksService();
        try {
            zkls.init(Services.get());
            LockToken lock = zkls.getWriteLock("foo", 3);
            lock.release();
            List<ACL> acls = getClient().getZookeeperClient().getZooKeeper().getACL("/oozie", new Stat());
            assertEquals(ZooDefs.Perms.ALL, acls.get(0).getPerms());
            assertEquals("world", acls.get(0).getId().getScheme());
            assertEquals("anyone", acls.get(0).getId().getId());
            acls = getClient().getACL().forPath("/locks");
View Full Code Here

            assertNull(getClient().getZookeeperClient().getZooKeeper().exists("/oozie", null));
            assertNull(getClient().checkExists().forPath("/locks"));
            assertNull(getClient().checkExists().forPath("/services"));
            // Check that new znodes will use the ACLs
            zkls.init(Services.get());
            LockToken lock = zkls.getWriteLock("foo", 3);
            lock.release();
            List<ACL> acls = getClient().getZookeeperClient().getZooKeeper().getACL("/oozie", new Stat());
            assertEquals(ZooDefs.Perms.ALL, acls.get(0).getPerms());
            assertEquals("sasl", acls.get(0).getId().getScheme());
            assertEquals(PRIMARY_PRINCIPAL, acls.get(0).getId().getId());
            acls = getClient().getACL().forPath("/locks");
View Full Code Here

    private static class LockGetter extends Thread {

        @Override
        public void run() {
            try {
                LockToken lock = Services.get().get(MemoryLocksService.class).getWriteLock("key", 1);
                if (lock == null) {
                    fail();
                }
                sleep(150);
            }
View Full Code Here

            this.lookupInterval = lookupInterval;
        }

        @Override
        public void run() {
            LockToken lock = null;

            // first check if there is some other running instance from the same service;
            try {
                lock = Services.get().get(MemoryLocksService.class)
                        .getWriteLock(CoordMaterializeTriggerService.class.getName(), lockTimeout);

                if (lock != null) {
                    runCoordJobMatLookup();
                    if (null != callables) {
                        boolean ret = Services.get().get(CallableQueueService.class).queueSerial(callables);
                        if (ret == false) {
                            XLog.getLog(getClass()).warn(
                                    "Unable to queue the callables commands for CoordMaterializeTriggerRunnable. "
                                            + "Most possibly command queue is full. Queue size is :"
                                            + Services.get().get(CallableQueueService.class).queueSize());
                        }
                        callables = null;
                    }
                    if (null != delayedCallables) {
                        boolean ret = Services.get().get(CallableQueueService.class)
                                .queueSerial(delayedCallables, this.delay);
                        if (ret == false) {
                            XLog.getLog(getClass()).warn(
                                    "Unable to queue the delayedCallables commands for CoordMaterializeTriggerRunnable. "
                                            + "Most possibly Callable queue is full. Queue size is :"
                                            + Services.get().get(CallableQueueService.class).queueSize());
                        }
                        delayedCallables = null;
                        this.delay = 0;
                    }
                }

                else {
                    LOG.debug("Can't obtain lock, skipping");
                }
            }
            catch (Exception e) {
                LOG.error("Exception", e);
            }
            finally {
                if (lock != null) {
                    lock.release();
                    LOG.info("Released lock for [{0}]", CoordMaterializeTriggerService.class.getName());
                }

            }
View Full Code Here

            long statusPendingCount = 0;
            List<SLASummaryBean> summaryBeans = jpaService.execute(new SLASummaryGetRecordsOnRestartJPAExecutor(
                    modifiedAfter));
            for (SLASummaryBean summaryBean : summaryBeans) {
                String jobId = summaryBean.getId();
                LockToken lock = null;
                switch (summaryBean.getAppType()) {
                    case COORDINATOR_ACTION:
                        isJobModified = processSummaryBeanForCoordAction(summaryBean, jobId);
                        break;
                    case WORKFLOW_ACTION:
                        isJobModified = processSummaryBeanForWorkflowAction(summaryBean, jobId);
                        break;
                    case WORKFLOW_JOB:
                        isJobModified = processSummaryBeanForWorkflowJob(summaryBean, jobId);
                        break;
                    default:
                        break;
                }
                if (isJobModified) {
                    try {
                        boolean update = true;
                        if (Services.get().get(JobsConcurrencyService.class).isHighlyAvailableMode()) {
                            lock = Services
                                    .get()
                                    .get(MemoryLocksService.class)
                                    .getWriteLock(
                                            SLACalcStatus.SLA_ENTITYKEY_PREFIX + jobId,
                                            Services.get().getConf()
                                                    .getLong(SLAService.CONF_SLA_CALC_LOCK_TIMEOUT, 5 * 1000));
                            if (lock == null) {
                                update = false;
                            }
                        }
                        if (update) {
                            summaryBean.setLastModifiedTime(new Date());
                            SLASummaryQueryExecutor.getInstance().executeUpdate(
                                    SLASummaryQuery.UPDATE_SLA_SUMMARY_FOR_STATUS_ACTUAL_TIMES, summaryBean);
                        }
                    }
                    catch (Exception e) {
                        LOG.warn("Failed to load records for " + jobId, e);
                    }
                    finally {
                        if (lock != null) {
                            lock.release();
                            lock = null;
                        }
                    }
                }
                try {
View Full Code Here

TOP

Related Classes of org.apache.oozie.lock.LockToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.