Package com.sleepycat.je.tree

Examples of com.sleepycat.je.tree.LN


        if (!database.getSortedDuplicates()) {
            throw new DatabaseException
                ("putNoDupData() called, but database is not configured " +
                 "for duplicate data.");
        }
        return putLN(Key.makeKey(key), new LN(data), true);
    }
View Full Code Here


            /*
             * Find the existing entry and get a reference to all BIN fields
             * while latched.
             */
            LN ln = (LN) targetBin.fetchTarget(targetIndex);
            byte[] lnKey = targetBin.getKey(targetIndex);
            Comparator userComparisonFcn = targetBin.getKeyComparator();

            /* If fetchTarget returned null, a deleted LN was cleaned. */
      if (targetBin.isEntryKnownDeleted(targetIndex) ||
                ln == null) {
    return OperationStatus.NOTFOUND;
      }

            /* Get a write lock. */
      LockResult lockResult = lockLN(ln, LockType.WRITE);
      ln = lockResult.getLN();

      /* Check LN deleted status under the protection of a write lock. */
      if (ln == null) {
    return OperationStatus.NOTFOUND;
      }

            /*
             * If cursor points at a dup, then we can only replace the entry
             * with a new entry that is "equal" to the old one.  Since a user
             * defined comparison function may actually compare equal for two
             * byte sequences that are actually different we still have to do
             * the replace.  Arguably we could skip the replacement if there is
             * no user defined comparison function and the new data is the
             * same.
             */
      byte[] foundDataBytes;
      byte[] foundKeyBytes;
            latchBINs();
      isDup = setTargetBin();
      if (isDup) {
    foundDataBytes = lnKey;
    foundKeyBytes = targetBin.getDupKey();
      } else {
    foundDataBytes = ln.getData();
    foundKeyBytes = lnKey;
      }
            byte[] newData;

            /* Resolve partial puts. */
            if (data.getPartial()) {
                int dlen = data.getPartialLength();
                int doff = data.getPartialOffset();
                int origlen = (foundDataBytes != null) ?
                    foundDataBytes.length : 0;
                int oldlen = (doff + dlen > origlen) ? doff + dlen : origlen;
                int len = oldlen - dlen + data.getSize();
                newData = new byte[len];
                int pos = 0;

                /*
     * Keep 0..doff of the old data (truncating if doff > length).
     */
                int slicelen = (doff < origlen) ? doff : origlen;
                if (slicelen > 0)
                    System.arraycopy(foundDataBytes, 0, newData,
             pos, slicelen);
                pos += doff;

                /* Copy in the new data. */
                slicelen = data.getSize();
                System.arraycopy(data.getData(), data.getOffset(),
                                 newData, pos, slicelen);
                pos += slicelen;

                /* Append the rest of the old data (if any). */
                slicelen = origlen - (doff + dlen);
                if (slicelen > 0)
                    System.arraycopy(foundDataBytes, doff + dlen, newData, pos,
                                     slicelen);
            } else {
                int len = data.getSize();
                newData = new byte[len];
                System.arraycopy(data.getData(), data.getOffset(),
                                 newData, 0, len);
            }

            if (database.getSortedDuplicates()) {
    /* Check that data compares equal before replacing it. */
    boolean keysEqual = false;
    if (foundDataBytes != null) {
        keysEqual = (userComparisonFcn == null ?
         (Key.compareKeys
                                  (foundDataBytes, newData) == 0) :
         (userComparisonFcn.compare
                                  (foundDataBytes, newData) == 0));
    }
    if (!keysEqual) {
        revertLock(ln, lockResult);
        throw new DatabaseException
      ("Can't replace a duplicate with different data.");
    }
      }
      if (foundData != null) {
    setDbt(foundData, foundDataBytes);
      }
      if (foundKey != null) {
    setDbt(foundKey, foundKeyBytes);
      }

            /*
             * Between the release of the BIN latch and acquiring the write
             * lock any number of operations may have executed which would
             * result in a new abort LSN for this record. Therefore, wait until
             * now to get the abort LSN.
             */
      long oldLsn = targetBin.getLsn(targetIndex);
      lockResult.setAbortLsn
    (oldLsn, targetBin.isEntryKnownDeleted(targetIndex));

            /*
       * The modify has to be inside the latch so that the BIN is updated
       * inside the latch.
       */
            long oldLNSize = ln.getMemorySizeIncludedByParent();
      byte[] newKey = (isDup ? targetBin.getDupKey() : lnKey);
            long newLsn = ln.modify(newData, database, newKey, oldLsn, locker);
            long newLNSize = ln.getMemorySizeIncludedByParent();

            /* Update the parent BIN. */
            targetBin.updateEntry(targetIndex, newLsn, oldLNSize, newLNSize);
            releaseBINs();

View Full Code Here

            /*
             * Get a reference to the LN under the latch.  Check the deleted
             * flag in the BIN.  If fetchTarget returns null, a deleted LN was
             * cleaned.
             */
            LN ln = null;
            if (!bin.isEntryKnownDeleted(index)) {
                ln = (LN) bin.fetchTarget(index);
            }
            if (ln == null) {
    releaseBIN();
View Full Code Here

                           EnvironmentParams.ENV_RUN_CLEANER.getName(),
                           "false");
            /* Don't checkpoint utilization info for this test. */
            DbInternal.setCheckpointUP(recoveryConfig, false);
            env = new Environment(envHome, recoveryConfig);
            LN ln = new LN(new byte[0]);
           
            /* Recovery should have initialized the next node id to use */
            assertTrue(maxSeenNodeId + 1 < ln.getNodeId());
            maxSeenNodeId = Node.getLastId();

            /*
             * One more time -- this recovery will get the node id off the
             * checkpoint of the environment close. This checkpoint records
             * the fact that the node id was bumped forward by the create of
             * the LN above.
             */
            env.close();
            env = new Environment(envHome, recoveryConfig);
            ln = new LN(new byte[0]);
            /*
             * The environment re-opening will increment the node id
             * several times because of the EOF node id.
             */
            assertTrue(maxSeenNodeId+1 <= ln.getNodeId());

        } catch (Throwable t) {
            t.printStackTrace();
            throw t;
        }
View Full Code Here

    public void testBasicLocking()
        throws Throwable {

        try {

            LN ln = new LN(new byte[0]);

            /*
             * Make a null txn that will lock. Take a lock and then end the
             * operation.
             */
            EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
            MemoryBudget mb = envImpl.getMemoryBudget();
           
            long beforeLock = mb.getCacheMemoryUsage();
            Locker nullTxn = new BasicLocker(envImpl);

            LockGrantType lockGrant = nullTxn.lock
                (ln.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            assertEquals(LockGrantType.NEW, lockGrant);
            long afterLock = mb.getCacheMemoryUsage();
            checkHeldLocks(nullTxn, 1, 0);

            nullTxn.operationEnd();
            long afterRelease = mb.getCacheMemoryUsage();
            checkHeldLocks(nullTxn, 0, 0);
            checkCacheUsage(beforeLock, afterLock, afterRelease,
                            LockManager.TOTAL_LOCK_OVERHEAD +
                            MemoryBudget.LOCKINFO_OVERHEAD);

            // Take a lock, release it.
            beforeLock = mb.getCacheMemoryUsage();
            lockGrant = nullTxn.lock
                (ln.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            afterLock = mb.getCacheMemoryUsage();
            assertEquals(LockGrantType.NEW, lockGrant);
            checkHeldLocks(nullTxn, 1, 0);

            nullTxn.releaseLock(ln.getNodeId());
            checkHeldLocks(nullTxn, 0, 0);
            afterRelease = mb.getCacheMemoryUsage();
            checkCacheUsage(beforeLock, afterLock, afterRelease,
                            LockManager.TOTAL_LOCK_OVERHEAD +
                            MemoryBudget.LOCKINFO_OVERHEAD);

            /*
             * Make a user transaction, check lock and release.
             */
            beforeLock = mb.getCacheMemoryUsage();
            Txn userTxn = new Txn(envImpl, new TransactionConfig());
            lockGrant = userTxn.lock
                (ln.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            afterLock = mb.getCacheMemoryUsage();

            assertEquals(LockGrantType.NEW, lockGrant);
            checkHeldLocks(userTxn, 1, 0);

            // Try demoting, nothing should happen.
            try {
                userTxn.demoteLock(ln.getNodeId());
                fail("exception not thrown on phoney demoteLock");
            } catch (AssertionError e){
            }
            checkHeldLocks(userTxn, 1, 0);
            long afterDemotion = mb.getCacheMemoryUsage();
            assertEquals(afterLock, afterDemotion);

            // Make it a write lock, then demote.
            lockGrant = userTxn.lock
                (ln.getNodeId(), LockType.WRITE,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            assertEquals(LockGrantType.PROMOTION, lockGrant);
            long afterWriteLock = mb.getCacheMemoryUsage();
            assertTrue(afterWriteLock > afterLock);
            assertTrue(afterLock > beforeLock);

            checkHeldLocks(userTxn, 0, 1);
            userTxn.demoteLock(ln.getNodeId());
            checkHeldLocks(userTxn, 1, 0);


            // Shouldn't release at operation end
            userTxn.operationEnd();
            checkHeldLocks(userTxn, 1, 0);

            userTxn.releaseLock(ln.getNodeId());
            checkHeldLocks(userTxn, 0, 0);
            userTxn.commit(Txn.TXN_SYNC);
            afterRelease = mb.getCacheMemoryUsage();
            assertEquals(beforeLock, afterRelease);
        } catch (Throwable t) {
View Full Code Here

     */
    public void testCommit()
        throws Throwable {

        try {
            LN ln1 = new LN(new byte[0]);
            LN ln2 = new LN(new byte[0]);
                                         
            EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
            Txn userTxn = new Txn(envImpl, new TransactionConfig());

            // get read lock 1
            LockGrantType lockGrant = userTxn.lock
                (ln1.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            assertEquals(LockGrantType.NEW, lockGrant);
            checkHeldLocks(userTxn, 1, 0);

            // get read lock 2
            lockGrant = userTxn.lock
                (ln2.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            assertEquals(LockGrantType.NEW, lockGrant);
            checkHeldLocks(userTxn, 2, 0);

            // upgrade read lock 2 to a write
            lockGrant = userTxn.lock
                (ln2.getNodeId(), LockType.WRITE,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            assertEquals(LockGrantType.PROMOTION, lockGrant);
            checkHeldLocks(userTxn, 1, 1);

View Full Code Here

        Map<DatabaseId,String> dbNameMap = dbMapTree.getDbNamesAndIds();

        while (reader.readNextEntry()) {
            if (reader.isLN()) {
                LN theLN = reader.getLN();
                byte[] theKey = reader.getKey();

                DatabaseId dbId = reader.getDatabaseId();
                String dbName = dbNameMap.get(dbId);
                if (DbTree.isReservedDbName(dbName)) {
                    continue;
                }

                boolean continueScanning =
                    scanner.scanRecord(new DatabaseEntry(theKey),
                                       new DatabaseEntry(theLN.getData()),
                                       theLN.isDeleted(),
                                       dbName);
                if (!continueScanning) {
                    break;
                }
            }
View Full Code Here

  /*
   * Check the nodeid to see if we've already seen it or not.
   */
  if (entry instanceof LNLogEntry) {
      LNLogEntry lnEntry = (LNLogEntry) entry;
      LN ln = lnEntry.getLN();
      long nodeId = ln.getNodeId();
      boolean isDelDupLN =
    entryType.equals(LogEntryType.
         LOG_DEL_DUPLN_TRANSACTIONAL) ||
    entryType.equals(LogEntryType.LOG_DEL_DUPLN);

View Full Code Here

      checkProcessEntry(entry, entryType, false);

  if (processThisEntry &&
      (entry instanceof LNLogEntry)) {
      LNLogEntry lnEntry = (LNLogEntry) entry;
      LN ln = lnEntry.getLN();
      if (ln instanceof NameLN) {
    String name = new String(lnEntry.getKey());
    Integer dbId = new Integer(((NameLN) ln).getId().getId());
    if (dbIdToName.containsKey(dbId) &&
        !((String) dbIdToName.get(dbId)).equals(name)) {
View Full Code Here

  if (processThisEntry) {
      LNLogEntry lnEntry = (LNLogEntry) entry;
      Integer dbId = new Integer(lnEntry.getDbId().getId());
      PrintStream out = getOutputStream(dbId);
          
            LN ln = lnEntry.getLN();
            byte[] keyData = lnEntry.getKey();
            byte[] data = ln.getData();
            if (data != null) {
                dumpOne(out, keyData, formatUsingPrintable);
                dumpOne(out, data, formatUsingPrintable);
    if ((++flushCounter % FLUSH_INTERVAL) == 0) {
        out.flush();
View Full Code Here

TOP

Related Classes of com.sleepycat.je.tree.LN

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.