Showing posts with label database. Show all posts
Showing posts with label database. Show all posts

Tuesday, 24 December 2013

Difference between XA and NonXA DataSource and Limitations with NonXA

Difference between XA and NonXA DataSource
An XA transaction, in the most general terms, is a "global transaction" that may span multiple resources. A non-XA transaction always involves just one resource.

An XA transaction involves a coordinating transaction manager, with one or more databases (or other resources, like JMS) all involved in a single global transaction. Non-XA transactions have no transaction coordinator, and a single resource is doing all its transaction work itself (this is sometimes called local transactions).

XA transactions come from the X/Open group specification on distributed, global transactions. JTA includes the X/Open XA spec, in modified form.

Most stuff in the world is non-XA - a Servlet or EJB or plain old JDBC in a Java application talking to a single database. XA gets involved when you want to work with multiple resources - 2 or more databases, a database and a JMS connection, all of those plus maybe a JCA resource - all in a single transaction. In this scenario, you'll have an app server like Websphere or Weblogic or JBoss acting as the Transaction Manager, and your various resources (Oracle, Sybase, IBM MQ JMS, SAP, whatever) acting as transaction resources. Your code can then update/delete/publish/whatever across the many resources. When you say "commit", the results are commited across all of the resources. When you say "rollback", _everything_ is rolled back across all resources.

The Transaction Manager coordinates all of this through a protocol called Two Phase Commit (2PC). This protocol also has to be supported by the individual resources.

In terms of datasources, an XA datasource is a data source that can participate in an XA global transaction. A non-XA datasource generally can't participate in a global transaction (sort of - some people implement what's called a "last participant" optimization that can let you do this for exactly one non-XA item).

For more details - see the JTA pages on java.sun.com. Look at the XAResource and Xid interfaces in JTA. See the X/Open XA Distributed Transaction specification. Do a google source on "Java JTA XA transaction".

Ref : http://www.theserverside.com/discussions/thread.tss?thread_id=21385

Limitations and Risks When Using a Non-XA Driver in Global Transactions

WebLogic Server supports the participation of non-XA JDBC resources in global transactions, but there are limitations that you must consider when designing applications to use such resources. Because a non-XA driver does not adhere to the XA/2PC contracts and only supports one-phase commit and rollback operations, WebLogic Server (through the JTS driver) has to make compromises to allow the resource to participate in a transaction controlled by the Transaction Manager.
Consider the following limitations and risks before using the Emulate Two-Phase Commit for non-XA Driver option.

Heuristic Completions and Data Inconsistency

When Emulate Two-Phase Commit is selected for a non-XA resource, (enableTwoPhaseCommit = true), the prepare phase of the transaction for the non-XA resource always succeeds. Therefore, the non-XA resource does not truly participate in the two-phase commit (2PC) protocol and is susceptible to failures. If a failure occurs in the non-XA resource after the prepare phase, the non-XA resource is likely to roll back the transaction while XA transaction participants will commit the transaction, resulting in a heuristic completion and data inconsistencies.
Because of the data integrity risks, the Emulate Two-Phase Commit option should only be used in applications that can tolerate heuristic conditions.

Cannot Recover Pending Transactions

Because a non-XA driver manipulates local database transactions only, there is no concept of a transaction pending state in the database with regard to an external transaction manager. When XAResource.recover() is called on the non-XA resource, it always returns an empty set of Xids (transaction IDs), even though there may be transactions that need to be committed or rolled back. Therefore, applications that use a non-XA resource in a global transaction cannot recover from a system failure and maintain data integrity.

Possible Performance Loss with Non-XA Resources in Multi-Server Configurations

Because WebLogic Server relies on the database local transaction associated with a particular JDBC connection to support non-XA resource participation in a global transaction, when the same JDBC data source is accessed by an application with a global transaction context on multiple WebLogic Server instances, the JTS driver will always route JDBC operations to the first connection established by the application in the transaction. For example, if an application starts a transaction on one server, accesses a non-XA JDBC resource, then makes a remote method invocation (RMI) call to another server and accesses a data source that uses the same underlying JDBC driver, the JTS driver recognizes that the resource has a connection associated with the transaction on another server and sets up an RMI redirection to the actual connection on the first server. All operations on the connection are made on the one connection that was established on the first server. This behavior can result in a performance loss due to the overhead associated with setting up these remote connections and making the RMI calls to the one physical connection.

Only One Non-XA Participant

When a non-XA resource (with Emulate Two-Phase Commit selected) is registered with the WebLogic Server Transaction Manager, it is registered with the name of the class that implements the XAResource interface. Since all non-XA resources with Emulate Two-Phase Commit selected use the JTS driver for the XAResource interface, all non-XA resources (with Emulate Two-Phase Commit selected) that participate in a global transaction are registered with the same name. If you use more than one non-XA resource in a global transaction, you will see naming conflicts or possible heuristic failures.

Ref :http://docs.oracle.com/cd/E13222_01/wls/docs81/ConsoleHelp/jdbc_datasources.html

Monday, 28 October 2013

Databse Query to count the number of instances of a composite



Connect to your infra database and below is the query

select state,
     count(*) Count,
     TO_CHAR(creation_date,'YYYY-MM-DD'),
    trunc(Max(extract(day    from (modify_date-creation_date))*24*60*60 +
              extract(hour   from (modify_date-creation_date))*60*60 +
              extract(minute from (modify_date-creation_date))*60 +
              extract(second from (modify_date-creation_date))),4) MaxTime,
    trunc(Min(extract(day    from (modify_date-creation_date))*24*60*60 +
              extract(hour   from (modify_date-creation_date))*60*60 +
              extract(minute from (modify_date-creation_date))*60 +
              extract(second from (modify_date-creation_date))),4) MinTime,
    trunc(AVG(extract(day    from (modify_date-creation_date))*24*60*60 +
              extract(hour   from (modify_date-creation_date))*60*60 +
              extract(minute from (modify_date-creation_date))*60 +
              extract(second from (modify_date-creation_date))),4) AvgTime,
     composite_name Composite, component_name Process, componenttype
     from cube_instance
     where creation_date >= sysdate -1 and composite_name='COMPOSITENAME'
      group by state, TO_CHAR(creation_date,'YYYY-MM-DD'), composite_name, component_name, componenttype
        order by count(*) desc;


Sysdate - 1 will return you the last 24 hours instances.

To check the transactions

SELECT * FROM CUBE_INSTANCE WHERE creation_date >= sysdate-1 and
    COMPOSITE_NAME='xoxoxo' order by creation_date desc;


Deploy, Undeploy, Start and Stop Composites


locate wlst.sh

/XXX/soa/middleware/oracle_soa/common/bin/wlst.sh

sca_deployComposite( "http://soaserver:port" ,  "location/Filename.jar")

sca_undeployComposite( 'http://soaserver:port' , 'CompositeName(ServiceName)' , 'version' , 'username' , 'Password' )

sca_stopComposite("soa server", "port", "username", "Password" , "CompositeName" , "Composite Version")

sca_startComposite("soa server", "port", "username", "Password" , "CompositeName" , "Composite Version")

Tuesday, 5 February 2013

BPEL Dehydration Table Descriptions

Main tables used by the BPEL engine
cube_instance – stores instance metadata, eg. instance creation date, current state, title, process identifier
cube_scope – stores the scope data for an instance … all the variables declared in the bpel flow are stored here, as well as some internal objects to help route logic throughout the flow.
work_item – stores activities created by an instance … all BPEL activities in a flow will have a work_item created for it. This work item row contains meta data for the activity … current state, label, expiration date (used by wait activities) … when the engine needs to be restarted and instances recovered, pending flows are resumed by inspecting their unfinished work items.
document - stores large XML variables. If a variable gets to be larger than a specific size (configurable via the largeDocumentThreshold property via the domain configuration page) then the variable is stored in this table to alleviate loading/saving time from the cube_scope table.
audit_trail - stores the audit trail for instances. The audit trail viewed from the console is modelled from an XML document. As the instance is worked on, each activity writes out events to the audit trail as XML which is compressed and stored in a raw column. Querying the audit trail via the API/console will join the raw columns together and uncompress the contents into a single XML document.
audit_details - audit details can be logged via the api … by default activities such as assign log the variables as audit details (this behavior can be set via the auditLevel property on the domain configuration page). Details are separated from the audit trail because they tend to be very large in size … if the user wishes to view a detail they click a link from the audit trail page and load the detail separately. There is a threshold value for details too … if the size of a detail is larger than a specific value (see auditDetailThreshold) then it is place in this table, otherwise it is merged into the audit trail row.
dlv_message – callback messages are stored here. All non-invocation messages are saved here upon receipt. The delivery layer will then attempt to correlate the message with the receiving instance. This table only stores the metadata for a message. (eg. current state, process identifier, receive date).
dlv_message_bin – stores the payload of a callback message. The metadata of a callback message is kept in the dlv_message table, this table only stores the payload as a blob. This separation allows the metadata to change frequently without being impacted by the size of the payload (which is stored here and never modified).
dlv_subscription – stores delivery subscriptions for an instance. Whenever an instance expects a message from a partner (eg. receive, onMessage) a subscription is written out for that specific receive activity. Once a delivery message is received the delivery layer attempts to correlate the message with the intended subscription.
invoke_message – stores invocation messages, messages which will result in the creation of a instance. This table only stores the metadata for an invocation message (eg. current state, process identifier, receive date).
invoke_message_bin – stores the payload of an invocation message. Serves the same purpose the dlv_message_bin table does for dlv_message.
task – stores tasks created for an instance. The TaskManager process keeps its current state in this table. Upon calling invoking the TaskManager process, a task object is created, with a title, assignee, status, expiration date, etc… When updates are made to the TaskManager instance via the console the underlying task object in the db is changed.
schema_md – (just added via patch delivered to Veerle) contains metadata about columns defined in the orabpel schema. Use case driving this feature was how to change the size of a custom_key column for a cube_instance row? Changing the db schema was simple but the engine code assumed a certain length and truncated values to match that length to avoid a db error being thrown. Now, column lengths are defined in this table instead of being specified in the code. To change a column length, change the column definition in the table, then change the value specified in this table, then restart the server.
Column-by-column description:
table ci_id_range
- next_range (integer) – instance ids in the system are allocated on a block basis … once all the ids from a block have been allocated, another block is fetched, next_range specifies the start of the next block.
table cube_instance
- cikey (integer) – primary key … foreign key for other tables
- domain_ref (smallint) – domain identifier is encoded as a integer to save space, can be resolved by joining with domain.domain_ref.
- process_id (varchar) – process id
- revision_tag (varchar) – revision tag
- creation_date (date)
- creator (varchar) – user who created instance … currently not used
- modify_date (date) – date instance was last modified
- modifier (varchar) – user who last modified instance … currently not used
- state (integer) – current state of instance, see com.oracle.bpel.client.IInstanceConstants for values
- priority (integer) – current instance priority (user specified, has no impact on engine)
- title (varchar) – current instance title (user specified, no engine impact)
- status (varchar) – current status (user specified)
- stage (varchar) – current stage (user specified)
- conversation_id (varchar) – extra identifier associated with instance, eg. if passed in via WS-Addressing or user specified custom key.
- root_id (varchar) – the conversation id of the instance at the top of the invocation tree. Suppose A -> B -> C, root( B ) = A, root( C ) = A, parent( B ) = A, parent( C ) = B. This instance, instance at the top of the tree will not have this set.
- parent_id (varchar) – the conversation id of the parent instance that created this instance, instance at the top of the tree will not have this set.
- scope_revision (integer) – internal checksum of scope bytes … used to keep caches in sync
- scope_csize (integer) – compressed size of instance scope in bytes
- scope_usize (integer) – uncompressed size of instance scope in bytes
- process_guid (varchar) – unique identifier for the process this instance belongs to … if changes need to be made for all instances of a process, this column is used to query (eg. stale process).
- process_type (integer) – internal
- metadata (varchar) – user specified

table cube_scope
- cikey (integer) – foreign key
- domain_ref (integer) – domain identifier
- modify_date (date) – date scope last modified
- scope_bin (blob) – scope bytes

table work_item
- cikey (integer) – foreign key
- node_id (varchar) – part of work item composite key, identifier for bpel activity that this work item created for
- scope_id (varchar) – part of work item composite key, identifier for internal scope that this work item created for (note this is not the scope declared in bpel, the engine has an internal scope tree that it creates for each instance, bpel scopes will map to an internal scope but there will be other internal scopes that have no mapping to the bpel definition).
- count_id (integer) – part of work item composite key, used to distinguish between work items created from same activity in the same scope.
- domain_ref (integer) – domain identifier
- creation_date (date)
- creator (varchar) – user who created work item … currently not used
- modify_date (date) – date work item was last modified
- modifier (varchar) – user who last modified work item … currently not used
- state (integer) – current state of work item, see com.oracle.bpel.client.IActivityConstants for values
- transition (integer) – internal use, used by engine for routing logic
- exception (integer) – no longer used
- exp_date (date) – expiration date for this work item; wait, onAlarm activities are implemented as expiration timers.
- exp_flag (integer) – set if a work item has been called back by the expiration agent (ie. expired).
- priority (integer) – priority of work item, user specified, no engine impact
- label (varchar) – current label (user specified, no engine impact)
- custom_id (varchar) – custom identifier (user specified, no engine impact)
- comments (varchar) – comment field (user specified, no engine impact)
- reference_id (varchar) -
- idempotent_flag (integer) – internal use
- process_guid (varchar) – unique identifier for the process this work item belongs to … if changes need to be made for all instances of a process, this column is used to query (eg. stale process).

table document
- dockey (varchar) – primary key for document
- cikey (integer) – foreign key
- domain_ref (integer) – domain identifier
- classname (varchar) – no longer used
- bin_csize (integer) – compressed size of document in bytes
- bin_usize (integer) – uncompressed size of document in bytes
- bin (blob) – document bytes
- modify_date (date) – date document was last modified

table audit_trail
- cikey (integer) – foreign key
- domain_ref – domain identifier
- count_id (integer) – many audit trail entries may be made for each instance, this column is incremented for each entry per instance.
- block (integer) – when the instance is dehydrated, the batched audit trail entries up to that point are written out … this block ties together all rows written out at one time.
- block_csize (integer) – compressed size of block in bytes
- block_usize (integer) – uncompressed size of block in bytes
- log (raw) – block bytes

table audit_details
- cikey (integer) – foreign key
- domain_ref (integer) – domain identifier
- detail_id (integer) – part of composite key, means of identifying particular detail from the audit trail
- bin_csize (integer) – compressed size of detail in bytes
- bin_usize (integer) – uncompressed size of detail in bytes
- bin (blob) – detail bytes

table dlv_message
- conv_id (varchar) – conversation id (correlation id) for the message…this value is used to correlate the message to the subscription.
- conv_type (integer) – internal use
- message_guid (varchar) – unique identifier for the message…each message received by the engine is tagged with a message guid.
- domain_ref (integer) – domain identifier
- process_id (varchar) – identifier for process to deliver the message to
- revision_tag (varchar) – identifier for process revision
- operation_name (varchar) – operation name for callback port.
- receive_date (date) – date message was received by engine
- state (integer) – current state of message … see com.oracle.bpel.client.IDeliveryConstants for values
- res_process_guid (varchar) – after the matching subscription is found, the process guid for the subscription is written out here. – res_subscriber (varchar) – identifier for matching subscription once found.

table dlv_message_bin
- message_guid (varchar) – unique identifier for message
- domain_ref (integer) – domain identifier
- bin_csize (integer) – compressed size of delivery message payload in bytes
- bin_usize (integer) – uncompressed size of delivery message payload in bytes
- bin (blob) – delivery message payload

table dlv_subscription
- conv_id (varchar) – conversation id for subscription, used to help correlate received delivery messages.
- conv_type (integer) – internal use
- cikey (integer) – foreign key
- domain_ref (integer) – domain identifier
- process_id (varchar) – process identifier for instance
- revision_tag (varchar) – revision tag for process
- process_guid (varchar) – guid for process this subscription belongs to
- operation_name (varchar) – operation name for subscription (receive, onMessage operation name).
- subscriber_id (varchar) – the work item composite key that this subscription is positioned at (ie. the key for the receive, onMessage work item).
- service_name (varchar) – internal use
- subscription_date (date) – date subscription was created
- state (integer) – current state of subscription … see com.oracle.bpel.client.IDeliveryConstants for values
- properties (varchar) – additional property settings for subscription

table invoke_message
- conv_id (varchar) – conversation id for message, passed into system so callbacks can correlate properly.
- message_guid (varchar) – unique identifier for message, generated when invocation message is received by engine.
- domain_ref (integer) – domain identifier
- process_id (varchar) – identifier for process to deliver the message to
- revision_tag (varchar) – revision tag for process
- operation_name (varchar) – operation name for receive activity
- receive_date (date) – date invocation message was received by engine
- state – current state of invocation message, see com.oracle.bpel.client.IDeliveryConstants for values
- priority (integer) – priority for invocation message, this value will be used by the engine dispatching layer to rank messages according to importance … lower values mean higher priority … messages with higher priority are dispatched to threads faster than messages with lower values.
- properties (varchar) – additional property settings for message

table invoke_message_bin
- message_guid (varchar) – unique identifier for message
- domain_ref (integer) – domain identifier
- bin_csize (integer) – compressed size of invocation message payload in bytes
- bin_usize (integer) – uncompressed size of invocation message payload in bytes
- bin (blob) – invocation message bytes

table task
- domain_ref (integer) – domain identifier
- conversation_id (varchar) – conversation id for task instance … allows task instance to callback to client
- title (varchar) – current title for task, user specified
- creation_date (date) – date task was created
- creator (varchar) – user who created task
- modify_date (date) – date task was last modified
- modifier (varchar) – user who last modified task
- assignee (varchar) – current assignee of task, user specified, no engine impact
- status (varchar) – current status, user specified, no engine impact
- expired (integer) – flag is set if task has expired
- exp_date (date) – expiration date for task, expiration actually takes place on work item in TaskManaged instance, upon expiration task row is updated
- priority (integer) – current task priority, user specified, no engine impact
- template (varchar) – not used
- custom_key (varchar) – user specified custom key
- conclusion (varchar) – user specified conclusion, no engine impact

Monday, 4 February 2013

Database tables used to store the instance details

I was working on a task this week, where I had to extract the RAW xml in the audit tab of an instance. Since all the details that are rendered on the BPEL console are from the database, I started to explore some details on the tables used in SOA. The tables are more or less common to 10g as well as 11g, which very little variations. I was going though some of the tables present in the database and below is the information I gathered.  I have shown below some non empty and key fields from the table. There are more fields available in the table and can be viewed from the database:

CUBE_INSTANCE
This table stores the basic information of an instance such as State, Domain name, Composite name, composite revision, Component name etc. A CI Key is created for every Composite Id and the CI key is used in other tables as the reference




CUBE_SCOPE
It stores the data available in the scope of an instance like the bpel variables that have been created, values of those variables etc.




AUDIT_TRAIL
This stores the complete the audit trail of an instance, provided the auditDetailThreshold is not reached. If the auditDetailThreshold is reached, the details are spilled to audit_details table. The instance details are stored in the RAW format and you would have to join the columns together and uncompress the RAW format to view in the readable xml format. The column LOG contains the RAW message




AUDIT_DETAILS
The details like the assign activities are stored here. The information that goes into the audit tables are determined from the auditLevel property set in the domain or for a composite


The difference between 10g and 11g is that, as far 11g is concerned, the EM is one stop for viewing all instances. So instances are stored in the tables mentioned above in the schema SOAINFRA. The Mediator instances can be viewed in the MEDIATOR_INSTANCE, MEDIATOR_* in the same schema. On the other hand, 10g had separate tables for tracking BPEL and ESB instances. The tables mentioned above are used for storing bpel instance details and can be found under the schema ORABPEL. The ESB instance deatils are stored in the tables mentioned below and can be found under ORAESB schema:

ESB_ACTIVITY, ESB_TRACKING_FIELD_VALUE, ESB_FAULTED_INSTANCE, ESB_TRANSACTION_STATUS

There are some interesting links that provide details on these tables. Some of them are below:

Tables used in BPEL instance tracking
Oracle Cookbook for SOA 10g
Table used in SOA 10g ESB instance tracking

Extract Composite Audit Trail from database table as XML

After I had done some reading on the database tables that were used for storing the instance details, I did find some information from Oracle forums to use the composite instance id to extract the audit xml from the database tables. A function had to created in the database under the same user (preferably) i.e. SOAINFRA. In case of 10g, to view the BPEL audit xml, create the function in ORABPEL. The function will take composite instance as input and return the audit as BLOB, through a query.

Function be created:

CREATE OR REPLACE FUNCTION get_audit_trail_log(cikey IN INTEGER) RETURN blob IS
--
CURSOR c_log(l_cikey INTEGER) IS
SELECT *
FROM audit_trail atr
WHERE cikey = l_cikey
ORDER BY count_id;
--
bl BLOB;
BEGIN
dbms_lob.createtemporary (bl, TRUE);
FOR r_log IN c_log(cikey)
LOOP
dbms_lob.append (bl,r_log.log);
END LOOP;
--
RETURN(bl);
END;


Query to fetch the details of an instance (instance id = 12345678):

SELECT UTL_COMPRESS.LZ_UNCOMPRESS(get_audit_trail_log(ci.cikey))
FROM cube_instance ci
WHERE ci.cikey = 12345678


To read more on this, visit the Oracle Forums where this thread is available.