Package com.sleepycat.je.dbi

Examples of com.sleepycat.je.dbi.MemoryBudget


     * Do a check on whether synchronous eviction is needed.
     */
    public void doCriticalEviction()
        throws DatabaseException {

        MemoryBudget mb = envImpl.getMemoryBudget();
        long currentUsage  = mb.getCacheMemoryUsage();
        long maxMem = mb.getCacheBudget();
        long over = currentUsage - maxMem;
       
        if (over > mb.getCriticalThreshold()) {
            if (DEBUG) {
                System.out.println("***critical detected:" + over);
            }
            doEvict(SOURCE_CRITICAL);
        }
View Full Code Here


     * Return true if eviction should happen.
     */
    boolean isRunnable(String source)
        throws DatabaseException {

        MemoryBudget mb = envImpl.getMemoryBudget();
        long currentUsage  = mb.getCacheMemoryUsage();
        long maxMem = mb.getCacheBudget();
        boolean doRun = ((currentUsage - maxMem) > 0);

        /* If running, figure out how much to evict. */
        if (doRun) {
            currentRequiredEvictBytes =
View Full Code Here

    private void evictAndCheck(boolean shouldEvict, int nKeys)
        throws DatabaseException {

        EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
        MemoryBudget mb = envImpl.getMemoryBudget();

        /*
         * The following batches are run in a single evictMemory() call:
         * 1st eviction will strip DBINs.
         * 2nd will evict DBINs
         * 3rd will evict DINs
         * 4th will strip BINs
         * 5th will evict BINs
         * 6th will evict INs
         * 7th will evict INs
         */
        long preEvictMem = mb.getCacheMemoryUsage();
        TestUtils.validateNodeMemUsage(envImpl, true);
        env.evictMemory();
        long postEvictMem = mb.getCacheMemoryUsage();

        TestUtils.validateNodeMemUsage(envImpl, true);
        if (DEBUG) {
            System.out.println("preEvict=" + preEvictMem +
                               " postEvict=" + postEvictMem);
        }

        if (shouldEvict) {
            assertTrue("preEvict=" + preEvictMem +
                       " postEvict=" + postEvictMem +
                       " maxMem=" + mb.getMaxMemory(),
                       (preEvictMem > postEvictMem));
        } else {
            assertTrue("preEvict=" + preEvictMem +
                       " postEvict=" + postEvictMem,
                       (preEvictMem == postEvictMem));
View Full Code Here

            /*
             * Make a null txn that will lock. Take a lock and then end the
             * operation.
             */
            EnvironmentImpl envImpl = DbInternal.envGetEnvironmentImpl(env);
            MemoryBudget mb = envImpl.getMemoryBudget();
           
            long beforeLock = mb.getCacheMemoryUsage();
            Locker nullTxn = new BasicLocker(envImpl);

            LockGrantType lockGrant = nullTxn.lock
                (ln.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            assertEquals(LockGrantType.NEW, lockGrant);
            long afterLock = mb.getCacheMemoryUsage();
            checkHeldLocks(nullTxn, 1, 0);

            nullTxn.operationEnd();
            long afterRelease = mb.getCacheMemoryUsage();
            checkHeldLocks(nullTxn, 0, 0);
            checkCacheUsage(beforeLock, afterLock, afterRelease,
                            LockManager.TOTAL_LOCK_OVERHEAD +
                            MemoryBudget.LOCKINFO_OVERHEAD);

            // Take a lock, release it.
            beforeLock = mb.getCacheMemoryUsage();
            lockGrant = nullTxn.lock
                (ln.getNodeId(), LockType.READ,
                 DbInternal.dbGetDatabaseImpl(db)).
    getLockGrant();
            afterLock = mb.getCacheMemoryUsage();
            assertEquals(LockGrantType.NEW, lockGrant);
            checkHeldLocks(nullTxn, 1, 0);

            nullTxn.releaseLock(ln.getNodeId());
            checkHeldLocks(nullTxn, 0, 0);
            afterRelease = mb.getCacheMemoryUsage();
            checkCacheUsage(beforeLock, afterLock, afterRelease,
                            LockManager.TOTAL_LOCK_OVERHEAD +
                            MemoryBudget.LOCKINFO_OVERHEAD);

            /*
             * 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();
            throw t;
View Full Code Here

        throws Exception {

  Locker txn1 = new BasicLocker(envImpl);
  Locker txn2 = new BasicLocker(envImpl);
  Locker txn3 = new BasicLocker(envImpl);
        MemoryBudget mb = envImpl.getMemoryBudget();
  try {
            /*
             * Start fresh. Ask for a read lock from txn1 twice,
             * should only be one owner. Then add multiple
             * would-be-writers as waiters.
View Full Code Here

  Locker txn1 = new BasicLocker(envImpl);
  Locker txn2 = new BasicLocker(envImpl);
  Locker txn3 = new BasicLocker(envImpl);
  Locker txn4 = new BasicLocker(envImpl);
        MemoryBudget mb = envImpl.getMemoryBudget();

        try {
            /*
             * Build up 3 owners and waiters for a lock, to test the
             * lazy initialization and optimization for single owner/waiter.
View Full Code Here

  Locker txn1 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn2 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn3 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn4 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn5 = new AutoTxn(envImpl, new TransactionConfig());
        MemoryBudget mb = envImpl.getMemoryBudget();

        try {
            /*
             * Build up 1 owners and 3waiters for a lock, to test the
             * lazy initialization and optimization for single owner/waiter.
View Full Code Here

  Locker txn1 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn2 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn3 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn4 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn5 = new AutoTxn(envImpl, new TransactionConfig());
        MemoryBudget mb = envImpl.getMemoryBudget();

        try {
            /*
             * Build up 1 owners and 3 read waiters for a lock. Then
             * check that all the waiters promote properly.
View Full Code Here

                               LockGrantType secondGrantType)
        throws Exception {

  Locker txn1 = new AutoTxn(envImpl, new TransactionConfig());
  Locker txn2 = new AutoTxn(envImpl, new TransactionConfig());
        MemoryBudget mb = envImpl.getMemoryBudget();

        try {
            Lock lock = new Lock(new Long(1));

            if (firstRequest != null) {
View Full Code Here

                              LockGrantType secondGrantType,
                              LockType finalType)
        throws Exception {

  Locker txn1 = new AutoTxn(envImpl, new TransactionConfig());
        MemoryBudget mb = envImpl.getMemoryBudget();

        try {
            Lock lock = new Lock(new Long(1));

            assertEquals(LockGrantType.NEW,
View Full Code Here

TOP

Related Classes of com.sleepycat.je.dbi.MemoryBudget

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.