Package com.sleepycat.je.txn

Examples of com.sleepycat.je.txn.Txn$AutoTransaction


             * back or one done on the behalf of a null txn.
             */
            LogEntryType entryType;
            long logAbortLsn;
            boolean logAbortKnownDeleted;
            Txn logTxn;
            if (locker.isTransactional()) {
                entryType = LogEntryType.LOG_DEL_DUPLN_TRANSACTIONAL;
                logAbortLsn = locker.getAbortLsn(getNodeId());
                logAbortKnownDeleted =
                    locker.getAbortKnownDeleted(getNodeId());
View Full Code Here


        throws DatabaseException {

        LogEntryType entryType;
        long logAbortLsn;
  boolean logAbortKnownDeleted;
        Txn logTxn;
        if (locker != null && locker.isTransactional()) {
            entryType = getTransactionalLogType();
            logAbortLsn = locker.getAbortLsn(getNodeId());
            logAbortKnownDeleted = locker.getAbortKnownDeleted(getNodeId());
            logTxn = locker.getTxnLocker();
View Full Code Here

        long prepareId = reader.getTxnPrepareId();
        Long prepareIdL = new Long(prepareId);
        if (!committedTxnIds.contains(prepareIdL) &&
      !abortedTxnIds.contains(prepareIdL)) {
      TransactionConfig txnConf = new TransactionConfig();
      Txn preparedTxn = new Txn(env, txnConf, prepareId);
      preparedTxn.setLockTimeout(0);
      preparedTxns.put(prepareIdL, preparedTxn);
      env.getTxnManager().registerXATxn
          (reader.getTxnPrepareXid(), preparedTxn, true);
      Tracer.trace(Level.INFO, env,
             "Found unfinished prepare record: id: " +
View Full Code Here

                     * non-transactional LN, redo it.
                     */
        boolean processThisLN = false;
        boolean lnIsCommitted = false;
        boolean lnIsPrepared = false;
        Txn preparedTxn = null;
        if (txnId == null) {
      processThisLN = true;
        } else {
      lnIsCommitted = committedTxnIds.contains(txnId);
      if (!lnIsCommitted) {
          preparedTxn = (Txn) preparedTxns.get(txnId);
          lnIsPrepared = preparedTxn != null;
      }
      if (lnIsCommitted || lnIsPrepared) {
          processThisLN = true;
      }
        }
        if (processThisLN) {

                        /* Invoke the evictor to reduce memory consumption. */
                        env.invokeEvictor();

                        LN ln = reader.getLN();
                        DatabaseId dbId = reader.getDatabaseId();
                        DatabaseImpl db = dbMapTree.getDb(dbId);
                        long logLsn = reader.getLastLsn();
                        long treeLsn = DbLsn.NULL_LSN;

                        /* Database may be null if it's been deleted. */
                        if (db != null) {
                            ln.postFetchInit(db, logLsn);

          if (preparedTxn != null) {
        preparedTxn.addLogInfo(logLsn);

        /*
         * We're reconstructing a prepared, but not
         * finished, transaction.  We know that there
         * was a write lock on this LN since it exists
         * in the log under this txnId.
         */
        preparedTxn.lock(ln.getNodeId(),
             LockType.WRITE,
             db);
        preparedTxn.setPrepared(true);
          }

                            treeLsn = redo(db,
                                           location,
                                           ln,
View Full Code Here

                    abortKnownDeleted =
                        ((entryBuffer.get() & ABORT_KNOWN_DELETED_MASK) != 0) ?
                        true : false;

                    /* Locker */
                    txn = new Txn();
                    txn.readFromLog(entryBuffer, entryTypeVersion);
                }
            } else {

                /*
 
View Full Code Here

        dbConfig.setAllowCreate(true);
        db = env.openDatabase(null, "foo", dbConfig);
        LogManager logManager = envImpl.getLogManager();

        long lsn;
        Txn userTxn = new Txn(envImpl, new TransactionConfig());
        long txnId = userTxn.getId();

        for (int i = 0; i < numIters; i++) {
            /* Add a debug record just to be filler. */
            Tracer rec = new Tracer("Hello there, rec " + (i+1));
            logManager.log(rec);

            /* Make a transactional LN, we expect it to be there. */
            byte [] data = new byte[i+1];
            Arrays.fill(data, (byte)(i+1));
            LN ln = new LN(data);
            byte [] key = new byte[i+1];
            Arrays.fill(key, (byte)(i+10));
           
            /*
       * Log an LN. If we're tracking LNs add it to the verification
       * list.
       */
            userTxn.lock
                (ln.getNodeId(), LockType.WRITE,
                 DbInternal.dbGetDatabaseImpl(db));
            lsn = ln.log(envImpl,
                         DbInternal.dbGetDatabaseImpl(db).getId(),
                         key,
                         DbLsn.NULL_LSN,
                         userTxn);

            if (trackLNs) {
                checkList.add(new CheckInfo(lsn, ln, key,
                                            ln.getData(), txnId));
            }

            /* Log a deleted duplicate LN. */
            LN deleteLN = new LN(data);
            byte[] dupKey = new byte[i+1];
            Arrays.fill(dupKey, (byte)(i+2));

            userTxn.lock
                (deleteLN.getNodeId(), LockType.WRITE,
                 DbInternal.dbGetDatabaseImpl(db));
            lsn = deleteLN.delete(DbInternal.dbGetDatabaseImpl(db),
                                  key,
                                  dupKey,
                                  DbLsn.NULL_LSN,
                                  userTxn);
            if (trackLNs) {
                checkList.add(new CheckInfo(lsn, deleteLN,
                                            dupKey, key, txnId));
            }

            /*
       * Make a non-transactional ln. Shouldn't get picked up by reader.
       */
            LN nonTxnalLN = new LN(data);
            nonTxnalLN.log(envImpl,
         DbInternal.dbGetDatabaseImpl(db).getId(),
         key, DbLsn.NULL_LSN, null);

            /* Add a MapLN. */
            MapLN mapLN = new MapLN(DbInternal.dbGetDatabaseImpl(db));
            userTxn.lock
                (mapLN.getNodeId(), LockType.WRITE,
                 DbInternal.dbGetDatabaseImpl(db));
            lsn = mapLN.log(envImpl,
                            DbInternal.dbGetDatabaseImpl(db).getId(),
                            key, DbLsn.NULL_LSN, userTxn);
            if (!trackLNs) {
                checkList.add(new CheckInfo(lsn, mapLN, key,
                                            mapLN.getData(),
                                            txnId));
            }
        }

        long commitLsn = userTxn.commit(Txn.TXN_SYNC);

        /* We only expect checkpoint entries to be read in redo passes. */
        if (!redo) {
            checkList.add(new CheckInfo(commitLsn, null, null, null, txnId));
        }
View Full Code Here

     * Used to get the Transaction object given an XA Xid.
     */
    public Transaction getXATransaction(Xid xid)
  throws DatabaseException {

  Txn ret = environmentImpl.getTxnManager().getTxnFromXid(xid);
  if (ret == null) {
      return null;
  }
  /* Do we guarantee object identity for Transaction objects? */
  return new Transaction(this, ret);
View Full Code Here

            /*
             * 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) {
            /* print stack trace before going to teardown. */
            t.printStackTrace();
View Full Code Here

        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);

            // read lock 1 again, shouldn't increase count
            lockGrant = userTxn.lock
                (ln1.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            assertEquals(LockGrantType.EXISTING, lockGrant);
            checkHeldLocks(userTxn, 1, 1);

            // Shouldn't release at operation end
            long commitLsn = userTxn.commit(Txn.TXN_SYNC);
            checkHeldLocks(userTxn, 0, 0);

            TxnCommit commitRecord =
                (TxnCommit) envImpl.getLogManager().get(commitLsn);

            assertEquals(userTxn.getId(), commitRecord.getId());
            assertEquals(userTxn.getLastLsn(), commitRecord.getLastLsn());
        } catch (Throwable t) {
            /* print stack trace before going to teardown. */
            t.printStackTrace();
            throw t;
        }
View Full Code Here

        boolean isDelDup = (delDupKey != null);
        LogEntryType entryType;
        long logAbortLsn;
        boolean logAbortKnownDeleted;
        Txn logTxn;
        LogContext context = new LogContext();

        if (locker != null && locker.isTransactional()) {
            entryType = isDelDup ?
                LogEntryType.LOG_DEL_DUPLN_TRANSACTIONAL :
View Full Code Here

TOP

Related Classes of com.sleepycat.je.txn.Txn$AutoTransaction

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.