本文整理汇总了Java中com.sleepycat.je.Transaction.abort方法的典型用法代码示例。如果您正苦于以下问题:Java Transaction.abort方法的具体用法?Java Transaction.abort怎么用?Java Transaction.abort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.sleepycat.je.Transaction
的用法示例。
在下文中一共展示了Transaction.abort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: delete
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
private void delete(byte keyVal, int keySize,
byte dataVal, int dataSize, boolean commit)
throws DatabaseException {
Transaction txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
assertEquals(OperationStatus.SUCCESS,
cursor.getSearchBoth(getEntry(keyVal, keySize),
getEntry(dataVal, dataSize),
LockMode.DEFAULT));
assertEquals(OperationStatus.SUCCESS, cursor.delete());
cursor.close();
if (commit) {
txn.commit();
} else {
txn.abort();
}
}
示例2: testActiveWhileCheckpointing
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Test the rollback of transactions that are active during a checkpoint.
*/
public void testActiveWhileCheckpointing()
throws Throwable {
createEnvAndDbs(1 << 20, true, NUM_DBS);
try {
int numRecs = 1;
Hashtable expectedData = new Hashtable();
Transaction txn = env.beginTransaction(null, null);
insertData(txn, 0, numRecs, expectedData, 1, false, NUM_DBS);
/* Now run a checkpoint while this operation hasn't finished. */
env.checkpoint(forceConfig);
txn.abort();
/* Shutdown, recover. */
closeEnv();
recoverAndVerify(expectedData, NUM_DBS);
} catch (Throwable t) {
t.printStackTrace();
throw t;
}
}
示例3: testDeletedReplaySR8984
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testDeletedReplaySR8984()
throws DatabaseException {
initEnvTransactional(true);
Transaction txn = exampleEnv.beginTransaction(null, null);
Cursor c = exampleDb.openCursor(txn, null);
c.put(simpleKeys[0], simpleData[0]);
c.delete();
for (int i = 1; i < 3; i++) {
c.put(simpleKeys[0], simpleData[i]);
}
c.close();
txn.abort();
txn = exampleEnv.beginTransaction(null, null);
c = exampleDb.openCursor(txn, null);
assertEquals(OperationStatus.NOTFOUND,
c.getFirst(new DatabaseEntry(),
new DatabaseEntry(),
LockMode.DEFAULT));
c.close();
txn.commit();
}
示例4: modify
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
private void modify(byte keyVal, int keySize,
byte dataVal, int dataSize,
boolean commit)
throws DatabaseException {
Transaction txn = null;
txn = env.beginTransaction(null, null);
Cursor cursor = db.openCursor(txn, null);
assertEquals(OperationStatus.SUCCESS,
cursor.getSearchKey(getEntry(keyVal, keySize),
new DatabaseEntry(),
LockMode.DEFAULT));
assertEquals(OperationStatus.SUCCESS,
cursor.delete());
assertEquals(OperationStatus.SUCCESS,
cursor.put(getEntry(keyVal, keySize),
getEntry(dataVal, dataSize)));
cursor.close();
if (commit) {
txn.commit();
} else {
txn.abort();
}
}
示例5: insert
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Inserts the given key and data in a new transaction and commits it.
*/
private void insert(int keyVal, int dataVal)
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
IntegerBinding.intToEntry(keyVal, key);
IntegerBinding.intToEntry(dataVal, data);
OperationStatus status;
Transaction writerTxn = env.beginTransaction(null, null);
try {
if (dups) {
status = db.putNoDupData(writerTxn, key, data);
} else {
status = db.putNoOverwrite(writerTxn, key, data);
}
} catch (DeadlockException e) {
writerTxn.abort();
throw e;
}
assertEquals(OperationStatus.SUCCESS, status);
writerTxn.commitNoSync();
}
示例6: insert
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
private void insert(byte keyVal, int keySize,
byte dataVal, int dataSize,
boolean commit)
throws DatabaseException {
Transaction txn = null;
if (!commit) {
txn = env.beginTransaction(null, null);
}
assertEquals(OperationStatus.SUCCESS,
db.put(null, getEntry(keyVal, keySize),
getEntry(dataVal, dataSize)));
if (!commit) {
txn.abort();
}
}
示例7: testUpdateUpdateDupAbort
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testUpdateUpdateDupAbort()
throws DatabaseException {
dups = true;
openEnv();
/* Insert two key 0 dups and checkpoint. */
Transaction txn = env.beginTransaction(null, null);
long file0 = doPut(0, 0, txn); // 1st LN
long file2 = doPut(0, 1, txn); // 2nd LN
long file1 = file2 - 1; // DupCountLN
txn.commit();
env.checkpoint(forceConfig);
/* Update {0, 1} twice and abort. */
txn = env.beginTransaction(null, null);
long file3 = doUpdate(0, 1, txn); // 3rd LN
long file4 = doUpdate(0, 1, txn); // 4rd LN
txn.abort();
performRecoveryOperation();
expectObsolete(file0, false);
expectObsolete(file1, false);
expectObsolete(file2, false);
expectObsolete(file3, true);
expectObsolete(file4, true);
closeEnv(true);
}
示例8: testReuseKnownDeletedSlotDup
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
public void testReuseKnownDeletedSlotDup()
throws DatabaseException {
dups = true;
openEnv();
/* Insert two key 0 dups and checkpoint. */
Transaction txn = env.beginTransaction(null, null);
long file0 = doPut(0, 0, txn); // 1st LN
long file2 = doPut(0, 1, txn); // 2nd LN
long file1 = file2 - 1; // DupCountLN
txn.commit();
env.checkpoint(forceConfig);
/* Insert {0, 2} and abort to create a knownDeleted slot. */
txn = env.beginTransaction(null, null);
long file3 = doPut(0, 2, txn); // 3rd LN
long file4 = file3 + 1; // DupCountLN
txn.abort();
/* Insert {0, 2} to reuse the knownDeleted slot. */
txn = env.beginTransaction(null, null);
long file5 = doPut(0, 2, txn); // 4th LN
long file6 = file5 + 1; // DupCountLN
txn.commit();
performRecoveryOperation();
/* Verify that file3 is still obsolete. */
expectObsolete(file0, false);
expectObsolete(file1, true);
expectObsolete(file2, false);
expectObsolete(file3, true);
expectObsolete(file4, true);
expectObsolete(file5, false);
expectObsolete(file6, false);
closeEnv(true);
}
示例9: testTruncateAbort
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Test that aborting truncate generates the right number of obsolete LNs.
*/
public void testTruncateAbort()
throws Exception {
openEnv(true);
openDb(null, DB_NAME1);
writeAndCountRecords(null, RECORD_COUNT);
DatabaseImpl saveDb = dbImpl;
closeDb();
Transaction txn = env.beginTransaction(null, null);
truncate(txn, true);
ObsoleteCounts beforeAbort = getObsoleteCounts();
txn.abort();
/* Make sure use count is decremented when we abort. */
assertDbInUse(saveDb, false);
openDb(null, DB_NAME1);
saveDb = dbImpl;
closeDb();
assertDbInUse(saveDb, false);
/*
* The obsolete count should include the records inserted after
* the truncate.
*/
verifyUtilization(beforeAbort,
/* 1 new nameLN, 2 copies of MapLN for new db */
3,
0);
/* Reopen, db should be populated. */
openDb(null, DB_NAME1);
assertEquals(RECORD_COUNT, countRecords(null));
closeEnv();
}
示例10: writeDataWithDeletes
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
private int writeDataWithDeletes()
throws DatabaseException {
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
int numInserted = 0;
data.setData(new byte[10]);
for (int i = 0; i < N_RECS; i++) {
IntegerBinding.intToEntry(i, key);
Transaction txn = env.beginTransaction(null, null);
assertEquals(db.put(txn, key, data),
OperationStatus.SUCCESS);
boolean deleted = false;
if ((i%2) ==0) {
assertEquals(db.delete(txn, key),
OperationStatus.SUCCESS);
deleted = true;
}
if ((i%3)== 0){
txn.abort();
} else {
txn.commit();
if (!deleted) {
numInserted++;
}
}
}
return numInserted;
}
示例11: modifyData
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Increment each data value.
*/
private void modifyData(Map expectedMap,
int increment,
boolean commit)
throws DatabaseException {
Transaction txn = exampleEnv.beginTransaction(null, null);
StringDbt foundKey = new StringDbt();
StringDbt foundData = new StringDbt();
Cursor cursor = exampleDb.openCursor(txn, null);
OperationStatus status = cursor.getFirst(foundKey, foundData,
LockMode.DEFAULT);
boolean toggle = true;
while (status == OperationStatus.SUCCESS) {
if (toggle) {
String foundKeyString = foundKey.getString();
String foundDataString = foundData.getString();
int newValue = Integer.parseInt(foundDataString) + increment;
String newDataString = Integer.toString(newValue);
/* If committing, adjust the expected map. */
if (commit) {
Set dataVals = (Set) expectedMap.get(foundKeyString);
if (dataVals == null) {
fail("Couldn't find " +
foundKeyString + "/" + foundDataString);
} else if (dataVals.contains(foundDataString)) {
dataVals.remove(foundDataString);
dataVals.add(newDataString);
} else {
fail("Couldn't find " +
foundKeyString + "/" + foundDataString);
}
}
assertEquals(OperationStatus.SUCCESS,
cursor.delete());
assertEquals(OperationStatus.SUCCESS,
cursor.put(foundKey,
new StringDbt(newDataString)));
toggle = false;
} else {
toggle = true;
}
status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT);
}
cursor.close();
if (commit) {
txn.commit();
} else {
txn.abort();
}
}
示例12: testDbCreation
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Test db creation and deletion
*/
public void testDbCreation()
throws DatabaseException {
Transaction txnA = env.beginTransaction(null, null);
Transaction txnB = env.beginTransaction(null, null);
DatabaseConfig dbConfig = new DatabaseConfig();
dbConfig.setAllowCreate(true);
dbConfig.setTransactional(true);
Database dbA =
env.openDatabase(txnA, "foo", dbConfig);
// Try to see this database with another txn -- we should not see it
dbConfig.setAllowCreate(false);
try {
txnB.setLockTimeout(1000);
env.openDatabase(txnB, "foo", dbConfig);
fail("Shouldn't be able to open foo");
} catch (DatabaseException e) {
}
/* txnB must be aborted since openDatabase timed out. */
txnB.abort();
// Open this database with the same txn and another handle
Database dbC =
env.openDatabase(txnA, "foo", dbConfig);
// Now commit txnA and txnB should be able to open this.
txnA.commit();
txnB = env.beginTransaction(null, null);
Database dbB =
env.openDatabase(txnB, "foo", dbConfig);
txnB.commit();
// XXX, test db deletion
dbA.close();
dbB.close();
dbC.close();
}
示例13: evolveIndex
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
private void evolveIndex(Format format,
EvolveEvent event,
EvolveListener listener)
throws DatabaseException {
Class entityClass = format.getType();
String entityClassName = format.getClassName();
EntityMetadata meta = model.getEntityMetadata(entityClassName);
String keyClassName = meta.getPrimaryKey().getClassName();
keyClassName = SimpleCatalog.keyClassName(keyClassName);
DatabaseConfig dbConfig = getPrimaryConfig(meta);
PrimaryIndex<Object,Object> index = getPrimaryIndex
(Object.class, keyClassName, entityClass, entityClassName);
Database db = index.getDatabase();
EntityBinding binding = index.getEntityBinding();
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
Cursor readCursor = db.openCursor(null, CursorConfig.READ_UNCOMMITTED);
try {
while (readCursor.getNext(key, data, null) ==
OperationStatus.SUCCESS) {
if (evolveNeeded(key, data, binding)) {
Transaction txn = null;
if (dbConfig.getTransactional()) {
boolean success = false;
txn = env.beginTransaction(null, null);
}
boolean written = false;
Cursor writeCursor = null;
try {
writeCursor = db.openCursor(txn, null);
if (writeCursor.getSearchKey
(key, data, LockMode.RMW) ==
OperationStatus.SUCCESS) {
if (evolveNeeded(key, data, binding)) {
writeCursor.putCurrent(data);
written = true;
}
if (listener != null) {
EvolveInternal.updateEvent
(event, entityClassName, 1,
written ? 1 : 0);
if (!listener.evolveProgress(event)) {
break;
}
}
}
} finally {
if (writeCursor != null) {
writeCursor.close();
}
if (txn != null) {
if (written) {
txn.commit();
} else {
txn.abort();
}
}
}
}
}
} finally {
readCursor.close();
}
}
示例14: testReuseSlot
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
/**
* Test when a duplicate tree reuses an entry previously populated by
* a deleted LN. [#SR12847]
* The sequence is this:
* create database
* insert k1/d1 (make BIN with a slot for k1)
* abort the insert, so the BIN is marked known deleted
* flush the BIN to the log
*
* insert k1/d100
* insert k1/d200 (creates a new duplicate tree)
*
* Now recover from here. The root of the duplicate tree must be put
* into the old known deleted slot used for k1/d1. There is some
* finagling to make this happen; namely the BIN must not be compressed
* during checkpoint.
*/
public void testReuseSlot()
throws DatabaseException {
/* Create 1 database. */
createEnvAndDbs(1 << 20, false, 1);
DatabaseEntry key = new DatabaseEntry();
DatabaseEntry data = new DatabaseEntry();
/* Insert a record, then abort it so it's marked knownDeleted. */
Transaction txn = env.beginTransaction(null, null);
IntegerBinding.intToEntry(100, key);
IntegerBinding.intToEntry(1, data);
dbs[0].put(txn, key, data);
txn.abort();
/*
* Put a cursor on this bin to prevent lazy compression and preserve
* the slot created above.
*/
IntegerBinding.intToEntry(200, key);
IntegerBinding.intToEntry(1, data);
txn = env.beginTransaction(null, null);
Cursor c = dbs[0].openCursor(txn, null);
c.put(key, data);
/* Flush this bin to the log. */
CheckpointConfig ckptConfig = new CheckpointConfig();
ckptConfig.setForce(true);
env.checkpoint(ckptConfig);
c.close();
txn.abort();
/*
* Now create a duplicate tree, reusing the known deleted slot
* in the bin.
*/
Hashtable expectedData = new Hashtable();
IntegerBinding.intToEntry(100, key);
IntegerBinding.intToEntry(1, data);
dbs[0].put(null, key, data);
addExpectedData(expectedData, 0, key, data, true);
IntegerBinding.intToEntry(2, data);
dbs[0].put(null, key, data);
addExpectedData(expectedData, 0, key, data, true);
/* close the environment. */
closeEnv();
recoverAndVerify(expectedData, 1);
}
示例15: initAndRetry
import com.sleepycat.je.Transaction; //导入方法依赖的package包/类
private void initAndRetry(final String storePrefix,
final EntityModel modelParam,
final Mutations mutationsParam)
throws DatabaseException {
for (int i = 0;; i += 1) {
Transaction txn = null;
if (transactional && DbCompat.getThreadTransaction(env) == null) {
txn =
env.beginTransaction(null, store.getAutoCommitTxnConfig());
}
boolean success = false;
try {
init(txn, storePrefix, modelParam, mutationsParam);
success = true;
return;
} catch (LockConflictException e) {
/*
* It is very unlikely that two threads opening the same
* EntityStore will cause a lock conflict. However, because we
* read-modify-update the catalog record,
* LockPreemptedException must be handled in a replicated JE
* environment. Since LockPreemptedException is a
* LockConfictException, it is simplest to retry when any
* LockConfictException occurs.
*/
if (i >= MAX_TXN_RETRIES) {
throw e;
}
continue;
} finally {
/*
* If the catalog is read-only we abort rather than commit,
* because a ReplicaWriteException may have occurred.
* ReplicaWriteException invalidates the transaction, and there
* are no writes to commit anyway. [#16655]
*/
if (txn != null) {
if (success && !isReadOnly()) {
txn.commit();
} else {
txn.abort();
}
}
}
}
}