Ejemplo n.º 1
0
  /** Initialize the starting environment memory state */
  void initCacheMemoryUsage() throws DatabaseException {

    synchronized (memoryUsageSynchronizer) {
      treeMemoryUsage = calcTreeCacheUsage();
    }
    assert LatchSupport.countLatchesHeld() == 0;
  }
Ejemplo n.º 2
0
 private boolean checkNoLatchesHeld(boolean nonBlockingRequest) {
   if (nonBlockingRequest) {
     return true; // don't check if it's a non blocking request.
   } else {
     return (LatchSupport.countLatchesHeld() == 0);
   }
 }
Ejemplo n.º 3
0
 protected void hook618(EnvironmentImpl env) {
   latch = LatchSupport.makeLatch(shortClassName() + getNodeId(), env);
   original(env);
 }
Ejemplo n.º 4
0
 protected void hook393() throws DatabaseException {
   assert LatchSupport.countLatchesHeld() == 0;
   original();
 }
Ejemplo n.º 5
0
  static {
    boolean is64 = false;
    boolean isJVM14 = (LatchSupport.getJava5LatchClass() == null); // TODO default value necessary
    String overrideArch = System.getProperty(FORCE_JVM_ARCH);
    try {
      if (overrideArch == null) {
        String arch = System.getProperty(JVM_ARCH_PROPERTY);
        if (arch != null) {
          is64 = Integer.parseInt(arch) == 64;
        }
      } else {
        is64 = Integer.parseInt(overrideArch) == 64;
      }
    } catch (NumberFormatException NFE) {
      NFE.printStackTrace(System.err);
    }

    if (is64) {
      if (isJVM14) {
        RuntimeException RE = new RuntimeException("1.4 based 64 bit JVM not supported");
        RE.printStackTrace(System.err);
        throw RE;
      }
      LONG_OVERHEAD = LONG_OVERHEAD_64;
      BYTE_ARRAY_OVERHEAD = BYTE_ARRAY_OVERHEAD_64;
      OBJECT_OVERHEAD = OBJECT_OVERHEAD_64;
      ARRAY_ITEM_OVERHEAD = ARRAY_ITEM_OVERHEAD_64;
      HASHMAP_OVERHEAD = HASHMAP_OVERHEAD_64;
      HASHMAP_ENTRY_OVERHEAD = HASHMAP_ENTRY_OVERHEAD_64;
      HASHSET_OVERHEAD = HASHSET_OVERHEAD_64;
      HASHSET_ENTRY_OVERHEAD = HASHSET_ENTRY_OVERHEAD_64;
      TWOHASHMAPS_OVERHEAD = TWOHASHMAPS_OVERHEAD_64;
      TREEMAP_OVERHEAD = TREEMAP_OVERHEAD_64;
      TREEMAP_ENTRY_OVERHEAD = TREEMAP_ENTRY_OVERHEAD_64;
      LN_OVERHEAD = LN_OVERHEAD_64;
      DUPCOUNTLN_OVERHEAD = DUPCOUNTLN_OVERHEAD_64;
      BIN_FIXED_OVERHEAD = BIN_FIXED_OVERHEAD_64_15;
      DIN_FIXED_OVERHEAD = DIN_FIXED_OVERHEAD_64_15;
      DBIN_FIXED_OVERHEAD = DBIN_FIXED_OVERHEAD_64_15;
      IN_FIXED_OVERHEAD = IN_FIXED_OVERHEAD_64_15;
      TXN_OVERHEAD = TXN_OVERHEAD_64_15;
      CHECKPOINT_REFERENCE_SIZE = CHECKPOINT_REFERENCE_SIZE_64_15;
      KEY_OVERHEAD = KEY_OVERHEAD_64;
      LOCK_OVERHEAD = LOCK_OVERHEAD_64;
      LOCKINFO_OVERHEAD = LOCKINFO_OVERHEAD_64;
      UTILIZATION_PROFILE_ENTRY = UTILIZATION_PROFILE_ENTRY_64;
      TFS_LIST_INITIAL_OVERHEAD = TFS_LIST_INITIAL_OVERHEAD_64;
      TFS_LIST_SEGMENT_OVERHEAD = TFS_LIST_SEGMENT_OVERHEAD_64;
      LN_INFO_OVERHEAD = LN_INFO_OVERHEAD_64;
      LONG_LIST_PER_ITEM_OVERHEAD = LONG_LIST_PER_ITEM_OVERHEAD_64;
    } else {
      LONG_OVERHEAD = LONG_OVERHEAD_32;
      BYTE_ARRAY_OVERHEAD = BYTE_ARRAY_OVERHEAD_32;
      OBJECT_OVERHEAD = OBJECT_OVERHEAD_32;
      ARRAY_ITEM_OVERHEAD = ARRAY_ITEM_OVERHEAD_32;
      HASHMAP_OVERHEAD = HASHMAP_OVERHEAD_32;
      HASHMAP_ENTRY_OVERHEAD = HASHMAP_ENTRY_OVERHEAD_32;
      HASHSET_OVERHEAD = HASHSET_OVERHEAD_32;
      HASHSET_ENTRY_OVERHEAD = HASHSET_ENTRY_OVERHEAD_32;
      TWOHASHMAPS_OVERHEAD = TWOHASHMAPS_OVERHEAD_32;
      TREEMAP_OVERHEAD = TREEMAP_OVERHEAD_32;
      TREEMAP_ENTRY_OVERHEAD = TREEMAP_ENTRY_OVERHEAD_32;
      LN_OVERHEAD = LN_OVERHEAD_32;
      DUPCOUNTLN_OVERHEAD = DUPCOUNTLN_OVERHEAD_32;
      if (isJVM14) {
        BIN_FIXED_OVERHEAD = BIN_FIXED_OVERHEAD_32_14;
        DIN_FIXED_OVERHEAD = DIN_FIXED_OVERHEAD_32_14;
        DBIN_FIXED_OVERHEAD = DBIN_FIXED_OVERHEAD_32_14;
        IN_FIXED_OVERHEAD = IN_FIXED_OVERHEAD_32_14;
        TXN_OVERHEAD = TXN_OVERHEAD_32_14;
        CHECKPOINT_REFERENCE_SIZE = CHECKPOINT_REFERENCE_SIZE_32_14;
      } else {
        BIN_FIXED_OVERHEAD = BIN_FIXED_OVERHEAD_32_15;
        DIN_FIXED_OVERHEAD = DIN_FIXED_OVERHEAD_32_15;
        DBIN_FIXED_OVERHEAD = DBIN_FIXED_OVERHEAD_32_15;
        IN_FIXED_OVERHEAD = IN_FIXED_OVERHEAD_32_15;
        TXN_OVERHEAD = TXN_OVERHEAD_32_15;
        CHECKPOINT_REFERENCE_SIZE = CHECKPOINT_REFERENCE_SIZE_32_15;
      }
      KEY_OVERHEAD = KEY_OVERHEAD_32;
      LOCK_OVERHEAD = LOCK_OVERHEAD_32;
      LOCKINFO_OVERHEAD = LOCKINFO_OVERHEAD_32;
      UTILIZATION_PROFILE_ENTRY = UTILIZATION_PROFILE_ENTRY_32;
      TFS_LIST_INITIAL_OVERHEAD = TFS_LIST_INITIAL_OVERHEAD_32;
      TFS_LIST_SEGMENT_OVERHEAD = TFS_LIST_SEGMENT_OVERHEAD_32;
      LN_INFO_OVERHEAD = LN_INFO_OVERHEAD_32;
      LONG_LIST_PER_ITEM_OVERHEAD = LONG_LIST_PER_ITEM_OVERHEAD_32;
    }
  }
Ejemplo n.º 6
0
  private LockGrantType lockInternal(
      long nodeId,
      Locker locker,
      LockType type,
      long timeout,
      boolean nonBlockingRequest,
      DatabaseImpl database)
      throws DeadlockException, DatabaseException {

    Long nid = Long.valueOf(nodeId);
    LockAttemptResult result = attemptLock(nid, locker, type, nonBlockingRequest);
    /* If we got the lock or a non-blocking lock was denied, return. */
    if (result.success || result.lockGrant == LockGrantType.DENIED) {
      assert nonBlockingRequest || result.success;
      return result.lockGrant;
    }

    assert checkNoLatchesHeld(nonBlockingRequest)
        : LatchSupport.countLatchesHeld()
            + " latches held while trying to lock, lock table ="
            + LatchSupport.latchesHeldToString();

    /*
     * We must have gotten WAIT_* from the lock request. We know that
     * this is a blocking request, because if it wasn't, Lock.lock
     * would have returned DENIED. Go wait!
     */
    assert !nonBlockingRequest;
    try {
      boolean doWait = true;
      boolean isImportunate = locker.getImportunate();

      /*
       * Before blocking, check locker timeout. We need to check here
       * or lock timeouts will always take precedence and we'll never
       * actually get any txn timeouts.
       */
      if (locker.isTimedOut()) {
        if (validateOwnership(nid, locker, type, !isImportunate, memoryBudget)) {
          doWait = false;
        } else if (isImportunate) {
          result = stealLock(nid, locker, type, memoryBudget);
          if (result.success) {
            doWait = false;
          } else {
            /* Lock holder is non-preemptable, wait below. */
          }
        } else {
          throw makeTimeoutMsg(
              false /*isLockNotTxnTimeout*/,
              locker,
              nodeId,
              type,
              result.lockGrant,
              result.useLock,
              locker.getTxnTimeout(),
              locker.getTxnStartMillis(),
              System.currentTimeMillis(),
              database);
        }
      }

      boolean keepTime = (timeout > 0);
      long startTime = (keepTime ? System.currentTimeMillis() : 0);
      while (doWait) {
        locker.setWaitingFor(result.useLock);

        try {
          locker.wait(timeout);
        } catch (InterruptedException IE) {
          throw new ThreadInterruptedException(envImpl, IE);
        }

        boolean lockerTimedOut = locker.isTimedOut();
        long now = System.currentTimeMillis();
        boolean thisLockTimedOut = (keepTime && (now - startTime >= timeout));
        boolean isRestart = (result.lockGrant == LockGrantType.WAIT_RESTART);

        /*
         * Re-check for ownership of the lock following wait.  If
         * we timed out and we don't have ownership then flush this
         * lock from both the waiters and owners while under the
         * lock table latch.  See SR 10103.
         */
        if (validateOwnership(
            nid,
            locker,
            type,
            (lockerTimedOut || thisLockTimedOut || isRestart) && !isImportunate,
            memoryBudget)) {
          break;
        } else if (isImportunate) {
          result = stealLock(nid, locker, type, memoryBudget);
          if (result.success) {
            break;
          } else {
            /* Lock holder is non-preemptable, wait again. */
          }
        } else {
          /* After a restart conflict the lock will not be held. */
          if (isRestart) {
            throw rangeRestartException;
          }

          if (thisLockTimedOut) {
            throw makeTimeoutMsg(
                true /*isLockNotTxnTimeout*/,
                locker,
                nodeId,
                type,
                result.lockGrant,
                result.useLock,
                timeout,
                startTime,
                now,
                database);
          }

          if (lockerTimedOut) {
            throw makeTimeoutMsg(
                false /*isLockNotTxnTimeout*/,
                locker,
                nodeId,
                type,
                result.lockGrant,
                result.useLock,
                locker.getTxnTimeout(),
                locker.getTxnStartMillis(),
                now,
                database);
          }
        }
      }
    } finally {
      locker.setWaitingFor(null);
      assert EnvironmentImpl.maybeForceYield();
    }

    /*
     * After waiting for the lock, we must break out of the wait loop and
     * add the lock to the locker.  This is true even for importunate
     * lockers, since an existing lock (acquired via a release) will not be
     * added to the locker by attemptLock. [#16879]
     */
    locker.addLock(nid, type, result.lockGrant);

    return result.lockGrant;
  }
Ejemplo n.º 7
0
 protected void hook434(EnvironmentImpl envImpl) throws DatabaseException {
   fsyncLatch = LatchSupport.makeLatch("fsyncLatch", envImpl);
   original(envImpl);
 }