users@glassfish.java.net

Re: [issue] can not store transaction log into database

From: sankara rao bhogi <Sankara.Rao_at_Sun.COM>
Date: Thu, 10 Jul 2008 14:00:56 +0530

Wang.Qiang wrote:
> sankara,
>
> Thank you very much for your help.
>
> but I still have some issues.
>
> 1.You writed 'It doesn't appear that you are using more than one
> resource in the transaction.'
> it seems something inconsistent with 'This log record is written only
> if the transaction has two or more resources (2PC transaction).'
> did you mean that it doesn't appear that you are using less than one
> resource in the transaction?not more than?

Sorry for the confusion. I meant from your sample in the first mail, I
thought you are using only one resource and that could be one reason why
you may not see the entry in the table. Then I went ahead and said the
entry will be created only if there are two or more resources used in
the transaction. Anyway, you got what I wanted to say.
>
> 2.As you written 'then try putting some load and then you will be able
> to see some entries in the table. '
> I used a transaction had two resources to test whether transaction log
> will be written to txn_log_table or not,
> before application finished,Ichecked the txn_log_table,but
> txn_log_table was still empty.
> how can I really affirm the function of storing Transaction Logging to
> database is correct?
>
> code like this
> @Stateless(name="myejb",mappedName="ejb/myejb")
> public class MyBeanImpl implements MyBean {
>
> public void method(){
> for(int i = 0; i < 100; i++ ){
> insertSomeDataIntoOneDatabase();
> insertSomeDataIntoAnotherDatabase();
> }
> }
> }

I am assuming, EJB is using container managed transactions and its
transaction attribute is one which will make to run method in a
transactional context.

In the above sample, you are iterating over doing some database
operations and all this still done in one transaction and this doesn't
change the amount of time, the log record is lived. If you send some
concurrent requests, then the possibility of seeing the log records is more.

To validate, whether it is written at all or not, you can use the
FailureInducer API. You can use the following code snippet.

import com.sun.jts.utils.RecoveryHooks.FailureInducer;
@Stateless(name="myejb",mappedName="ejb/myejb")
public class MyBeanImpl implements MyBean {

public void method(){
FailureInducer.activateFailureInducer();
// for(int i = 0; i < 100; i++ ){
insertSomeDataIntoOneDatabase();
insertSomeDataIntoAnotherDatabase();
// }
FailureInducer.setWaitPoint(FailureInducer.PREPARED, 20); // Transaction
will wait for 20 secs before it is complete and in this time you could
have a look at the table.
}
}

You need appserv-rt.jar in the class path to compile.

If you see the log record, it is fine.

If not, then could you please check if the files under
#INSTALL_DIR/logs/tx are getting modified when you run your application?
Also send me your logs after setting JTA and JTS log levels to FINE.

regards
sankar

>
> regards
> Wang
>
>
>
> sankara rao bhogi
>> Wang,
>>
>> Step1 is not required. Transaction log record in the txn_log_table is
>> quite short lived, hence it is pretty difficult to realize if there is
>> any data written to it at all. This log record is written only if the
>> transaction has two or more resources (2PC transaction). It doesn't
>> appear that you are using more than one resource in the transaction.
>> If you are using 2PC transaction and want to validate if any data is
>> written to the txn_log_table, then try putting some load and then you
>> will be able to see some entries in the table.
>>
>> regards
>> sankar
>>
>>
>>
>> Wang.Qiang wrote:
>>
>>> Hi,all
>>>
>>> I am writing a application to test Transaction Logging, and I want to
>>> store Transaction Logs in a Database(Derby) by following steps
>>>
>>> 1. Create a JDBC connection Pool and set the
>>> non-transactional-connections attribute to true.
>>>
>>> 2. Create a JDBC resource name of jdbc/myds that uses the connection
>>> pool and note the JNDI name of the JDBC resource.
>>>
>>> 3. Create a table named txn_log_table with the schema:
>>> create table txn_log_table(localtid bigint,servername varchar(40),gtrid
>>> char(70) for bit data)
>>>
>>> 4. Add the db-logging-resource property to the transaction service.
>>> asadmin set
>>> server.transaction-service.property.db-logging-resource="jdbc/myds"
>>>
>>> 5. To disable file synchronization, use the following asadmin
>>> create-jvm-options command:
>>> asadmin create-jvm-options -Dcom.sun.appserv.transaction.nofdsync
>>>
>>> 6. Restart the server
>>>
>>> 7.deloy the application into default server
>>> ** all above steps are configed in the glassfish default server
>>>
>>> my application use toplink to persist a entity to database
>>> EJB code like this
>>>
>>> @Stateless(name="myejb",mappedName="ejb/myejb")
>>> public class MyBeanImpl implements MyBean {
>>> @PersistenceContext(unitName="myunit")
>>> private EntityManager manager;
>>>
>>> public void testInsert(String name, String sex) {
>>> MyEntity entity = new MyEntity();
>>> entity.setName(name);
>>> entity.setSex(sex);
>>> manager.persist(entity);
>>> }
>>> }
>>>
>>> Client to invoke the ejb.
>>> the result is the entity is correct insert into the database,
>>> but,I go to check the txn_log_table in the database,
>>> the 'txn_log_table' table does not have any data.
>>> I think txn_log_table will record this transaction.
>>> I don't know why?
>>> Could you help me?
>>>
>>> Thanks in advance
>>> Wang
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net <mailto:users-unsubscribe_at_glassfish.dev.java.net>
>>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net <mailto:users-help_at_glassfish.dev.java.net>
>>>
>>>
>>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net <mailto:users-unsubscribe_at_glassfish.dev.java.net>
>> For additional commands, e-mail: users-help_at_glassfish.dev.java.net <mailto:users-help_at_glassfish.dev.java.net>
>>
>>
>>
>>
>
>
> --
> 以上
> --------------------------------------------------
> 王 強
> Development Dept.II(Interstage)
> Nanjing Fujitsu Nanda Software Tech. Co., Ltd.(FNST)
> 8/F., Civil Defense Building, No.189 Guangzhou Road,
> Nanjing, 210029, China
> TEL:+86+25-86630566-918
> COINS:79955-918
> FAX:+86+25-83317685
> MAIL:wang.qiang_at_cn.fujitsu.com <mailto:wang.qiang_at_cn.fujitsu.com>
> --------------------------------------------------
>