Package com.sleepycat.je.txn

Examples of com.sleepycat.je.txn.Locker


        if (dbHandle != null) {
            dbHandle.checkOpen("Can't access Database:");
        }

        /* Do not allow auto-commit when creating a user cursor. */
        Locker locker = LockerFactory.getReadableLocker
            (dbHandle.getEnvironment(),
             txn,
             dbHandle.isTransactional(),
             cursorConfig.getReadCommitted());

View Full Code Here


        assert key != null;
        assert ln != null;
        assert putMode != null;
        assert putMode != PutMode.CURRENT;

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

        if (owners == null) {
            return;
        }
        /* Acquire newLsn locks. */
        for (LockInfo lockInfo : owners) {
            final Locker locker = lockInfo.getLocker();
            if (locker != excludeLocker) {
                locker.lockAfterLsnChange(oldLsn, newLsn, dbImpl);
            }
        }
        /* Release oldLsn locks. */
        for (LockInfo lockInfo : owners) {
            final Locker locker = lockInfo.getLocker();
            if (locker != excludeLocker &&
                locker.allowReleaseLockAfterLsnChange()) {
                locker.releaseLock(oldLsn);
            }
        }
    }
View Full Code Here

                                            WithCursor withCursor)
        throws DatabaseException {

        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry data = new DatabaseEntry();
        Locker locker = null;
        CursorImpl cursor = null;
        try {
            EnvironmentImpl envImpl = db.getDbEnvironment();
            locker = LockerFactory.getInternalReadOperationLocker(envImpl);
            cursor = new CursorImpl(db, locker);
            cursor.setAllowEviction(allowEviction);
            if (cursor.positionFirstOrLast(true /*first*/)) {
                OperationStatus status =
                    cursor.getCurrentAlreadyLatched(key, data, lockType);
                boolean done = false;
                while (!done) {

                    /*
                     * getCurrentAlreadyLatched may have returned non-SUCCESS
                     * if the first record is deleted, but we can call getNext
                     * below to move forward.
                     */
                    if (status == OperationStatus.SUCCESS) {
                        if (!withCursor.withCursor(cursor, key, data)) {
                            done = true;
                        }
                    }
                    if (!done) {
                        status = cursor.getNext(key, data, lockType,
                                                true /*forward*/,
                                                false /*alreadyLatched*/,
                                                null /*rangeConstraint*/);
                        if (status != OperationStatus.SUCCESS) {
                            done = true;
                        }
                    }
                }
            }
        } finally {
            if (cursor != null) {
                cursor.releaseBIN();
                cursor.close();
            }
            if (locker != null) {
                locker.operationEnd();
            }
        }
    }
View Full Code Here

        this.db = db;
        this.key = copyEntry(key);
        logger = db.getEnvironment().getEnvironmentImpl().getLogger();

        /* Perform an auto-commit transaction to create the sequence. */
        Locker locker = null;
        Cursor cursor = null;
        OperationStatus status = OperationStatus.NOTFOUND;
        try {
            locker = LockerFactory.getReadableLocker
                (db.getEnvironment(), txn,
                 db.isTransactional(),
                 false /*readCommitedIsolation*/);

            cursor = new Cursor(db, locker, null);

            boolean sequenceExists = readData(cursor, null);
            boolean isWritableLocker = !db.getConfig().getTransactional() ||
                (locker.isTransactional() &&
                 !DbInternal.getEnvironmentImpl(db.getEnvironment()).
                 isReplicated());

            if (sequenceExists) {
                if (useConfig.getAllowCreate() &&
                    useConfig.getExclusiveCreate()) {
                    throw new SequenceExistsException
                       ("ExclusiveCreate=true and the sequence record " +
                        "already exists.");
                }
            } else {
                if (useConfig.getAllowCreate()) {
                    if (!isWritableLocker) {
                        if (cursor != null) {
                            cursor.close();
                        }
                        locker.operationEnd(OperationStatus.SUCCESS);

                        locker = LockerFactory.getWritableLocker
                            (db.getEnvironment(),
                             txn,
                             db.getDatabaseImpl().isInternalDb(),
                             db.isTransactional(),
                             db.getDatabaseImpl().isReplicated(),
                             autoCommitConfig);
                        cursor = new Cursor(db, locker, null);
                    }

                    /* Get the persistent fields from the config. */
                    rangeMin = useConfig.getRangeMin();
                    rangeMax = useConfig.getRangeMax();
                    increment = !useConfig.getDecrement();
                    wrapAllowed = useConfig.getWrap();
                    storedValue = useConfig.getInitialValue();

                    /*
                     * To avoid dependence on SerializableIsolation, try
                     * putNoOverwrite first.  If it fails, then try to get an
                     * existing record.
                     */
                    status = cursor.putNoOverwrite(key, makeData());

                    if (!readData(cursor, null)) {
                        /* A retry loop should be performed here. */
                        throw new IllegalStateException
                            ("Sequence record removed during openSequence.");
                    }
                    status = OperationStatus.SUCCESS;
                } else {
                    throw new SequenceNotFoundException
                        ("AllowCreate=false and the sequence record " +
                         "does not exist.");
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (locker != null) {
                locker.operationEnd(status);
            }
        }

        /*
         * cacheLast is initialized such that the cache will be considered
View Full Code Here

        /* Get the DatabaseId for all synced databases. */
        SyncDataSet dataSet = processor.getDataSets().get(dataSetName);
        Iterator<SyncDatabase> databases = dataSet.getDatabases().iterator();

        while (databases.hasNext()) {
            Locker readLocker = null;
            boolean operationOK = false;
            DatabaseImpl dbImpl = null;
            String dbName = databases.next().getLocalName();

            try {
                readLocker = LockerFactory.getReadableLocker
                    (env, null,
                     false, /* transactional */
                     false /* readCommittedIsolation */);

                dbImpl = envImpl.getDbTree().getDb(readLocker, dbName, null);
                if (dbImpl != null) {
                    syncDbs.put(dbImpl.getId(),
                                new DbInfo(dbName,
                                           dbImpl.getSortedDuplicates()));
                }
                operationOK = true;
            } finally {
                if (dbImpl != null) {
                    envImpl.getDbTree().releaseDb(dbImpl);
                }

                if (readLocker != null) {
                    readLocker.operationEnd(operationOK);
                }
            }
        }
    }
View Full Code Here

        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry data = new DatabaseEntry();
        LongBinding.longToEntry(VLSNRange.RANGE_KEY, key);

        Cursor cursor = null;
        Locker locker = null;
        try {
            locker = BasicLocker.createBasicLocker(envImpl);
            cursor = DbInternal.makeCursor(mappingDbImpl,
                                           locker,
                                           CursorConfig.DEFAULT);
            DbInternal.getCursorImpl(cursor).setAllowEviction(false);

            OperationStatus status = cursor.getSearchKey(key, data,
                                                         LockMode.DEFAULT);
            if (status == OperationStatus.SUCCESS) {
                /* initialize the range from the database. */
                VLSNRangeBinding rangeBinding = new VLSNRangeBinding();
                range = rangeBinding.entryToObject(data);
                lastOnDiskVLSN = range.getLast();
            } else if (status == OperationStatus.NOTFOUND) {
                /* No mappings exist before. */
                range = VLSNRange.EMPTY;
            } else {
                throw EnvironmentFailureException.unexpectedState
                    ("VLSNTracker init: status=" + status);
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }

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

                           DataType dataType,
                           OpType opType) {
        /* This method can only be invoked when env is not null. */
        assert env != null;

        Locker locker = null;
        Cursor cursor = null;
        boolean operationOK = false;

        try {
            locker = LockerFactory.getWritableLocker
                (env, txn, true /*isInternalDb*/, dbImpl.isTransactional(),
                 dbImpl.isReplicated());
            cursor = makeCursor(locker);

            DatabaseEntry key = new DatabaseEntry();
            StringBinding.stringToEntry
                (generateKey(processorName, dataSetName, dataType), key);

            DatabaseEntry oldData = new DatabaseEntry();
            cursor.getSearchKey(key, oldData, null);

            if (dataType == DataType.CHANGE_SET) {
                checkUsageErrors(oldData, opType, dataSetName);
            }

            OperationStatus status = null;
            if (opType == OpType.DELETE) {
                status = cursor.delete();
            } else {
                status = cursor.put(key, data);
            }

            assert status == OperationStatus.SUCCESS;
           
            operationOK = true;
        } finally {
            if (cursor != null) {
                cursor.close();
                cursor = null;
            }

            if (locker != null) {
                locker.operationEnd(operationOK);
            }
        }
    }
View Full Code Here

                          DatabaseEntry data,
                          DataType dataType) {
        /* This method can only be invoked when env is not null. */
        assert env != null;

        Locker locker = null;
        Cursor cursor = null;
        boolean operationOK = false;

        try {
            locker = LockerFactory.getReadableLocker
                (env, txn, dbImpl.isTransactional(), false /*readCommitted*/);
            cursor = makeCursor(locker);

            DatabaseEntry key = new DatabaseEntry();
            StringBinding.stringToEntry
                (generateKey(processorName, dataSetName, dataType), key);

            OperationStatus status =
                cursor.getSearchKey(key, data, null);

            /*
             * Read operations should be either succeed or read a non-existing
             * key.
             */
            assert data.getData() == null || status == OperationStatus.SUCCESS;

            operationOK = true;
        } finally {
            if (cursor != null) {
                cursor.close();
                cursor = null;
            }

            if (locker != null) {
                locker.operationEnd(operationOK);
            }
        }
    }
View Full Code Here

                                                      Environment env) {
        if (dbImpl == null) {
            return null;
        }

        Locker locker = null;
        boolean operationOK = false;
        Map<String, DatabaseEntry> readData =
            new HashMap<String, DatabaseEntry>();

        try {
            locker = LockerFactory.getReadableLocker
                (env, null, dbImpl.isTransactional(), false);
           
            Cursor cursor = makeCursor(locker);
           
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry data = new DatabaseEntry();

            while (OperationStatus.SUCCESS ==
                   cursor.getNext(key, data, null)) {
                String keyName = StringBinding.entryToString(key);
                if (DataType.getDataType(keyName).equals(dataType)) {
                    readData.put(keyName, data);
                }
                data = new DatabaseEntry();
            }

            operationOK = true;
        } finally {
            if (locker != null) {
                locker.operationEnd(operationOK);
            }
        }

        return readData;
    }                                                     
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.