Java Code Examples for com.sleepycat.je.Transaction#abort()

The following examples show how to use com.sleepycat.je.Transaction#abort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReplicatedEnvironmentFacadeTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testBeginTransaction() throws Exception
{
    ReplicatedEnvironmentFacade facade = createMaster();
    Transaction txn = null;
    try
    {
        TransactionConfig transactionConfig = new TransactionConfig();
        transactionConfig.setDurability(facade.getRealMessageStoreDurability());
        txn = facade.beginTransaction(transactionConfig);
        assertNotNull("Transaction is not created", txn);
        txn.commit();
        txn = null;
    }
    finally
    {
        if (txn != null)
        {
            txn.abort();
        }
    }
}
 
Example 2
Source File: AbstractBDBMessageStore.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
/**
 * Abandons all operations performed within a given transaction.
 *
 * @param tx The transaction to abandon.
 *
 * @throws org.apache.qpid.server.store.StoreException If the operation fails for any reason.
 */
private void abortTran(final Transaction tx) throws StoreException
{
    getLogger().debug("abortTran called for transaction {}", tx);

    try
    {
        tx.abort();
    }
    catch (RuntimeException e)
    {
        throw getEnvironmentFacade().handleDatabaseException("Error aborting transaction: " + e.getMessage(), e);
    }
}
 
Example 3
Source File: BDBUtils.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public static void abortTransactionSafely(Transaction tx, EnvironmentFacade environmentFacade)
{
    try
    {
        if (tx != null)
        {
            tx.abort();
        }
    }
    catch (RuntimeException e)
    {
        // We need the possible side effect of the facade restarting the environment but don't care about the exception
        environmentFacade.handleDatabaseException("Cannot abort transaction", e);
    }
}
 
Example 4
Source File: ReplicatedEnvironmentFacadeTest.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
@Test
public void testReplicaTransactionBeginsImmediately()  throws Exception
{
    ReplicatedEnvironmentFacade master = createMaster();
    String nodeName2 = TEST_NODE_NAME + "_2";
    String host = "localhost";
    int port = _portHelper.getNextAvailable();
    String node2NodeHostPort = host + ":" + port;

    final ReplicatedEnvironmentFacade replica = createReplica(nodeName2, node2NodeHostPort, new NoopReplicationGroupListener() );

    // close the master
    master.close();

    // try to create a transaction in a separate thread
    // and make sure that transaction is created immediately.
    ExecutorService service =  Executors.newSingleThreadExecutor();
    try
    {

        Future<Transaction> future = service.submit(new Callable<Transaction>(){

            @Override
            public Transaction call() throws Exception
            {
                return  replica.beginTransaction(null);
            }
        });
        Transaction transaction = future.get(_timeout, TimeUnit.SECONDS);
        assertNotNull("Transaction was not created during expected time", transaction);
        transaction.abort();
    }
    finally
    {
        service.shutdown();
    }
}
 
Example 5
Source File: DatabasePinger.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
public void pingDb(EnvironmentFacade facade)
{
    try
    {
        if (LOGGER.isDebugEnabled())
        {
            LOGGER.debug("Beginning ping transaction");
        }

        final Database db = facade.openDatabase(PING_DATABASE_NAME,
                                                DATABASE_CONFIG);

        DatabaseEntry key = new DatabaseEntry();
        IntegerBinding.intToEntry(ID, key);

        DatabaseEntry value = new DatabaseEntry();
        LongBinding.longToEntry(System.currentTimeMillis(), value);
        Transaction txn = null;
        try
        {
            txn = facade.beginTransaction(_pingTransactionConfig);
            db.put(txn, key, value);
            txn.commit();

            txn = null;
        }
        finally
        {
            if (LOGGER.isDebugEnabled())
            {
                LOGGER.debug("Ping transaction completed");
            }

            if (txn != null)
            {
                txn.abort();
            }
        }
    }
    catch (RuntimeException de)
    {
        RuntimeException handledException = facade.handleDatabaseException("DatabaseException from DatabasePinger ", de);
        LOGGER.debug("Non fatal exception on invoking DatabasePinger. Ignoring...", handledException);
    }
}
 
Example 6
Source File: UpgradeFrom8To9.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
@Override
public void performUpgrade(final Environment environment,
                           final UpgradeInteractionHandler handler,
                           final ConfiguredObject<?> parent)
{
    reportStarting(environment, 8);

    DatabaseConfig dbConfig = new DatabaseConfig();
    dbConfig.setTransactional(true);
    dbConfig.setAllowCreate(true);

    final Transaction transaction = environment.beginTransaction(null, null);
    try
    {
        Database userPreferencesDb = environment.openDatabase(transaction, "USER_PREFERENCES", dbConfig);
        userPreferencesDb.close();

        try (Database userPreferencesVersionDb = environment.openDatabase(transaction,
                                                                          "USER_PREFERENCES_VERSION",
                                                                          dbConfig))
        {
            if (userPreferencesVersionDb.count() == 0L)
            {
                DatabaseEntry key = new DatabaseEntry();
                DatabaseEntry value = new DatabaseEntry();
                StringBinding.stringToEntry(DEFAULT_VERSION, key);
                LongBinding.longToEntry(System.currentTimeMillis(), value);
                OperationStatus status = userPreferencesVersionDb.put(transaction, key, value);
                if (status != OperationStatus.SUCCESS)
                {
                    throw new StoreException("Error initialising user preference version: " + status);
                }
            }
        }

        transaction.commit();
        reportFinished(environment, 9);
    }
    catch (RuntimeException e)
    {
        try
        {
            if (transaction.isValid())
            {
                transaction.abort();
            }
        }
        finally
        {
            throw e;
        }
    }
}
 
Example 7
Source File: OrphanConfigurationRecordPurger.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private void purge() throws Exception
{
    EnvironmentConfig config = EnvironmentConfig.DEFAULT;
    config.setAllowCreate(false);
    config.setTransactional(true);

    try (Environment env = createEnvironment(config))
    {
        final int version = getVersion(env, READ_ONLY_DB_CONFIG);
        if (!ALLOWED_VERSIONS.contains(version))
        {
            throw new IllegalStateException(String.format("Store has unexpected version. Found %d expected %s",
                                                          version, ALLOWED_VERSIONS));
        }

        final Transaction tx = env.beginTransaction(null, TransactionConfig.DEFAULT);
        boolean success = false;
        try
        {
            purgeOrphans(env, tx);
            success = true;
        }
        finally
        {
            if (!success)
            {
                System.out.println("No config or config hierarchy records purged.");
                tx.abort();
            }
            else if (_dryRun)
            {
                System.out.println("No config or config hierarchy records purged - -dryRun flag specified.");
                tx.abort();
            }
            else
            {
                tx.commit();
                System.out.format("Config records(s) and associated hierarchy records purged.");
            }
        }
    }
}