/** Write data into the database. */ private void generateData( Environment master, int numTxns, Durability durability, boolean doCommit) { /* Write some data. */ DatabaseEntry key = new DatabaseEntry(); byte[] dataPadding = new byte[1000]; DatabaseEntry data = new DatabaseEntry(dataPadding); TransactionConfig txnConfig = new TransactionConfig(); txnConfig.setDurability(durability); for (int i = 0; i < numTxns; i++) { final Transaction txn = master.beginTransaction(null, txnConfig); // long keyPrefix = i << 10; // LongBinding.longToEntry(keyPrefix + i, key); LongBinding.longToEntry(i, key); db.put(txn, key, data); if (doCommit) { txn.commit(); } else { txn.abort(); } } }
public boolean createSecondaryKey( SecondaryDatabase secDb, DatabaseEntry keyEntry, DatabaseEntry dataEntry, DatabaseEntry resultEntry) { BdbPrimaryKey key = BdbGraph.primaryKeyBinding.entryToObject(keyEntry); if (key.type != BdbPrimaryKey.VERTEX_PROPERTY) return false; LongBinding.longToEntry(key.id1, resultEntry); return true; }
private void readData(Environment env, int lastRecordVal) { Database readDb = null; DatabaseEntry key = new DatabaseEntry(); DatabaseEntry data = new DatabaseEntry(); try { readDb = openDatabase(env); for (int i = 0; i < lastRecordVal; i++) { LongBinding.longToEntry(i, key); assertEquals(OperationStatus.SUCCESS, db.get(null, key, data, LockMode.DEFAULT)); } } finally { if (readDb != null) { readDb.close(); } } }
/* * Test that a replica using the jdb files copied from the master can join * the group. */ @Test public void testCopyEnvJoin() throws Throwable { createGroup(1); assertTrue(repEnvInfo[0].isMaster()); /* Create some data on the master. */ populateDB(repEnvInfo[0].getEnv(), "testDB", 1000); /* Close the Environment before copy. */ repEnvInfo[0].closeEnv(); /* First check there is no jdb files in the second replica. */ File repEnvHome = repEnvInfo[1].getEnvHome(); File[] envFiles = repEnvHome.listFiles(); for (File envFile : envFiles) { if (envFile.getName().contains(".jdb")) { throw new IllegalStateException("Replica home should not contain any jdb files"); } } /* Copy the jdb files from the master to the replica. */ SharedTestUtils.copyFiles(repEnvInfo[0].getEnvHome(), repEnvInfo[1].getEnvHome()); /* Reopen the master. */ repEnvInfo[0].openEnv(); assertTrue(repEnvInfo[0].isMaster()); /* Open the replica. */ repEnvInfo[1].openEnv(); assertTrue(repEnvInfo[1].isReplica()); /* Read the data to make sure data is correctly copied. */ Database db = repEnvInfo[1].getEnv().openDatabase(null, "testDB", dbconfig); for (int i = 0; i < 1000; i++) { IntegerBinding.intToEntry(i, key); db.get(null, key, data, null); assertEquals(i, (int) LongBinding.entryToLong(data)); } db.close(); }