Package com.sleepycat.je.tree

Examples of com.sleepycat.je.tree.LN


        throws DatabaseException {

        assert assertCursorState(false) : dumpToString(true);

        OperationStatus result = putLN
            (Key.makeKey(key), new LN(data), database.getSortedDuplicates());
        if (result == OperationStatus.KEYEXIST) {
            status = CURSOR_INITIALIZED;

            /*
             * If dups are allowed and putLN() returns KEYEXIST, the duplicate
View Full Code Here


            DatabaseEntry data)
        throws DatabaseException {

        assert assertCursorState(false) : dumpToString(true);

        return putLN(Key.makeKey(key), new LN(data), false);
    }
View Full Code Here

        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) {
                releaseBINs();
    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) {
                releaseBINs();
    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;
      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();

    if (len == 0) {
        newData = LogUtils.ZERO_LENGTH_BYTE_ARRAY;
    } else {
        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();
    if (len == 0) {
        newData = LogUtils.ZERO_LENGTH_BYTE_ARRAY;
    } else {
        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 = Key.compareKeys
                        (foundDataBytes, newData, userComparisonFcn) == 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

                            }
                        } else {
                            foundSomething = true;
                            if (!containsDuplicates && exactSearch) {
        /* Lock LN, check if deleted. */
        LN ln = (LN) n;
        LockResult lockResult = lockLN(ln, lockType);
        ln = lockResult.getLN();

        if (ln == null) {
            foundSomething = false;
View Full Code Here

                    found = !exactSearch;
                }
            }
        } else {
      /* Not a duplicate, but checking for both key and data match. */
            LN ln = (LN) n;

      /* Lock LN, check if deleted. */
      LockResult lockResult = lockLN(ln, lockType);
      ln = lockResult.getLN();

      if (ln == null) {
                found = !exactSearch;
      } else {

    /* Don't set abort LSN for read operation. [#13158] */
    dupBin = null;
    dupIndex = -1;

                /*
                 * The comparison logic below mimics IN.findEntry as used above
                 * for duplicates.
                 */
    int cmp = Key.compareKeys
                    (ln.getData(), data, database.getDuplicateComparator());
                if (cmp == 0 || (cmp <= 0 && !exactSearch)) {
                    if (cmp == 0) {
                        exact = true;
                    }
                    found = true;
View Full Code Here

            } else {
                return OperationStatus.NOTFOUND;
            }
        }

        LN ln = (LN) n;

  assert TestHookExecute.doHookIfSet(testHook);

        /*
         * Lock the LN.  For dirty-read, the data of the LN can be set to null
         * at any time.  Cache the data in a local variable so its state does
         * not change before calling setDbt further below.
         */
  LockResult lockResult = lockLN(ln, lockType);
  try {
            ln = lockResult.getLN();
            byte[] lnData = (ln != null) ? ln.getData() : null;
            if (ln == null || lnData == null) {
                if (treeStatsAccumulator != null) {
                    treeStatsAccumulator.incrementDeletedLNCount();
                }
                return OperationStatus.KEYEMPTY;
View Full Code Here

                }

                /* The entry is not known to be obsolete -- process it now. */
                if (isLN) {

                    LN targetLN = reader.getLN();
                    DatabaseId dbId = reader.getDatabaseId();
                    byte[] key = reader.getKey();
                    byte[] dupKey = reader.getDupTreeKey();

                    lookAheadCache.add
View Full Code Here

        /* Get the first LN from the queue. */
        Long offset = lookAheadCache.nextOffset();
        LNInfo info = lookAheadCache.remove(offset);

        LN ln = info.getLN();
        byte[] key = info.getKey();
        byte[] dupKey = info.getDupKey();

        long logLsn = DbLsn.makeLsn
            (fileNum.longValue(), offset.longValue());

        DatabaseImpl db = env.getDbMapTree().getDb
            (info.getDbId(), cleaner.lockTimeout, dbCache);

        /* Status variables are used to generate debug tracing info. */
        boolean processedHere = true; // The LN was cleaned here.
        boolean obsolete = false;     // The LN is no longer in use.
        boolean completed = false;    // This method completed.

        BIN bin = null;
        DIN parentDIN = null;      // for DupCountLNs
        try {

            /*
             * If the DB is gone, this LN is obsolete.  If delete cleanup is in
             * progress, put the DB into the DB pending set; this LN will be
             * declared deleted after the delete cleanup is finished.
             */
            if (db == null || db.isDeleted()) {
                cleaner.addPendingDB(db);
                nLNsDeadThisRun++;
                obsolete = true;
                completed = true;
                return;
            }

            Tree tree = db.getTree();
            assert tree != null;

            /*
       * Search down to the bottom most level for the parent of this LN.
       */
            boolean parentFound = tree.getParentBINForChildLN
                (location, key, dupKey, ln,
                 false,  // splitsAllowed
                 true,   // findDeletedEntries
                 false,  // searchDupTree
                 Cleaner.UPDATE_GENERATION);
            bin = location.bin;
            int index = location.index;

            if (!parentFound) {
                nLNsDeadThisRun++;
    obsolete = true;
                completed = true;
    return;
            }

      /*
       * Now we're at the parent for this LN, whether BIN, DBIN or DIN.
       * If knownDeleted, LN is deleted and can be purged.
       */
      if (bin.isEntryKnownDeleted(index)) {
    nLNsDeadThisRun++;
    obsolete = true;
    completed = true;
                return;
      }

            /*
             * Determine whether the parent is the current BIN, or in the case
             * of a DupCountLN, a DIN.  Get the tree LSN in either case.
             */
            boolean isDupCountLN = ln.containsDuplicates();
            long treeLsn;
      if (isDupCountLN) {
    parentDIN = (DIN) bin.fetchTarget(index);
    parentDIN.latch(Cleaner.UPDATE_GENERATION);
                ChildReference dclRef = parentDIN.getDupCountLNRef();
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.