Package com.sleepycat.je

Examples of com.sleepycat.je.Database$DbState


             * no-latches-while-locking check.
             */
            Transaction txnSpoiler = env.beginTransaction(null, null);
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setTransactional(true);
            Database dbSpoiler = env.openDatabase(txnSpoiler, "foo", dbConfig);

            txn.abort();

            /*
             * The database should be empty
             */
            Cursor cursor = dbSpoiler.openCursor(txnSpoiler, null);
           
            assertTrue(cursor.getFirst(keyDbt, dataDbt, LockMode.DEFAULT) !=
                       OperationStatus.SUCCESS);
            cursor.close();
            txnSpoiler.abort();
View Full Code Here


        if (makeDatabase) {
            /* Database */

            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setAllowCreate(true);
            Database db = env.openDatabase(null, "foo", dbConfig);
       
            /* Insert enough keys to get an odd number of nodes */

            DatabaseEntry keyAndData = new DatabaseEntry();
            for (int i = 0; i < 110; i++) {
                IntegerBinding.intToEntry(i, keyAndData);
                db.put(null, keyAndData, keyAndData);
            }

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

            /* Grab a lock */
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setTransactional(true);
            dbConfig.setAllowCreate(true);
            Database dbA = env.openDatabase(txnA, "foo", dbConfig);

            /* Now make a second txn so we can induce some blocking. */
            Transaction txnB = env.beginTransaction(null, null);
            txnB.setTxnTimeout(300000)// microseconds
            txnB.setLockTimeout(9000000)
            Thread.sleep(400);
            Database dbB = null;

            try {
                dbB = env.openDatabase(txnB, "foo", dbConfig);
                fail("Should time out");
            } catch (TxnTimeOutException e) {
View Full Code Here

            Transaction txnA = env.beginTransaction(null, null);
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setTransactional(true);
            dbConfig.setAllowCreate(true);
            Database dbA = env.openDatabase(txnA, "foo", dbConfig);

            /*
       * Now make a second txn so we can induce some blocking. Make the
       * txn timeout environment wide.
       */
            Transaction txnB = env.beginTransaction(null, null);
            if (!setEnvConfigTimeout) {
                if (setPerTxnTimeout) {
                    txnB.setTxnTimeout(300000);
                }
                if (setPerLockTimeout) {
                    txnB.setLockTimeout(9000000);
                }
            }

            Thread.sleep(400);
            Database dbB = null;

            try {
                dbB = env.openDatabase(txnB, "foo", dbConfig);
                fail("Should time out");
            } catch (DeadlockException e) {
View Full Code Here

        throws Throwable {

        try {
            /* Create an environment. */
            env = new Environment(envHome, startEnvConfig);
            Database db = env.openDatabase(null, dbName, startDbConfig);

            /* Generate test data. */
            testGen.generateData(db);

            /* Scan the database to save what values we should have. */
            loadExpectedData(db);

            /* Close w/out checkpointing. */
            db.close();
            DbInternal.envGetEnvironmentImpl(env).close(false);
            env = null;

            /* Recover and load what's in the database post-recovery. */
            recoverAndLoadData(validateEnvConfig,
View Full Code Here

                                      DatabaseConfig dbConfig,
                                      String dbName)
        throws DatabaseException {

        env = new Environment(envHome, envConfig);
        Database db = env.openDatabase(null, dbName, dbConfig);
        found = new HashSet();

        Cursor cursor = db.openCursor(null, null);
        DatabaseEntry key = new DatabaseEntry();
        DatabaseEntry data = new DatabaseEntry();

        int i = 0;
        try {
            while (cursor.getNext(key, data, null) ==
                   OperationStatus.SUCCESS) {
                TestData t = new TestData(key, data);
                if (DEBUG) {
                    System.out.println("found k=" +
                                       IntegerBinding.entryToInt(key) +
                                       " d=" +
                                       IntegerBinding.entryToInt(data));
                }
                found.add(t);
            }
        }
        finally {
            cursor.close();
        }

        db.close();
       
        assertTrue(env.verify(new VerifyConfig(), System.out));
        env.close();
    }
View Full Code Here

      Transaction txn = env.beginTransaction(null, null);
      DatabaseEntry key = new DatabaseEntry("aaaaa".getBytes());
      DatabaseEntry data1 = new DatabaseEntry("dddddddddd".getBytes());
      DatabaseEntry data2 = new DatabaseEntry("eeeeeeeeee".getBytes());
      DatabaseEntry data3 = new DatabaseEntry("ffffffffff".getBytes());
      Database db = dbs[0];
      assertEquals(OperationStatus.SUCCESS,
       db.put(null, key, data1));
      addExpectedData(expectedData, 0, key, data1, true);
      assertEquals(OperationStatus.SUCCESS,
       db.put(null, key, data2));
      addExpectedData(expectedData, 0, key, data2, true);
      assertEquals(OperationStatus.SUCCESS,
       db.put(null, key, data3));
      addExpectedData(expectedData, 0, key, data3, true);
      assertEquals(OperationStatus.SUCCESS,
       db.put(null, key, data3));
      txn.commit();
      closeEnv();

      recoverAndVerify(expectedData, NUM_DBS);
        } catch (Throwable t) {
View Full Code Here

        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(false);
        dbConfig.setAllowCreate(true);
        dbConfig.setSortedDuplicates(true);
  Database db = env.openDatabase(null, "testSR8984db", dbConfig);

  DatabaseEntry key = new DatabaseEntry("k1".getBytes());
  DatabaseEntry data = new DatabaseEntry("d1".getBytes());
  assertEquals(OperationStatus.SUCCESS, db.put(null, key, data));
  assertEquals(OperationStatus.SUCCESS, db.delete(null, key));
       
  if (!sameKey) {
      data.setData("d2".getBytes());
  }
  /* Cause a dup tree of some depth to be created. */
  assertEquals(OperationStatus.SUCCESS, db.put(null, key, data));
  for (int i = 3; i < NUM_EXTRA_DUPS; i++) {
      data.setData(("d" + i).getBytes());
      assertEquals(OperationStatus.SUCCESS, db.put(null, key, data));
  }

  data.setData("d1".getBytes());

  Cursor c = db.openCursor(null, null);
  assertEquals(OperationStatus.SUCCESS,
         c.getFirst(key, data, LockMode.DEFAULT));

  c.close();
  db.close();
       
        /* Force an abrupt close so there is no checkpoint at the end. */
        closeEnv();
        env = new Environment(envHome, envConfig);
  db = env.openDatabase(null, "testSR8984db", dbConfig);
  c = db.openCursor(null, null);
  assertEquals(OperationStatus.SUCCESS,
         c.getFirst(key, data, LockMode.DEFAULT));
  assertEquals(NUM_EXTRA_DUPS - 2, c.count());
  c.close();
  db.close();
  env.close();
    }
View Full Code Here

        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setTransactional(true);
        dbConfig.setAllowCreate(true);
        dbConfig.setSortedDuplicates(true);
  final Database db = env.openDatabase(dbTxn, "foo", dbConfig);
  dbTxn.commit();
  final Transaction txn = env.beginTransaction(null, null);
  sequence = 0;

  /**
   * The sequence between the two tester threads is:
   *
   * tester2: write 1/1 into the database.  This causes the initial tree
   * to be created (IN/BIN/LN).  Flush that out to the disk with a full
   * checkpoint.  Signal tester1 and wait.
   *
   * tester1: Lock the MapLN for "foo" db.  Signal tester2 and wait.
   *
   * tester2: Add 2/2 to the tree which causes the BIN to be dirtied.
   * Signal tester1 to continue, perform a full checkpoint which will
   * causes the root IN to be dirtied and flushed.  DbTree.modifyDbRoot
   * will block on the MapLN lock held by tester1.
   *
   * tester1: while tester2 is blocking on the MapLN lock, this thread is
   * sleeping.  When it wakes up, it releases the MapLN lock by aborting
   * the transaction.
   *
   * tester2: modifyDbRoot finally acquires the write lock on foo-db's
   * MapLN write lock, performs the update to the DbTree and returns from
   * the sync().
   */
  JUnitThread tester1 =
      new JUnitThread("testSR11293DbTreeLocker") {
        public void testBody() {
      try {
          /* Wait for tester2. */
          while (sequence < 1) {
        Thread.yield();
          }

          /* Lock the MapLN for the database. */
          DatabaseId fooId =
        DbInternal.dbGetDatabaseImpl(db).getId();
          DatabaseImpl fooDb = dbTree.getDb(fooId, 500000L);
          assert fooDb != null;

          sequence++;

          /* Wait for tester2. */
          while (sequence < 3) {
        Thread.yield();
          }

          try {
        Thread.sleep(3000);
          } catch (Exception E) {
          }

          try {
        txn.abort();
        db.close();
        env.close();
          } catch (DatabaseException DBE) {
        DBE.printStackTrace();
        fail("unexpected exception: " + DBE);
          }
      } catch (DatabaseException DBE) {
          DBE.printStackTrace();
          fail("caught DatabaseException " + DBE);
      }
        }
    };

  JUnitThread tester2 =
      new JUnitThread("testSR11293DbWriter") {
        public void testBody() {
      try {
          DatabaseEntry key =
        new DatabaseEntry(new byte[] { 1 });
          DatabaseEntry data =
        new DatabaseEntry(new byte[] { 1 });
          assertEquals(OperationStatus.SUCCESS,
           db.put(null, key, data));
          env.sync();

          sequence++;
          while (sequence < 2) {
        Thread.yield();
          }

          key.setData(new byte[] { 2 });
          data.setData(new byte[] { 2 });
          assertEquals(OperationStatus.SUCCESS,
           db.put(null, key, data));
          sequence++;
          env.sync();
      } catch (DatabaseException DBE) {
          DBE.printStackTrace();
          fail("unexpected exception: " + DBE);
      }
        }
    };

  tester1.start();
  tester2.start();
  tester1.finishTest();
  tester2.finishTest();

        EnvironmentConfig recoveryConfig = TestUtils.initEnvConfig();

        recoveryConfig.setConfigParam
      (EnvironmentParams.ENV_RUN_CHECKPOINTER.getName(), "false");
  recoveryConfig.setConfigParam
      (EnvironmentParams.ENV_RUN_CLEANER.getName(), "false");
  recoveryConfig.setConfigParam
      (EnvironmentParams.ENV_RUN_EVICTOR.getName(), "false");

        env = new Environment(envHome, recoveryConfig);
  dbConfig.setAllowCreate(false);
  dbConfig.setTransactional(false);
  Database db2 = env.openDatabase(null, "foo", dbConfig);
  Cursor c = db2.openCursor(null, null);
  DatabaseEntry key = new DatabaseEntry();
  DatabaseEntry data = new DatabaseEntry();
  assertEquals(OperationStatus.SUCCESS,
         c.getNext(key, data, LockMode.DEFAULT));
  assertEquals((key.getData())[0], 1);
  assertEquals((data.getData())[0], 1);

  assertEquals(OperationStatus.SUCCESS,
         c.getNext(key, data, LockMode.DEFAULT));
  assertEquals((key.getData())[0], 2);
  assertEquals((data.getData())[0], 2);
  assertEquals(OperationStatus.NOTFOUND,
         c.getNext(key, data, LockMode.DEFAULT));

  c.close();
  db2.close();
  env.close();
    }
View Full Code Here

           
            DatabaseConfig dbConfig = new DatabaseConfig();
            dbConfig.setAllowCreate(true);
            dbConfig.setTransactional(transactional);
            dbConfig.setSortedDuplicates(true);
            Database db = env.openDatabase(null, dbName, dbConfig);

            Transaction txn = null;
            if (transactional) {
                txn = env.beginTransaction(null, null);
            }

            /* Write: {0, 0}, {0, 1}, {1, 0}, {2, 0}, {3, 0} */
            for (int j = 0; j < N_ENTRIES; j += 1) {
                db.put(txn, Utils.entry(j), Utils.entry(0));
            }
            db.put(txn, Utils.entry(0), Utils.entry(1));

            /* Must checkpoint to generate BINDeltas. */
            env.checkpoint(forceCheckpoint);

            /* Delete everything but the last LN to cause IN deletion. */
            for (int j = 0; j < N_ENTRIES - 1; j += 1) {
                db.delete(txn, Utils.entry(j));
            }

            if (transactional) {
                txn.abort();
            }

            db.close();
        }

        /* Compress to delete DBIN, DIN, BIN, IN. */
        env.compress();

        /* DB2 was not aborted and will contain: {3, 0} */
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(false);
        dbConfig.setReadOnly(true);
        dbConfig.setSortedDuplicates(true);
        Database db = env.openDatabase(null, Utils.DB2_NAME, dbConfig);
        Cursor cursor = db.openCursor(null, null);
        try {
            DatabaseEntry key = new DatabaseEntry();
            DatabaseEntry data = new DatabaseEntry();
            OperationStatus status = cursor.getFirst(key, data, null);
            if (status != OperationStatus.SUCCESS) {
                throw new Exception("Expected SUCCESS but got: " + status);
            }
            if (Utils.value(key) != 3 || Utils.value(data) != 0) {
                throw new Exception("Expected {3,0} but got: {" +
                                    Utils.value(key) + ',' +
                                    Utils.value(data) + '}');
            }
        } finally {
            cursor.close();
        }
        db.close();

  XidImpl xid =
      new XidImpl(1, "MakeLogEntryVersionData".getBytes(), null);
  env.start(xid, XAResource.TMNOFLAGS);
  env.prepare(xid);
View Full Code Here

TOP

Related Classes of com.sleepycat.je.Database$DbState

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.