Package com.sleepycat.je.txn

Examples of com.sleepycat.je.txn.Locker


     */
    public void testGetFirstLast()
  throws DatabaseException {

        initEnv(true);
        Locker txn = new BasicLocker(DbInternal.envGetEnvironmentImpl(env));
        NullCursor cursor = new NullCursor(tree.getDatabase(), txn);

  /* Make sure IllegalArgumentException is thrown for null args. */
        try {
            TestUtils.checkLatchCount();
            tree.getFirstNode(null);
            fail("Tree.getFirstNode didn't throw IllegalArgumentException");
        } catch (IllegalArgumentException IAE) {
        }
        TestUtils.checkLatchCount();

        try {
            TestUtils.checkLatchCount();
            tree.getLastNode(null);
            fail("Tree.getLastNode didn't throw IllegalArgumentException");
        } catch (IllegalArgumentException IAE) {
        }
        TestUtils.checkLatchCount();

        byte[][] keys = new byte[N_TOP_LEVEL_KEYS][];
        LN[][] lns = new LN[N_TOP_LEVEL_KEYS][];
  byte[][] minKeys = new byte[N_TOP_LEVEL_KEYS][];
  byte[][] maxKeys = new byte[N_TOP_LEVEL_KEYS][];
        for (int i = 0; i < N_TOP_LEVEL_KEYS; i++) {
            byte[] key = new byte[N_KEY_BYTES];
      byte[] minKey = null;
      byte[] maxKey = null;
            keys[i] = key;
      lns[i] = new LN[N_DUPLICATES_PER_KEY];
            TestUtils.generateRandomAlphaBytes(key);
      for (int j = 0; j < N_DUPLICATES_PER_KEY; j++) {
    byte[] data = new byte[N_KEY_BYTES];
    TestUtils.generateRandomAlphaBytes(data);
    byte[] dupKey = data;

    if (minKey == null) {
        minKey = dupKey;
    } else if (Key.compareKeys(dupKey, minKey) < 0) {
        minKey = dupKey;
    }

    if (maxKey == null) {
        maxKey = dupKey;
    } else if (Key.compareKeys(maxKey, dupKey) < 0) {
        maxKey = dupKey;
    }

    LN ln = new LN(data);
    lns[i][j] = ln;
    insertAndRetrieveDuplicate(key, ln, cursor);
      }
      minKeys[i] = minKey;
      maxKeys[i] = maxKey;
        }

        for (int i = 0; i < N_TOP_LEVEL_KEYS; i++) {
      byte[] key = keys[i];
      for (int j = 0; j < N_DUPLICATES_PER_KEY; j++) {
    validateFirstLast(key, minKeys[i], maxKeys[i]);
      }
        }
        txn.operationEnd();
    }
View Full Code Here


        if (cursorConfig == null) {
            cursorConfig = CursorConfig.DEFAULT;
        }

        Locker locker = LockerFactory.getReadableLocker
            (dbHandle.getEnvironment(),
             txn,
             dbHandle.isTransactional(),
             false,  // retainNonTxnLocks
             cursorConfig.getReadCommitted());
View Full Code Here

        DatabaseEntry data,
                                PutMode putMode,
                                DatabaseEntry returnOldData)
        throws DatabaseException {

        Locker nextKeyLocker = null;
        CursorImpl nextKeyCursor = null;
        try {
            /* If other transactions are serializable, lock the next key. */
            Locker cursorLocker = cursorImpl.getLocker();
            if (putMode != PutMode.CURRENT &&
                dbImpl.getDbEnvironment()
                      .getTxnManager()
                      .areOtherSerializableTransactionsActive(cursorLocker)) {
                nextKeyLocker = new BuddyLocker
View Full Code Here

         * Check that the open configuration doesn't conflict with the
         * environmentImpl configuration.
         */
        validateDbConfigAgainstEnv(dbConfig, databaseName);

        Locker locker = null;
        boolean operationOk = false;
  boolean dbIsClosing = false;
        try {

            /*
             * Does this database exist? Get a transaction to use. If the
             * database exists already, we really only need a readable locker.
             * If the database must be created, we need a writable one.
             * Unfortunately, we have to get the readable one first before we
             * know whether we have to create.  However, if we need to write
             * during initialization (to populate a secondary for example),
             * then just create a writable locker now.
             */
            boolean isWritableLocker;
            if (needWritableLockerForInit) {
                locker = LockerFactory.getWritableLocker
                    (this,
                     txn,
                     dbConfig.getTransactional(),
                     true,  // retainNonTxnLocks
                     null);
                isWritableLocker = true;
            } else {
                locker = LockerFactory.getReadableLocker
                    (this, txn,
                     dbConfig.getTransactional(),
                     true,   // retainNonTxnLocks
                     false); // readCommittedIsolation
                isWritableLocker = !dbConfig.getTransactional() ||
                                   locker.isTransactional();
            }

            DatabaseImpl database = environmentImpl.getDb(locker,
                                                          databaseName,
                                                          newDb);
            boolean databaseExists =
                (database == null) ? false :
                ((database.getIsDeleted()) ? false : true);

            if (databaseExists) {
                if (dbConfig.getAllowCreate() &&
                    dbConfig.getExclusiveCreate()) {
                    /* We intended to create this, but it already exists. */
        dbIsClosing = true;
                    throw new DatabaseException
                        ("Database " + databaseName + " already exists");
                }

                newDb.initExisting(this, locker, database, dbConfig);
            } else {
                /* No database. Create if we're allowed to. */
                if (dbConfig.getAllowCreate()) {

                    /*
                     * We're going to have to do some writing. Switch to a
                     * writable locker if we don't already have one.
                     */
                    if (!isWritableLocker) {
                        locker.operationEnd(OperationStatus.SUCCESS);
                        locker = LockerFactory.getWritableLocker
                            (this,
                             txn,
                             dbConfig.getTransactional(),
                             true,  // retainNonTxnLocks
                             null);
                        isWritableLocker  = true;
                    }

                    newDb.initNew(this, locker, databaseName, dbConfig);
                } else {
                    /* We aren't allowed to create this database. */
                    throw new DatabaseNotFoundException("Database " +
                                                        databaseName +
                                                        " not found.");
                }
            }

            operationOk = true;
            addReferringHandle(newDb);
        } finally {

            /*
             * Tell the transaction that this operation is over. Some types of
             * transactions (BasicLocker and AutoTxn) will actually finish. The
             * transaction can decide if it is finishing and if it needs to
             * transfer the db handle lock it owns to someone else.
             */
            if (locker != null) {
                locker.setHandleLockOwner(operationOk, newDb, dbIsClosing);
                locker.operationEnd(operationOk);
            }
        }
    }
View Full Code Here

        checkHandleIsValid();
        checkEnv();
        DatabaseUtil.checkForNullParam(databaseName, "databaseName");

        Locker locker = null;
        boolean operationOk = false;
        try {

            /*
             * Note: use env level isTransactional as proxy for the db
             * isTransactional.
             */
            locker = LockerFactory.getWritableLocker
                        (this, txn,
                         environmentImpl.isTransactional(),
                         true /*retainNonTxnLocks*/,
                         null);
            environmentImpl.dbRemove(locker, databaseName);
            operationOk = true;
        } finally {
            if (locker != null) {
                locker.operationEnd(operationOk);
            }
        }
    }
View Full Code Here

        DatabaseUtil.checkForNullParam(newName, "newName");

        checkHandleIsValid();
        checkEnv();

        Locker locker = null;
        boolean operationOk = false;
        try {

            /*
             * Note: use env level isTransactional as proxy for the db
             * isTransactional.
             */
            locker = LockerFactory.getWritableLocker
                        (this, txn,
                         environmentImpl.isTransactional(),
                         true /*retainNonTxnLocks*/,
                         null);
            environmentImpl.dbRename(locker, databaseName, newName);
            operationOk = true;
        } finally {
            if (locker != null) {
                locker.operationEnd(operationOk);
            }
        }
    }
View Full Code Here

        checkHandleIsValid();
        checkEnv();
        DatabaseUtil.checkForNullParam(databaseName, "databaseName");

        Locker locker = null;
        boolean operationOk = false;
        long count = 0;
        try {

            /*
             * Note: use env level isTransactional as proxy for the db
             * isTransactional.
             */
            locker = LockerFactory.getWritableLocker
                        (this, txn,
                         environmentImpl.isTransactional(),
                         true /*retainNonTxnLocks*/,
                         null);
           
            /*
             * Currently, returnCount is unused. We need to count
             * in order to update the LN utilization.
             */
            count = environmentImpl.truncate(locker, databaseName);

            operationOk = true;
        } finally {
            if (locker != null) {
                locker.operationEnd(operationOk);
            }
        }
        return count;
    }
View Full Code Here

        db = env.openDatabase(null, DB_NAME, dbConfig);

        addRecords(start, end);

        /* Now reach into the tree and get the first BIN */
        Locker txn = new BasicLocker(DbInternal.envGetEnvironmentImpl(env));
        CursorImpl internalCursor = new CursorImpl(DbInternal.dbGetDatabaseImpl(db),
               txn);
        assertTrue(internalCursor.positionFirstOrLast(true, null));
        BIN firstBIN = internalCursor.getBIN();
        firstBIN.releaseLatch();
        internalCursor.close();
        txn.operationEnd();
        return firstBIN;
    }
View Full Code Here

     * Rudimentary insert/retrieve test.
     */
    public void testSimpleTreeCreation()
  throws DatabaseException {
        initEnv(false);
        Locker txn = new BasicLocker(DbInternal.envGetEnvironmentImpl(env));
        NullCursor cursor = new NullCursor(tree.getDatabase(), txn);
        insertAndRetrieve(cursor, "aaaaa".getBytes(),
                          new LN((byte[]) null));
        insertAndRetrieve(cursor, "aaaab".getBytes(),
                          new LN((byte[]) null));
        insertAndRetrieve(cursor, "aaaa".getBytes(),
                          new LN((byte[]) null));
        insertAndRetrieve(cursor, "aaa".getBytes(),
                          new LN((byte[]) null));
        txn.operationEnd();
    }
View Full Code Here

   * Set the seed to reproduce a specific problem found while debugging:
         * IN.split was splitting with the identifier key being on the right
         * side.
   */
        initEnv(false);
        Locker txn = new BasicLocker(DbInternal.envGetEnvironmentImpl(env));
        NullCursor cursor = new NullCursor(tree.getDatabase(), txn);
        for (int i = 0; i < 21; i++) {
            byte[] key = new byte[N_KEY_BYTES];
            TestUtils.generateRandomAlphaBytes(key);
            insertAndRetrieve(cursor, key, new LN((byte[]) null));
        }
        txn.operationEnd();
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.txn.Locker

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.