Package com.sleepycat.je

Examples of com.sleepycat.je.Cursor$KeyChangeStatus


     * For debugging and unit tests
     * @throws DatabaseException
     */
    public Map<VLSN, Long> dumpDb(boolean display) {

        Cursor cursor = null;
        Locker locker = null;
        if (display) {
            System.out.println(tracker);
        }

        Map<VLSN, Long> mappings = new HashMap<VLSN, Long>();

        try {
            locker = BasicLocker.createBasicLocker(envImpl);
            cursor = makeCursor(locker);

            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry data = new DatabaseEntry();

            /*
             * The first item in the database is the VLSNRange. All subsequent
             * items are VLSNBuckets.
             */
            int count = 0;
            while (cursor.getNext(key, data, LockMode.DEFAULT) ==
                   OperationStatus.SUCCESS) {

                Long keyValue = LongBinding.entryToLong(key);

                if (display) {
                    System.out.println("key => " + keyValue);
                }
                if (count == 0) {
                    VLSNRange range = VLSNRange.readFromDatabase(data);
                    if (display) {
                        System.out.println("range =>");
                        System.out.println(range);
                    }
                } else {
                    VLSNBucket bucket = VLSNBucket.readFromDatabase(data);
                    for (long i = bucket.getFirst().getSequence();
                         i <= bucket.getLast().getSequence();
                         i++) {
                        VLSN v = new VLSN(i);
                        long lsn = bucket.getLsn(v);

                        if (lsn != DbLsn.NULL_LSN) {
                            mappings.put(v, lsn);
                        }
                    }
                    if (display) {
                        System.out.println("bucket =>");
                        System.out.println(bucket);
                    }
                }
                count++;
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }

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


        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setReadOnly(true);
        Database db = env.openDatabase
            (null, DbType.VLSN_MAP.getInternalName(), dbConfig);
        Cursor cursor = null;
        try {
            if (verbose) {
                System.out.println("Verifying VLSN index");
            }

            cursor = db.openCursor(null, CursorConfig.READ_COMMITTED);

            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry data = new DatabaseEntry();

            /*
             * The first item in the database is the VLSNRange. All subsequent
             * items are VLSNBuckets.
             */
            int count = 0;
            VLSNRange range = null;
            VLSNBucket lastBucket = null;
            Long lastKey = null;
            VLSN firstVLSNSeen = VLSN.NULL_VLSN;
            VLSN lastVLSNSeen = VLSN.NULL_VLSN;
            while (cursor.getNext(key, data, null) ==
                   OperationStatus.SUCCESS) {

                Long keyValue = LongBinding.entryToLong(key);

                if (count == 0) {
                    if (keyValue != VLSNRange.RANGE_KEY) {
                        out.println("Wrong key value for range! " + range);
                    }
                    range = VLSNRange.readFromDatabase(data);
                    if (verbose) {
                        out.println("range=>" + range);
                    }
                } else {
                    VLSNBucket bucket = VLSNBucket.readFromDatabase(data);
                    if (verbose) {
                        out.print("key=> " + keyValue);
                        out.println(" bucket=>" + bucket);
                    }

                    if (lastBucket != null) {
                        if (lastBucket.getLast().compareTo(bucket.getFirst())
                            >= 0) {
                            out.println("Buckets out of order.");
                            out.println("Last = " + lastKey + "/" +
                                        lastBucket);
                            out.println("Current = " + keyValue + "/" +
                                        bucket);
                        }
                    }

                    lastBucket = bucket;
                    lastKey = keyValue;
                    if ((firstVLSNSeen != null) && firstVLSNSeen.isNull()) {
                        firstVLSNSeen = bucket.getFirst();
                    }
                    lastVLSNSeen = bucket.getLast();
                }
                count++;
            }

            if (count == 0) {
                out.println("VLSNIndex not on disk");
                return;
            }

            if (firstVLSNSeen.compareTo(range.getFirst()) != 0) {
                out.println("First VLSN in bucket = " + firstVLSNSeen +
                            " and doesn't match range " + range.getFirst());
            }

            if (lastVLSNSeen.compareTo(range.getLast()) != 0) {
                out.println("Last VLSN in bucket = " + lastVLSNSeen +
                            " and doesn't match range " + range.getLast());
            }

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

            db.close();
        }
    }
View Full Code Here

        VLSNRange dbRange = null;
        ArrayList<VLSN> firstVLSN = new ArrayList<VLSN>();
        ArrayList<VLSN> lastVLSN = new ArrayList<VLSN>();
        final Locker locker = BasicLocker.createBasicLocker(envImpl);
        Cursor cursor = null;

        /*
         * Synchronize so we don't try to verify while the checkpointer
         * thread is calling flushToDatabase on the vlsnIndex.
         */
        synchronized (flushSynchronizer) {
            /*
             * Read the on-disk range and buckets.
             * -The tracker and the database buckets should not intersect.
             * -The on-disk range should be a subset of the tracker range.
             */
            try {
                cursor = makeCursor(locker);

                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry data = new DatabaseEntry();

                /*
                 * Read the on-disk range and all the buckets.
                 */
                OperationStatus status =
                    cursor.getFirst(key, data, LockMode.DEFAULT);
                if (status == OperationStatus.SUCCESS) {
                    VLSNRangeBinding rangeBinding = new VLSNRangeBinding();
                    dbRange = rangeBinding.entryToObject(data);

                    /* Collect info about the  buckets. */
                    while (cursor.getNext(key, data, LockMode.DEFAULT) ==
                           OperationStatus.SUCCESS) {

                        VLSNBucket bucket = VLSNBucket.readFromDatabase(data);

                        Long keyValue = LongBinding.entryToLong(key);
                        if (bucket.getFirst().getSequence() != keyValue) {
                            return false;
                        }

                        firstVLSN.add(bucket.getFirst());
                        lastVLSN.add(bucket.getLast());
                    }
                }
            } finally {
                if (cursor != null) {
                    cursor.close();
                }

                locker.operationEnd(true);
            }

View Full Code Here

     * Disable critical eviction for all VLSNIndex cursors. [#18475] An
     * improvement would be to enable eviction, and do all database operations
     * that are in a loop asynchronously.
     */
    private Cursor makeCursor(Locker locker) {
        Cursor cursor = DbInternal.makeCursor(mappingDbImpl,
                                              locker,
                                              CursorConfig.DEFAULT);
        DbInternal.getCursorImpl(cursor).setAllowEviction(false);
        return cursor;
    }
View Full Code Here

       
        /*
         * window represents a BlockSize window into db. Initialize it to
         * represent the block starting at the first key in db.
         */
        Cursor cursor = db.openCursor(null, null);

        long pos = 1;
        int numKeys = cfg.getBlockSize();
        Window window = new Window(cursor, numKeys);

        int errors = 0;
        int maxerrors = cfg.getMaxErrors();
        tracker = new DiffTracker(numKeys);
        while (window.getChecksum() != 0 && blkBag.size() > 0) {

            /*
             * Find the block in the bag whose checksum and md5 match the
             * current window. This block, if it exists, is match.
             */
            Block match = findMatch(db.getEnvironment(), blkBag, window);
            if (match != null) {
                tracker.setBlockDiffBegin
                    (blkBag.getBlock(), blkBag.getBlockIndex());
                /* Remove match and any earlier blocks from the bag. */
                List<Block> removed = blkBag.remove(match);
                if (removed != null) {
                    identical = false;
                    errors += removed.size();
                    tracker.calBlockDiffSize(blkBag.getBlockIndex());
                    if (maxerrors > 0 && errors >= maxerrors) {
                        break;
                    }
                }

                tracker.addDiffRegion(window);

                /* Advance the window beyond the just matched block. */
                window.nextWindow();
                pos += window.size();

                continue;
            }

            identical = false;
            LoggerUtils.envLogMsg
                (Level.FINE,
                 DbInternal.getEnvironmentImpl(db.getEnvironment()),
                 "Unmatched block at position " + pos);
            errors++;
            if (maxerrors > 0 && errors >= maxerrors) {
                break;
            }

            /* Roll the window forward by one key. */
            window.rollWindow();

            if (window.getChecksum() != 0) {
                pos++;
            }
        }

        cursor.close();

        if (window.getChecksum() != 0) {

            /*
             * We ran out of blocks in blkBag before we got to the end of db.
View Full Code Here

    private static void preload(Environment env, String dbName)
        throws Exception {

        System.out.println("Preload starting");
        Database db = env.openDatabase(null, dbName, null);
        Cursor cursor = db.openCursor(null, null);
        try {
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry data = new DatabaseEntry();
            int count = 0;
            while (cursor.getNext(key, data, LockMode.DEFAULT) ==
                   OperationStatus.SUCCESS) {
                count++;
                if ((count % 50000) == 0) {
                    System.out.println(count + "...");
                }
            }
            System.out.println("Preloaded " + count + " records");
        } finally {
            cursor.close();
            db.close();
        }
    }
View Full Code Here

        if (dbConfig.getTransactional()) {
            txn = env.beginTransaction(null, autoCommitTxnConfig);
            cursorConfig = CursorConfig.READ_COMMITTED;
        }

        Cursor cursor = null;
        int nWritten = 0;
        try {
            cursor = db.openCursor(txn, cursorConfig);
            OperationStatus status = cursor.getFirst(key, data, null);
            while (status == OperationStatus.SUCCESS) {
                boolean oneWritten = false;
                if (evolveNeeded(key, data, binding)) {
                    cursor.putCurrent(data);
                    oneWritten = true;
                    nWritten += 1;
                }
                /* Update event stats, even if no listener. [#17024] */
                EvolveInternal.updateEvent
                    (event, entityClassName, 1, oneWritten ? 1 : 0);
                if (listener != null) {
                    if (!listener.evolveProgress(event)) {
                        break;
                    }
                }
                if (txn != null && nWritten >= WRITES_PER_TXN) {
                    cursor.close();
                    cursor = null;
                    txn.commit();
                    txn = null;
                    txn = env.beginTransaction(null, autoCommitTxnConfig);
                    cursor = db.openCursor(txn, cursorConfig);
                    DatabaseEntry saveKey = KeyRange.copy(key);
                    status = cursor.getSearchKeyRange(key, data, null);
                    if (status == OperationStatus.SUCCESS &&
                        KeyRange.equalBytes(key, saveKey)) {
                        status = cursor.getNext(key, data, null);
                    }
                } else {
                    status = cursor.getNext(key, data, null);
                }
            }
        } finally {
            if (cursor != null) {
                cursor.close();
            }
            if (txn != null) {
                if (nWritten > 0) {
                    txn.commit();
                } else {
View Full Code Here

        final DatabaseEntry key = new DatabaseEntry();
        final DatabaseEntry noData = new DatabaseEntry();
        noData.setPartial(0, 0, true);
        final Locker locker = BasicLocker.createBasicLocker(envImpl);
        try {
            final Cursor c = DbInternal.makeCursor(this, locker,
                                                   null /*cursorConfig*/);
            try {
                /* Position cursor on beginning key. */
                if (beginKey != null) {
                    key.setData(beginKey.getData(), beginKey.getOffset(),
                                beginKey.getSize());
                    if (c.getSearchKeyRange(key, noData,
                                            LockMode.READ_UNCOMMITTED) !=
                        OperationStatus.SUCCESS) {
                        return 0;
                    }
                    if (!beginInclusive && key.equals(beginKey)) {
                        if (c.getNext(key, noData,
                                      LockMode.READ_UNCOMMITTED) !=
                            OperationStatus.SUCCESS) {
                            return 0;
                        }
                    }
                } else {
                    if (c.getFirst(key, noData, LockMode.READ_UNCOMMITTED) !=
                        OperationStatus.SUCCESS) {
                        return 0;
                    }
                }

                /* Create RangeConstraint for ending key. */
                RangeConstraint rangeConstraint = null; // INCOMPLETE

                /* Skip entries to get count. */
                return DbInternal.getCursorImpl(c).skip
                    (true /*forward*/, 0 /*maxCount*/, rangeConstraint);
            } finally {
                c.close();
            }
        } finally {
            locker.operationEnd(true);
        }
    }
View Full Code Here

    }

    @Override
    public ClosableIterator<Pair<ByteArray, Versioned<byte[]>>> entries() {
        try {
            Cursor cursor = getBdbDatabase().openCursor(null, null);
            // evict data brought in by the cursor walk right away
            if(this.minimizeScanImpact)
                cursor.setCacheMode(CacheMode.EVICT_BIN);
            return new BdbEntriesIterator(cursor, this);
        } catch(DatabaseException e) {
            this.bdbEnvironmentStats.reportException(e);
            logger.error(e);
            throw new PersistenceFailureException(e);
View Full Code Here

    }

    @Override
    public ClosableIterator<ByteArray> keys() {
        try {
            Cursor cursor = getBdbDatabase().openCursor(null, null);
            // evict data brought in by the cursor walk right away
            if(this.minimizeScanImpact)
                cursor.setCacheMode(CacheMode.EVICT_BIN);
            return new BdbKeysIterator(cursor, this);
        } catch(DatabaseException e) {
            this.bdbEnvironmentStats.reportException(e);
            logger.error(e);
            throw new PersistenceFailureException(e);
View Full Code Here

TOP

Related Classes of com.sleepycat.je.Cursor$KeyChangeStatus

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.