当前位置: 首页>>代码示例>>Java>>正文


Java HashedBytes类代码示例

本文整理汇总了Java中org.apache.hadoop.hbase.util.HashedBytes的典型用法代码示例。如果您正苦于以下问题:Java HashedBytes类的具体用法?Java HashedBytes怎么用?Java HashedBytes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HashedBytes类属于org.apache.hadoop.hbase.util包,在下文中一共展示了HashedBytes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Returns existing row lock if found, otherwise obtains a new row lock and returns it.
 * @param lockid requested by the user, or null if the user didn't already hold lock
 * @param row the row to lock
 * @param waitForLock if true, will block until the lock is available, otherwise will simply
 *          return null if it could not acquire the lock.
 * @return lockid or null if waitForLock is false and the lock was unavailable.
 */
protected Integer getLock(Integer lockid, HashedBytes row, boolean waitForLock)
    throws IOException {
  Integer lid;
  if (lockid == null) {
    lid = internalObtainRowLock(row, waitForLock);
  } else {
    HashedBytes rowFromLock = lockIds.get(lockid);
    if (!row.equals(rowFromLock)) {
      throw new IOException("Invalid row lock: LockId: " + lockid + " holds the lock for row: "
          + rowFromLock + " but wanted lock for row: " + row);
    }
    lid = lockid;
  }
  return lid;
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:24,代码来源:HRegion.java

示例2: releaseRowLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Release the row lock!
 * @param lockId  The lock ID to release.
 */
public void releaseRowLock(final Integer lockId) {
  if (lockId == null) return; // null lock id, do nothing
  HashedBytes rowKey = lockIds.remove(lockId);
  if (rowKey == null) {
    LOG.warn("Release unknown lockId: " + lockId);
    return;
  }
  CountDownLatch rowLatch = lockedRows.remove(rowKey);
  if (rowLatch == null) {
    LOG.error("Releases row not locked, lockId: " + lockId + " row: "
        + rowKey);
    return;
  }
  rowLatch.countDown();
}
 
开发者ID:wanhao,项目名称:IRIndex,代码行数:20,代码来源:HRegion.java

示例3: releaseRowLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Release the row lock!
 * @param lockId The lock ID to release.
 */
public void releaseRowLock(final Integer lockId) {
  if (lockId == null) return; // null lock id, do nothing
  HashedBytes rowKey = lockIds.remove(lockId);
  if (rowKey == null) {
    LOG.warn("Release unknown lockId: " + lockId);
    return;
  }
  CountDownLatch rowLatch = lockedRows.remove(rowKey);
  if (rowLatch == null) {
    LOG.error("Releases row not locked, lockId: " + lockId + " row: " + rowKey);
    return;
  }
  rowLatch.countDown();
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:19,代码来源:HRegion.java

示例4: testGettingTheLockMatchesMyRow

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
@Test
public void testGettingTheLockMatchesMyRow() throws Exception {
  MockHRegion region = getMockHRegion();
  HashedBytes rowKey = new HashedBytes(Bytes.toBytes(1));
  assertEquals(Integer.valueOf(2), region.getLock(null, rowKey, false));
  assertEquals(Integer.valueOf(2), region.getLock(2, rowKey, false));
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:8,代码来源:TestBatchHRegionLockingAndWrites.java

示例5: getLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
@Override
public Integer getLock(Integer lockid, HashedBytes row, boolean waitForLock) throws IOException {
  if (testStep == TestStep.CHECKANDPUT_STARTED) {
    latch.countDown();
  }
  return super.getLock(lockid, row, waitForLock);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:8,代码来源:TestHBase7051.java

示例6: getRowLockInternal

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * A version of getRowLock(byte[], boolean) to use when a region operation has already been
 * started (the calling thread has already acquired the region-close-guard lock).
 */
protected RowLock getRowLockInternal(byte[] row, boolean waitForLock) throws IOException {
    checkRow(row, "row lock");
    HashedBytes rowKey = new HashedBytes(row);
    RowLockContext rowLockContext = new RowLockContext(rowKey);

    // loop until we acquire the row lock (unless !waitForLock)
    while (true) {
        RowLockContext existingContext = lockedRows.putIfAbsent(rowKey, rowLockContext);
        if (existingContext == null) {
            // Row is not already locked by any thread, use newly created context.
            break;
        } else if (existingContext.ownedByCurrentThread()) {
            // Row is already locked by current thread, reuse existing context instead.
            rowLockContext = existingContext;
            break;
        } else {
            if (!waitForLock) {
                return null;
            }
            try {
                // Row is already locked by some other thread, give up or wait for it
                if (!existingContext.latch.await(this.rowLockWaitDuration, TimeUnit.MILLISECONDS)) {
                    throw new IOException("Timed out waiting for lock for row: " + rowKey);
                }
            } catch (InterruptedException ie) {
                LOG.warn("Thread interrupted waiting for lock on row: " + rowKey);
                InterruptedIOException iie = new InterruptedIOException();
                iie.initCause(ie);
                throw iie;
            }
        }
    }

    // allocate new lock for this thread
    return rowLockContext.newLock();
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:41,代码来源:HRegion.java

示例7: getLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Returns existing row lock if found, otherwise
 * obtains a new row lock and returns it.
 * @param lockid requested by the user, or null if the user didn't already hold lock
 * @param row the row to lock
 * @param waitForLock if true, will block until the lock is available, otherwise will
 * simply return null if it could not acquire the lock.
 * @return lockid or null if waitForLock is false and the lock was unavailable.
 */
protected Integer getLock(Integer lockid, HashedBytes row, boolean waitForLock)
throws IOException {
  Integer lid;
  if (lockid == null) {
    lid = internalObtainRowLock(row, waitForLock);
  } else {
    HashedBytes rowFromLock = lockIds.get(lockid);
    if (!row.equals(rowFromLock)) {
      throw new IOException("Invalid row lock: LockId: " + lockid + " holds the lock for row: " + rowFromLock + " but wanted lock for row: " + row);
    }
    lid = lockid;
  }
  return lid;
}
 
开发者ID:wanhao,项目名称:IRIndex,代码行数:24,代码来源:HRegion.java

示例8: releaseRowLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Release the row lock!
 * @param lockId  The lock ID to release.
 */
public void releaseRowLock(final Integer lockId) {
  HashedBytes rowKey = lockIds.remove(lockId);
  if (rowKey == null) {
    LOG.warn("Release unknown lockId: " + lockId);
    return;
  }
  CountDownLatch rowLatch = lockedRows.remove(rowKey);
  if (rowLatch == null) {
    LOG.error("Releases row not locked, lockId: " + lockId + " row: "
        + rowKey);
    return;
  }
  rowLatch.countDown();
}
 
开发者ID:lifeng5042,项目名称:RStore,代码行数:19,代码来源:HRegion.java

示例9: getRowLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Get a row lock for the specified row. All locks are reentrant. Before calling this function
 * make sure that a region operation has already been started (the calling thread has already
 * acquired the region-close-guard lock).
 *
 * @param row      The row actions will be performed against
 * @param readLock is the lock reader or writer. True indicates that a non-exlcusive lock is
 *                 requested
 */
public RowLock getRowLock(byte[] row, boolean readLock) throws IOException {
  // Make sure the row is inside of this region before getting the lock for
  // it.
  checkRow(row, "row lock");
  // create an object to use a a key in the row lock map
  HashedBytes rowKey = new HashedBytes(row);

  RowLockContext rowLockContext = null;
  RowLockImpl result = null;
  TraceScope traceScope = null;

  // If we're tracing start a span to show how long this took.
  if (Trace.isTracing()) {
    traceScope = Trace.startSpan("HRegion.getRowLock");
    traceScope.getSpan()
        .addTimelineAnnotation("Getting a " + (readLock ? "readLock" : "writeLock"));
  }

  try {
    // Keep trying until we have a lock or error out.
    // TODO: do we need to add a time component here?
    while (result == null) {

      // Try adding a RowLockContext to the lockedRows.
      // If we can add it then there's no other transactions currently
      // running.
      rowLockContext = new RowLockContext(rowKey);
      RowLockContext existingContext = lockedRows.putIfAbsent(rowKey, rowLockContext);

      // if there was a running transaction then there's already a context.
      if (existingContext != null) {
        rowLockContext = existingContext;
      }

      // Now try an get the lock.
      //
      // This can fail as
      if (readLock) {
        result = rowLockContext.newReadLock();
      } else {
        result = rowLockContext.newWriteLock();
      }
    }
    if (!result.getLock().tryLock(this.rowLockWaitDuration, TimeUnit.MILLISECONDS)) {
      if (traceScope != null) {
        traceScope.getSpan().addTimelineAnnotation("Failed to get row lock");
      }
      result = null;
      // Clean up the counts just in case this was the thing keeping the
      // context alive.
      rowLockContext.cleanUp();
      throw new IOException("Timed out waiting for lock for row: " + rowKey);
    }
    return result;
  } catch (InterruptedException ie) {
    LOG.warn("Thread interrupted waiting for lock on row: " + rowKey);
    InterruptedIOException iie = new InterruptedIOException();
    iie.initCause(ie);
    if (traceScope != null) {
      traceScope.getSpan().addTimelineAnnotation("Interrupted exception getting row lock");
    }
    Thread.currentThread().interrupt();
    throw iie;
  } finally {
    if (traceScope != null) {
      traceScope.close();
    }
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:79,代码来源:HRegion.java

示例10: RowLockContext

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
RowLockContext(HashedBytes row) {
  this.row = row;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:4,代码来源:HRegion.java

示例11: internalObtainRowLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Obtains or tries to obtain the given row lock.
 * @param waitForLock if true, will block until the lock is available. Otherwise, just tries to
 *          obtain the lock and returns null if unavailable.
 */
private Integer internalObtainRowLock(final HashedBytes rowKey, boolean waitForLock)
    throws IOException {
  checkRow(rowKey.getBytes(), "row lock");
  startRegionOperation();
  try {
    CountDownLatch rowLatch = new CountDownLatch(1);

    // loop until we acquire the row lock (unless !waitForLock)
    while (true) {
      CountDownLatch existingLatch = lockedRows.putIfAbsent(rowKey, rowLatch);
      if (existingLatch == null) {
        break;
      } else {
        // row already locked
        if (!waitForLock) {
          return null;
        }
        try {
          if (!existingLatch.await(this.rowLockWaitDuration, TimeUnit.MILLISECONDS)) {
            throw new IOException("Timed out on getting lock for row=" + rowKey);
          }
        } catch (InterruptedException ie) {
          // Empty
        }
      }
    }

    // loop until we generate an unused lock id
    while (true) {
      Integer lockId = lockIdGenerator.incrementAndGet();
      HashedBytes existingRowKey = lockIds.putIfAbsent(lockId, rowKey);
      if (existingRowKey == null) {
        return lockId;
      } else {
        // lockId already in use, jump generator to a new spot
        lockIdGenerator.set(rand.nextInt());
      }
    }
  } finally {
    closeRegionOperation();
  }
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:48,代码来源:HRegion.java

示例12: getLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
@Override
public Integer getLock(Integer lockid, HashedBytes row, boolean waitForLock) throws IOException {
  acqioredLockCount++;
  return super.getLock(lockid, row, waitForLock);
}
 
开发者ID:fengchen8086,项目名称:LCIndex-HBase-0.94.16,代码行数:6,代码来源:TestBatchHRegionLockingAndWrites.java

示例13: RowLockContext

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
RowLockContext(HashedBytes row) {
    this.row = row;
    this.thread = Thread.currentThread();
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:5,代码来源:HRegion.java

示例14: getRowLock

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
/**
 * Tries to acquire a lock on the given row.
 * @param waitForLock if true, will block until the lock is available.
 *        Otherwise, just tries to obtain the lock and returns
 *        false if unavailable.
 * @return the row lock if acquired,
 *   null if waitForLock was false and the lock was not acquired
 * @throws IOException if waitForLock was true and the lock could not be acquired after waiting
 */
public RowLock getRowLock(byte[] row, boolean waitForLock) throws IOException {
  checkRow(row, "row lock");
  startRegionOperation();
  try {
    HashedBytes rowKey = new HashedBytes(row);
    RowLockContext rowLockContext = new RowLockContext(rowKey);

    // loop until we acquire the row lock (unless !waitForLock)
    while (true) {
      RowLockContext existingContext = lockedRows.putIfAbsent(rowKey, rowLockContext);
      if (existingContext == null) {
        // Row is not already locked by any thread, use newly created context.
        break;
      } else if (existingContext.ownedByCurrentThread()) {
        // Row is already locked by current thread, reuse existing context instead.
        rowLockContext = existingContext;
        break;
      } else {
        // Row is already locked by some other thread, give up or wait for it
        if (!waitForLock) {
          return null;
        }
        try {
          if (!existingContext.latch.await(this.rowLockWaitDuration, TimeUnit.MILLISECONDS)) {
            throw new IOException("Timed out waiting for lock for row: " + rowKey);
          }
        } catch (InterruptedException ie) {
          LOG.warn("Thread interrupted waiting for lock on row: " + rowKey);
          InterruptedIOException iie = new InterruptedIOException();
          iie.initCause(ie);
          throw iie;
        }
      }
    }

    // allocate new lock for this thread
    return rowLockContext.newLock();
  } finally {
    closeRegionOperation();
  }
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:51,代码来源:HRegion.java

示例15: RowLockContext

import org.apache.hadoop.hbase.util.HashedBytes; //导入依赖的package包/类
RowLockContext(HashedBytes row) {
  this.row = row;
  this.thread = Thread.currentThread();
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:5,代码来源:HRegion.java


注:本文中的org.apache.hadoop.hbase.util.HashedBytes类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。