Examples of LockToken


Examples of com.linkedin.databus.core.util.RangeBasedReaderWriterLock.LockToken

    RangeBasedReaderWriterLock.LOG.setLevel(Level.FATAL);
    long startTime = System.nanoTime();
    int numOperations = 1000000;
    for (int i=numOperations -1; i > 0; --i)
    {
      LockToken token = lockProvider.acquireReaderLock(i, numOperations,_parser, "lock" + i);
      long minStart = lockProvider.getReaderRanges().peek()._id.start;
      lockProvider.acquireWriterLock(0, minStart,_parser);
      lockProvider.releaseWriterLock(_parser);
      if (minStart != i)
      {
        Assert.fail("i should always be equal to minStart");
      }
      //assertEquals(i, minStart);
      while (!checkedOutLockTokens.offer(token))
      {
        for (int j = 0; j < 5; ++j)
        {
          LockToken releaseToken = checkedOutLockTokens.poll();
          lockProvider.releaseReaderLock(releaseToken);
        }
      }

    }
View Full Code Here

Examples of com.linkedin.databus.core.util.RangeBasedReaderWriterLock.LockToken

  @Override
  public void run()
  {
    _stopRunning.set(!_enabled);
    LockToken readRangeLock = null;

    // Init : delete existing files in this directory first
    // We don't do this as part of the constructor since we want the EventLogReader
    // to be able to read files if they are present.
    if (_writeSessionDir.exists())
View Full Code Here

Examples of com.linkedin.databus.core.util.RangeBasedReaderWriterLock.LockToken

  private void queueWriteRequest()
  {
    // non-contiguous write
    // signal write ready
    LockToken readRangeLockToken = null;
    try
    {
      readRangeLockToken = _lockProvider.acquireReaderLock(_batchStartOffset, _batchNextOffset,
                                      _eventBuffer.getBufferPositionParser(),
                                      "EventLogWriter.queueWriteRequest");
View Full Code Here

Examples of com.linkedin.databus.core.util.RangeBasedReaderWriterLock.LockToken

  }


  private void flush()
  {
    LockToken readToken;
    while ((readToken = _contiguousRanges.poll()) != null)
    {
      try
      {
        performWrite(readToken);
      }
      catch (IOException e)
      {
        LOG.error("unable to flush" + e.getMessage(), e);
        _stopRunning.set(true);
      }
      finally
      {
        _lockProvider.releaseReaderLock(readToken);
      }
    }
    if (_batchState == BatchState.STARTED)
    {
      LockToken readRangeLockToken = null;
      try
      {
        readRangeLockToken = _lockProvider.acquireReaderLock(_batchStartOffset, _batchNextOffset,
                                                             _eventBuffer.getBufferPositionParser(),
                                                             "EventLogWriter.flush");
View Full Code Here

Examples of com.linkedin.databus.core.util.RangeBasedReaderWriterLock.LockToken

  }

  @Test
  public void testAcquireReaderLock() throws Exception {
    RangeBasedReaderWriterLock lock = new RangeBasedReaderWriterLock();
    LockToken token = lock.acquireReaderLock(10, 200,_parser, "testAcquireReaderLock");
    AssertJUnit.assertEquals(10, token._id.start);
    AssertJUnit.assertEquals(200, token._id.end);

  }
View Full Code Here

Examples of com.linkedin.databus.core.util.RangeBasedReaderWriterLock.LockToken

     {
       /*
          * When Readers with same GenIds present
          */
         LockToken token1 = lock.acquireReaderLock(_parser.setGenId(1000, 1),
                                                   _parser.setGenId(20000, 1),
                                                   _parser,
                                                   "testAcquireWriterLock1");
         LockToken token2 = lock.acquireReaderLock(_parser.setGenId(1000,1),
                                                   _parser.setGenId(20000,1),
                                                   _parser,
                                                   "testAcquireWriterLock2");
         LockToken token3 = lock.acquireReaderLock(_parser.setGenId(10000,1),
                                                   _parser.setGenId(20000,1),
                                                   _parser,
                                                   "testAcquireWriterLock3");

         Runnable writer = new Runnable() {
           @Override
          public void run()
           {
             try
            {
              lock.acquireWriterLock(_parser.setGenId(0,1), _parser.setGenId(1001,1), _parser);
            }
            catch (InterruptedException e)
            {
              log.error(e);
            }
            catch (TimeoutException e)
            {
              log.error(e);
            }
           }
         };

         Thread writerThread = new Thread(writer);
         writerThread.start();

         try
         {
           Thread.sleep(100);
         } catch ( InterruptedException ie) { throw new RuntimeException(ie); }

         AssertJUnit.assertTrue(lock.isWriterWaiting());
         AssertJUnit.assertFalse(lock.isWriterIn());
         lock.releaseReaderLock(token1);

         try
         {
           Thread.sleep(100);
         } catch ( InterruptedException ie) { throw new RuntimeException(ie); }
         AssertJUnit.assertTrue(lock.isWriterWaiting());
         AssertJUnit.assertFalse(lock.isWriterIn());
         lock.releaseReaderLock(token2);

         try
         {
           writerThread.join(1000);
         } catch (InterruptedException ie) {throw new RuntimeException(ie); }

         AssertJUnit.assertTrue(lock.isWriterIn());
         AssertJUnit.assertFalse(lock.isWriterWaiting());
         AssertJUnit.assertFalse(writerThread.isAlive());
         lock.releaseReaderLock(token3);
         lock.releaseWriterLock(_parser);
     }


     {
       /*
        * When Readers with different GenIds present
        */
       LockToken token1 = lock.acquireReaderLock(_parser.setGenId(10, 1),
                                                 _parser.setGenId(200, 1),
                                                 _parser,
                                                 "testAcquireWriterLock4");
       LockToken token2 = lock.acquireReaderLock(_parser.setGenId(10,1),
                                                 _parser.setGenId(2000,1),
                                                 _parser,
                                                 "testAcquireWriterLock5");
       LockToken token3 = lock.acquireReaderLock(2000, 3000, _parser, "testAcquireWriterLock6");

       Runnable writer = new Runnable() {
         @Override
        public void run()
         {
View Full Code Here

Examples of com.linkedin.databus.core.util.RangeBasedReaderWriterLock.LockToken

  }

  @Test
  public void testShiftReaderLock() throws Exception {
    RangeBasedReaderWriterLock lock = new RangeBasedReaderWriterLock();
    LockToken token = lock.acquireReaderLock(10, 200,_parser, "testShiftReaderLock");
    lock.shiftReaderLockStart(token, 50,_parser);
    AssertJUnit.assertEquals(50, token._id.start);
    AssertJUnit.assertEquals(200, token._id.end);
    lock.acquireWriterLock(0, 40,_parser);
    lock.releaseWriterLock(_parser);
View Full Code Here

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

Examples of org.apache.oozie.lock.LockToken

        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

Examples of org.apache.oozie.lock.LockToken

        @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
TOP
Copyright © 2018 www.massapi.com. 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.