Search in sources :

Example 1 with ContextService

use of org.apache.derby.iapi.services.context.ContextService in project derby by apache.

the class EmbedXAResource method forget.

/**
 * Tell the resource manager to forget about a heuristically completed
 * transaction branch.
 *
 * @param xid A global transaction identifier
 * @exception XAException An error has occurred. Possible exception values
 * are XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
public final synchronized void forget(Xid xid) throws XAException {
    checkXAActive();
    // ensure immtable and correct equals method.
    XAXactId xid_im = new XAXactId(xid);
    XATransactionState tranState = getTransactionState(xid_im);
    if (tranState == null) {
        XAResourceManager rm = ra.getXAResourceManager();
        ContextManager inDoubtCM = rm.find(xid);
        // RM also does not know about this xid.
        if (inDoubtCM == null)
            throw new XAException(XAException.XAER_NOTA);
        ContextService csf = getContextService();
        csf.setCurrentContextManager(inDoubtCM);
        try {
            rm.forget(inDoubtCM, xid_im);
            // close the connection/transaction since it can never be used again.
            inDoubtCM.cleanupOnError(StandardException.closeException(), false);
            return;
        } catch (StandardException se) {
            // The rm threw an exception, clean it up in the approprate
            // context.  There is no transactionResource to handle the
            // exception for us.
            inDoubtCM.cleanupOnError(se, con.isActive());
            throw wrapInXAException(se);
        } finally {
            csf.resetCurrentContextManager(inDoubtCM);
        }
    }
    // DERBY-1016; if the transaction exists throw XAER_PROTO on forget
    throw new XAException(XAException.XAER_PROTO);
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) XAXactId(org.apache.derby.iapi.store.access.xa.XAXactId) ContextService(org.apache.derby.iapi.services.context.ContextService) XAException(javax.transaction.xa.XAException) XAResourceManager(org.apache.derby.iapi.store.access.xa.XAResourceManager) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 2 with ContextService

use of org.apache.derby.iapi.services.context.ContextService in project derby by apache.

the class EmbedXAResource method rollback.

/**
 * Inform the resource manager to roll back work done on behalf of a
 * transaction branch
 *
 * @param xid A global transaction identifier
 * @exception XAException - An error has occurred
 */
public final synchronized void rollback(Xid xid) throws XAException {
    checkXAActive();
    // ensure immtable and correct equals method.
    XAXactId xid_im = new XAXactId(xid);
    XATransactionState tranState = getTransactionState(xid_im);
    if (tranState == null) {
        XAResourceManager rm = ra.getXAResourceManager();
        ContextManager inDoubtCM = rm.find(xid);
        // RM also does not know about this xid.
        if (inDoubtCM == null)
            throw new XAException(XAException.XAER_NOTA);
        ContextService csf = getContextService();
        csf.setCurrentContextManager(inDoubtCM);
        try {
            rm.rollback(inDoubtCM, xid_im);
            // close the connection/transaction since it can never be used again.
            inDoubtCM.cleanupOnError(StandardException.closeException(), false);
            return;
        } catch (StandardException se) {
            // The rm threw an exception, clean it up in the approprate
            // context.  There is no transactionResource to handle the
            // exception for us.
            inDoubtCM.cleanupOnError(se, con.isActive());
            throw wrapInXAException(se);
        } finally {
            csf.resetCurrentContextManager(inDoubtCM);
        }
    }
    synchronized (tranState) {
        // any XAResource.
        switch(tranState.associationState) {
            case XATransactionState.T0_NOT_ASSOCIATED:
            case XATransactionState.TRO_FAIL:
                break;
            default:
                throw new XAException(XAException.XAER_PROTO);
        }
        if (tranState.suspendedList != null && tranState.suspendedList.size() != 0)
            throw new XAException(XAException.XAER_PROTO);
        checkUserCredentials(tranState.creatingResource);
        try {
            tranState.xa_rollback();
        } catch (SQLException sqle) {
            throw wrapInXAException(sqle);
        } finally {
            returnConnectionToResource(tranState, xid_im);
        }
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) XAXactId(org.apache.derby.iapi.store.access.xa.XAXactId) ContextService(org.apache.derby.iapi.services.context.ContextService) XAException(javax.transaction.xa.XAException) XAResourceManager(org.apache.derby.iapi.store.access.xa.XAResourceManager) SQLException(java.sql.SQLException) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Example 3 with ContextService

use of org.apache.derby.iapi.services.context.ContextService in project derby by apache.

the class DataDictionaryImpl method boot.

/**
 * Start-up method for this instance of the data dictionary.
 *
 * @param startParams	The start-up parameters
 *
 *	@exception StandardException	Thrown if the module fails to start
 */
public void boot(boolean create, Properties startParams) throws StandardException {
    softwareVersion = new DD_Version(this, DataDictionary.DD_VERSION_DERBY_10_15);
    startupParameters = startParams;
    uuidFactory = getMonitor().getUUIDFactory();
    engineType = Monitor.getEngineType(startParams);
    // Set the collation type of system schemas before we start loading
    // built-in schemas's SchemaDescriptor(s). This is because
    // SchemaDescriptor will look to DataDictionary to get the correct
    // collation type for themselves. We can't load SD for SESSION schema
    // just yet because we do not know the collation type for user schemas
    // yet. We will know the right collation for user schema little later
    // in this boot method.
    collationTypeOfSystemSchemas = StringDataValue.COLLATION_TYPE_UCS_BASIC;
    getBuiltinSystemSchemas();
    // REMIND: actually, we're supposed to get the DataValueFactory
    // out of the connection context...this is a bit of a shortcut.
    // We get the DataValueFactory early in order to help bootstrap the system catalogs.
    LanguageConnectionFactory langConnFactory = (LanguageConnectionFactory) bootServiceModule(create, this, LanguageConnectionFactory.MODULE, startParams);
    dvf = langConnFactory.getDataValueFactory();
    exFactory = (ExecutionFactory) bootServiceModule(create, this, ExecutionFactory.MODULE, startParams);
    // initailze the arrays of core and noncore tables
    initializeCatalogInfo();
    // indicate that we are in the process of booting
    booting = true;
    // set only if child class hasn't overriden this already
    if (dataDescriptorGenerator == null) {
        dataDescriptorGenerator = new DataDescriptorGenerator(this);
    }
    if (!create) {
        // SYSTABLES
        coreInfo[SYSTABLES_CORE_NUM].setHeapConglomerate(getBootParameter(startParams, CFG_SYSTABLES_ID, true));
        coreInfo[SYSTABLES_CORE_NUM].setIndexConglomerate(SYSTABLESRowFactory.SYSTABLES_INDEX1_ID, getBootParameter(startParams, CFG_SYSTABLES_INDEX1_ID, true));
        coreInfo[SYSTABLES_CORE_NUM].setIndexConglomerate(SYSTABLESRowFactory.SYSTABLES_INDEX2_ID, getBootParameter(startParams, CFG_SYSTABLES_INDEX2_ID, true));
        // SYSCOLUMNS
        coreInfo[SYSCOLUMNS_CORE_NUM].setHeapConglomerate(getBootParameter(startParams, CFG_SYSCOLUMNS_ID, true));
        coreInfo[SYSCOLUMNS_CORE_NUM].setIndexConglomerate(SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX1_ID, getBootParameter(startParams, CFG_SYSCOLUMNS_INDEX1_ID, true));
        // 2nd syscolumns index added in Xena, hence may not be there
        coreInfo[SYSCOLUMNS_CORE_NUM].setIndexConglomerate(SYSCOLUMNSRowFactory.SYSCOLUMNS_INDEX2_ID, getBootParameter(startParams, CFG_SYSCOLUMNS_INDEX2_ID, false));
        // SYSCONGLOMERATES
        coreInfo[SYSCONGLOMERATES_CORE_NUM].setHeapConglomerate(getBootParameter(startParams, CFG_SYSCONGLOMERATES_ID, true));
        coreInfo[SYSCONGLOMERATES_CORE_NUM].setIndexConglomerate(SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX1_ID, getBootParameter(startParams, CFG_SYSCONGLOMERATES_INDEX1_ID, true));
        coreInfo[SYSCONGLOMERATES_CORE_NUM].setIndexConglomerate(SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX2_ID, getBootParameter(startParams, CFG_SYSCONGLOMERATES_INDEX2_ID, true));
        coreInfo[SYSCONGLOMERATES_CORE_NUM].setIndexConglomerate(SYSCONGLOMERATESRowFactory.SYSCONGLOMERATES_INDEX3_ID, getBootParameter(startParams, CFG_SYSCONGLOMERATES_INDEX3_ID, true));
        // SYSSCHEMAS
        coreInfo[SYSSCHEMAS_CORE_NUM].setHeapConglomerate(getBootParameter(startParams, CFG_SYSSCHEMAS_ID, true));
        coreInfo[SYSSCHEMAS_CORE_NUM].setIndexConglomerate(SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX1_ID, getBootParameter(startParams, CFG_SYSSCHEMAS_INDEX1_ID, true));
        coreInfo[SYSSCHEMAS_CORE_NUM].setIndexConglomerate(SYSSCHEMASRowFactory.SYSSCHEMAS_INDEX2_ID, getBootParameter(startParams, CFG_SYSSCHEMAS_INDEX2_ID, true));
    }
    String value = startParams.getProperty(Property.LANG_TD_CACHE_SIZE);
    tdCacheSize = PropertyUtil.intPropertyValue(Property.LANG_TD_CACHE_SIZE, value, 0, Integer.MAX_VALUE, Property.LANG_TD_CACHE_SIZE_DEFAULT);
    value = startParams.getProperty(Property.LANG_SPS_CACHE_SIZE);
    stmtCacheSize = PropertyUtil.intPropertyValue(Property.LANG_SPS_CACHE_SIZE, value, 0, Integer.MAX_VALUE, Property.LANG_SPS_CACHE_SIZE_DEFAULT);
    value = startParams.getProperty(Property.LANG_SEQGEN_CACHE_SIZE);
    seqgenCacheSize = PropertyUtil.intPropertyValue(Property.LANG_SEQGEN_CACHE_SIZE, value, 0, Integer.MAX_VALUE, Property.LANG_SEQGEN_CACHE_SIZE_DEFAULT);
    value = startParams.getProperty(Property.LANG_PERMISSIONS_CACHE_SIZE);
    permissionsCacheSize = PropertyUtil.intPropertyValue(Property.LANG_PERMISSIONS_CACHE_SIZE, value, 0, Integer.MAX_VALUE, Property.LANG_PERMISSIONS_CACHE_SIZE_DEFAULT);
    // See if automatic index statistics update is disabled through a
    // system wide property. May be overridden by a database specific
    // property later on.
    // The default is that automatic index statistics update is enabled.
    indexStatsUpdateDisabled = !PropertyUtil.getSystemBoolean(Property.STORAGE_AUTO_INDEX_STATS, true);
    // See if we should enable logging of index stats activities.
    indexStatsUpdateLogging = PropertyUtil.getSystemBoolean(Property.STORAGE_AUTO_INDEX_STATS_LOGGING);
    // See if we should enable tracing of index stats activities.
    indexStatsUpdateTracing = PropertyUtil.getSystemProperty(Property.STORAGE_AUTO_INDEX_STATS_TRACING, "off");
    /*
		 * data dictionary contexts are only associated with connections.
		 * we have to look for the basic data dictionary, as there is
		 * no connection, and thus no context stack yet.
		 */
    /*
		 * Get the table descriptor cache.
		 */
    CacheFactory cf = (CacheFactory) startSystemModule(org.apache.derby.shared.common.reference.Module.CacheFactory);
    OIDTdCache = cf.newCacheManager(this, "TableDescriptorOIDCache", tdCacheSize, tdCacheSize);
    nameTdCache = cf.newCacheManager(this, "TableDescriptorNameCache", tdCacheSize, tdCacheSize);
    if (stmtCacheSize > 0) {
        spsNameCache = cf.newCacheManager(this, "SPSNameDescriptorCache", stmtCacheSize, stmtCacheSize);
        spsIdHash = new Hashtable<UUID, SPSDescriptor>(stmtCacheSize);
    // spsTextHash = new Hashtable(stmtCacheSize);
    }
    sequenceGeneratorCache = cf.newCacheManager(this, "SequenceGeneratorCache", seqgenCacheSize, seqgenCacheSize);
    sequenceIDs = new HashMap<String, HashMap<String, String>>();
    /* Get the object to coordinate cache transitions */
    cacheCoordinator = new ShExLockable();
    /* Get AccessFactory in order to transaction stuff */
    af = (AccessFactory) findServiceModule(this, AccessFactory.MODULE);
    /* Get the lock factory */
    lockFactory = af.getLockFactory();
    /*
		 * now we need to setup a context stack for the database creation work.
		 * We assume the System boot process has created a context
		 * manager already, but not that contexts we need are there.
		 */
    ContextService csf = getContextService();
    ContextManager cm = csf.getCurrentContextManager();
    if (SanityManager.DEBUG)
        SanityManager.ASSERT((cm != null), "Failed to get current ContextManager");
    // RESOLVE other non-StandardException errors.
    bootingTC = null;
    try {
        // Get a transaction controller. This has the side effect of
        // creating a transaction context if there isn't one already.
        bootingTC = af.getTransaction(cm);
        /*
				We need an execution context so that we can generate rows
				REMIND: maybe only for create case?
			 */
        exFactory.newExecutionContext(cm);
        DataDescriptorGenerator ddg = getDataDescriptorGenerator();
        // We should set the user schema collation type here now because
        // later on, we are going to create user schema APP. By the time any
        // user schema gets created, we should have the correct collation
        // type set for such schemas to use. For this reason, don't remove
        // the following if else statement and don't move it later in this
        // method.
        String userDefinedCollation;
        if (create) {
            // Get the collation attribute from the JDBC url. It can only
            // have one of 2 possible values - UCS_BASIC or TERRITORY_BASED
            // This attribute can only be specified at database create time.
            // The attribute value has already been verified in DVF.boot and
            // hence we can be assured that the attribute value if provided
            // is either UCS_BASIC or TERRITORY_BASED. If none provided,
            // then we will take it to be the default which is UCS_BASIC.
            userDefinedCollation = startParams.getProperty(Attribute.COLLATION, Property.UCS_BASIC_COLLATION);
            bootingTC.setProperty(Property.COLLATION, userDefinedCollation, true);
        } else {
            userDefinedCollation = startParams.getProperty(Property.COLLATION, Property.UCS_BASIC_COLLATION);
        }
        // Initialize the collation type of user schemas by looking at
        // collation property/attribute.
        collationTypeOfUserSchemas = DataTypeDescriptor.getCollationType(userDefinedCollation);
        if (SanityManager.DEBUG)
            SanityManager.ASSERT((collationTypeOfUserSchemas != -1), "Invalid collation type: " + userDefinedCollation);
        // Now is also a good time to create schema descriptor for global
        // temporary tables. Since this is a user schema, it should use the
        // collation type associated with user schemas. Since we just
        // finished setting up the collation type of user schema, it is
        // safe to create user SchemaDescriptor(s) now.
        declaredGlobalTemporaryTablesSchemaDesc = newDeclaredGlobalTemporaryTablesSchemaDesc(SchemaDescriptor.STD_DECLARED_GLOBAL_TEMPORARY_TABLES_SCHEMA_NAME);
        boolean nativeAuthenticationEnabled = PropertyUtil.nativeAuthenticationEnabled(startParams);
        if (create) {
            String userName = IdUtil.getUserNameFromURLProps(startParams);
            authorizationDatabaseOwner = IdUtil.getUserAuthorizationId(userName);
            HashSet<String> newlyCreatedRoutines = new HashSet<String>();
            // log the current dictionary version. Moving this statement to top as SYSCOLUMNSRowFactory
            // queries the version info. SEE Derby-6904
            dictionaryVersion = softwareVersion;
            // create any required tables.
            createDictionaryTables(startParams, bootingTC, ddg);
            // create procedures for network server metadata
            create_SYSIBM_procedures(bootingTC, newlyCreatedRoutines);
            // create metadata sps statement required for network server
            createSystemSps(bootingTC);
            // create the SYSCS_UTIL system procedures)
            create_SYSCS_procedures(bootingTC, newlyCreatedRoutines);
            // now grant execute permission on some of these routines
            grantPublicAccessToSystemRoutines(newlyCreatedRoutines, bootingTC, authorizationDatabaseOwner);
            /* Set properties for current and create time 
				 * DataDictionary versions.
				 */
            bootingTC.setProperty(DataDictionary.CORE_DATA_DICTIONARY_VERSION, dictionaryVersion, true);
            bootingTC.setProperty(DataDictionary.CREATE_DATA_DICTIONARY_VERSION, dictionaryVersion, true);
            // 
            if (PropertyUtil.getSystemBoolean(Property.SQL_AUTHORIZATION_PROPERTY)) {
                bootingTC.setProperty(Property.SQL_AUTHORIZATION_PROPERTY, "true", true);
            }
            if (PropertyUtil.getSystemBoolean(Property.SQL_AUTHORIZATION_PROPERTY) || nativeAuthenticationEnabled) {
                usesSqlAuthorization = true;
            }
            // Set default hash algorithm used to protect passwords stored
            // in the database for BUILTIN and NATIVE authentication.
            bootingTC.setProperty(Property.AUTHENTICATION_BUILTIN_ALGORITHM, findDefaultBuiltinAlgorithm(), false);
        } else {
            // Get the ids for non-core tables
            loadDictionaryTables(bootingTC, startParams);
            // See if index stats update is disabled by a database prop.
            String dbIndexStatsUpdateAuto = PropertyUtil.getDatabaseProperty(bootingTC, Property.STORAGE_AUTO_INDEX_STATS);
            if (dbIndexStatsUpdateAuto != null) {
                indexStatsUpdateDisabled = !Boolean.valueOf(dbIndexStatsUpdateAuto).booleanValue();
            }
            String dbEnableIndexStatsLogging = PropertyUtil.getDatabaseProperty(bootingTC, Property.STORAGE_AUTO_INDEX_STATS_LOGGING);
            if (dbEnableIndexStatsLogging != null) {
                indexStatsUpdateLogging = Boolean.valueOf(dbEnableIndexStatsLogging).booleanValue();
            }
            String dbEnableIndexStatsTracing = PropertyUtil.getDatabaseProperty(bootingTC, Property.STORAGE_AUTO_INDEX_STATS_TRACING);
            if (dbEnableIndexStatsTracing != null) {
                if (!(dbEnableIndexStatsTracing.equalsIgnoreCase("off") || dbEnableIndexStatsTracing.equalsIgnoreCase("log") || dbEnableIndexStatsTracing.equalsIgnoreCase("stdout") || dbEnableIndexStatsTracing.equalsIgnoreCase("both"))) {
                    indexStatsUpdateTracing = "off";
                } else {
                    indexStatsUpdateTracing = dbEnableIndexStatsTracing;
                }
            }
            String sqlAuth = PropertyUtil.getDatabaseProperty(bootingTC, Property.SQL_AUTHORIZATION_PROPERTY);
            // Feature compatibility check.
            if (Boolean.valueOf(startParams.getProperty(Attribute.SOFT_UPGRADE_NO_FEATURE_CHECK)).booleanValue()) {
                // database owner check at a hard upgrade.
                if (dictionaryVersion.majorVersionNumber >= DataDictionary.DD_VERSION_DERBY_10_2) {
                    usesSqlAuthorization = Boolean.valueOf(sqlAuth).booleanValue() || nativeAuthenticationEnabled;
                }
            } else {
                if (Boolean.valueOf(sqlAuth).booleanValue() || nativeAuthenticationEnabled) {
                    // SQL authorization requires 10.2 or higher database
                    checkVersion(DataDictionary.DD_VERSION_DERBY_10_2, "sqlAuthorization");
                    usesSqlAuthorization = true;
                }
            }
        }
        if (SanityManager.DEBUG)
            SanityManager.ASSERT((authorizationDatabaseOwner != null), "Failed to get Database Owner authorization");
        /* Commit & destroy the create database */
        bootingTC.commit();
        // done with ctx
        cm.getContext(ExecutionContext.CONTEXT_ID).popMe();
    } finally {
        if (bootingTC != null) {
            // gets rid of the transaction context
            bootingTC.destroy();
            bootingTC = null;
        }
    }
    setDependencyManager();
    booting = false;
}
Also used : ContextService(org.apache.derby.iapi.services.context.ContextService) ShExLockable(org.apache.derby.iapi.services.locks.ShExLockable) HashMap(java.util.HashMap) DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) LanguageConnectionFactory(org.apache.derby.iapi.sql.conn.LanguageConnectionFactory) ContextManager(org.apache.derby.iapi.services.context.ContextManager) CacheFactory(org.apache.derby.iapi.services.cache.CacheFactory) UUID(org.apache.derby.catalog.UUID) SPSDescriptor(org.apache.derby.iapi.sql.dictionary.SPSDescriptor) HashSet(java.util.HashSet)

Example 4 with ContextService

use of org.apache.derby.iapi.services.context.ContextService in project derby by apache.

the class T_Bomb method blowUp.

private void blowUp() {
    performLastGasp();
    ContextService csf = getContextService();
    if (csf != null) {
        System.out.println("ran out of time");
        csf.notifyAllActiveThreads((Context) null);
    }
    try {
        // Give threads 30 sec to shut down.
        Thread.currentThread().sleep(30 * 1000);
    } catch (InterruptedException ie) {
    }
    System.out.println("Exit due to time bomb");
    Runtime.getRuntime().exit(1234);
}
Also used : ContextService(org.apache.derby.iapi.services.context.ContextService)

Example 5 with ContextService

use of org.apache.derby.iapi.services.context.ContextService in project derby by apache.

the class T_CreateConglomRet method t_002.

/**
 * Test backout during critical times of splits.
 * <p>
 * Use trace points to force errors in split at critical points:
 *     leaf_split_abort{1,2,3,4}
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_002(TransactionController tc) throws StandardException, T_Fail {
    ScanController scan = null;
    // SanityManager.DEBUG_SET("LockTrace");
    REPORT("Starting t_002");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    // Create the btree so that it only allows 2 rows per page.
    createCongloms(tc, 2, false, false, 2, create_ret);
    // Open the base table
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the secondary index
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    if (!(index_cc instanceof B2IController)) {
        throw T_Fail.testFailMsg("openConglomerate returned wrong type");
    }
    index_cc.checkConsistency();
    // Create a row and insert into base table, remembering it's location.
    DataValueDescriptor[] r1 = TemplateRow.newU8Row(2);
    T_SecondaryIndexRow index_row1 = new T_SecondaryIndexRow();
    RowLocation base_rowloc1 = base_cc.newRowLocationTemplate();
    index_row1.init(r1, base_rowloc1, 3);
    // Commit the create of the tables so that the following aborts don't
    // undo that work.
    tc.commit();
    // Now try aborts of transactions during splits, using magic
    // trace flags.  This test inserts enough rows to cause a split
    // and then forces the split to fail at various key points.  The
    // split should be backed out and also the rows before the split.
    // The test makes sure that there are some inserts before the forced
    // split abort.
    String[] debug_strings = { "leaf_split_growRoot1", "leaf_split_growRoot2", "leaf_split_growRoot3", "leaf_split_growRoot4", "leaf_split_growRoot5", "leaf_split_abort1", "leaf_split_abort2", "leaf_split_abort3", "leaf_split_abort4", "branch_split_abort1", "branch_split_abort2", "branch_split_abort3", "branch_split_abort4", "BTreeController_doIns2" };
    for (int errs = 0; errs < debug_strings.length; errs++) {
        REPORT("Doing abort test: " + debug_strings[errs]);
        if (SanityManager.DEBUG)
            SanityManager.DEBUG_SET(debug_strings[errs]);
        try {
            // Open the base table
            base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
            // Open the secondary index
            index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
            // insert one row that does not cause failure.
            ((SQLLongint) r1[0]).setValue(2);
            ((SQLLongint) r1[1]).setValue(10000 + errs);
            // Insert the row into the base table;remember its location.
            base_cc.insertAndFetchLocation(r1, base_rowloc1);
            // Insert the row into the secondary index.
            if (index_cc.insert(index_row1.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
            // language to make sure error handling really works.
            if (SanityManager.DEBUG)
                SanityManager.DEBUG_SET(debug_strings[errs]);
            // now insert enough rows to cause failure
            for (int i = 100; i > 0; i -= 2) {
                ((SQLLongint) r1[0]).setValue(2);
                ((SQLLongint) r1[1]).setValue(i);
                // Insert the row into the base table;remember its location.
                base_cc.insertAndFetchLocation(r1, base_rowloc1);
                // Insert the row into the secondary index.
                if (index_cc.insert(index_row1.getRow()) != 0) {
                    throw T_Fail.testFailMsg("insert failed");
                }
            }
            throw T_Fail.testFailMsg("debug flag (" + debug_strings[errs] + ")did not cause exception.");
        } catch (StandardException e) {
            ContextService contextFactory = getContextService();
            // Get the context manager.
            ContextManager cm = contextFactory.getCurrentContextManager();
            if (SanityManager.DEBUG)
                SanityManager.ASSERT(cm != null);
            cm.cleanupOnError(e, isdbActive());
            // RESOLVE (mikem) - when split abort works come up with
            // a good sanity check here.
            // 
            // index check - there should be no records:
            scan = tc.openScan(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, null, ScanController.NA, null, null, ScanController.NA);
            index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
            index_cc.checkConsistency();
            index_cc.close();
            if (scan.next()) {
                throw T_Fail.testFailMsg("t_002: there are still rows in table.");
            }
            scan.close();
        }
        // Unset the flag.
        if (SanityManager.DEBUG)
            SanityManager.DEBUG_CLEAR(debug_strings[errs]);
    }
    // Try a simple abort.  The following adds enough rows to cause a
    // split.  The result of the split should be a tree with no rows, but
    // the splits will not be undone.  It is up to the implementation
    // whether the undo's cause shrinks in the tree.  In the initial
    // implementation it won't.
    {
        tc.commit();
        // Open the base table
        base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        // Open the secondary index
        index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        // Make sure that normal abort leaves the committed split.
        for (int i = 0; i < 3; i++) {
            ((SQLLongint) r1[0]).setValue(2);
            ((SQLLongint) r1[1]).setValue(i);
            // Insert the row into the base table;remember its location.
            base_cc.insertAndFetchLocation(r1, base_rowloc1);
            // Insert the row into the secondary index.
            if (index_cc.insert(index_row1.getRow()) != 0)
                throw T_Fail.testFailMsg("insert failed");
        }
        tc.abort();
        // index check - there should be no records left.
        ScanController empty_scan = tc.openScan(create_ret.index_conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, null, ScanController.NA, null, null, ScanController.NA);
        if (empty_scan.next()) {
            throw T_Fail.testFailMsg("t_002: there are still rows in table.");
        }
    }
    tc.commit();
    REPORT("Ending t_002");
    return true;
}
Also used : ScanController(org.apache.derby.iapi.store.access.ScanController) ContextService(org.apache.derby.iapi.services.context.ContextService) ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) StandardException(org.apache.derby.shared.common.error.StandardException) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ContextManager(org.apache.derby.iapi.services.context.ContextManager) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Aggregations

ContextService (org.apache.derby.iapi.services.context.ContextService)10 ContextManager (org.apache.derby.iapi.services.context.ContextManager)7 StandardException (org.apache.derby.shared.common.error.StandardException)7 XAException (javax.transaction.xa.XAException)3 XAResourceManager (org.apache.derby.iapi.store.access.xa.XAResourceManager)3 XAXactId (org.apache.derby.iapi.store.access.xa.XAXactId)3 SQLException (java.sql.SQLException)2 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)2 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)2 ScanController (org.apache.derby.iapi.store.access.ScanController)2 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 RowLocation (org.apache.derby.iapi.types.RowLocation)2 SQLLongint (org.apache.derby.iapi.types.SQLLongint)2 AccessControlException (java.security.AccessControlException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Properties (java.util.Properties)1 UUID (org.apache.derby.catalog.UUID)1