Snapshot isolation level usage
Dear All,
There are some transaction tables in which more than one user add and update records (only).
what ever they add and update in transaction tables, based on that entry they add a record in Table A1
, Table A1 has two cols one keeps the table name of transaction table and other col keeps the pk(primarykey) of transaction tables.
So Table A1 always gets only inserts,
Table A1 gets entry only for transaction tables , and only when transaction table gets entry .
At the same time there is a process (ts) which reads Table A1 on time basis, picks up all records
form Table A1 and reads data from transaction tables on the basis of PK stored in it . there it after inserts all the read records into a
new temp table.
and at the end of transaction it deletes records from Table A1.
after some time it again picks up new records from Table A1 and repeats the process.
For process (ts) . i want to use ALLOW_SNAPSHOT_ISOLATION
so that user can keep on entering records.
Q1) The ALLOW_SNAPSHOT_ISOLATION
database option must be set to ON
before one can start a transaction that uses the SNAPSHOT isolation level. I wanted to know should i set the option to OFF after the process(ts) is complete, and switch
it on again on the database when process(ts) starts again.
that is, keeping it on all the time will affect the database in any case?
Q2) ALLOW_SNAPSHOT_ISOLATION ON , will affect other isolation level's transactions or only to snapshot isolation levels transactions. that is, i have old
stored proc and front end applications like web or window on .net which are using default isolation levels.
Q3) is my choice of isolation level for process(ts) is correct or there can be any other solution.
Note: "the information is quite less but i wont be able to give full information."
yours sincerely
>Q1) should i set the option to OFF after the process(ts) is complete
No keep it on.
>Q2) ALLOW_SNAPSHOT_ISOLATION ON , will affect other isolation level's transactions
No it will not affect any other transaction isolation level.
>Q3) is my choice of isolation level for process(ts) is correct or there can be any other solution.
Seems fine, although there are probably many other solutions.
David
David http://blogs.msdn.com/b/dbrowne/
Similar Messages
-
Hi,
In mssql i am using following things.
I have two database D1 and D2, i am using snapshot isolation (ALTER DATABASE MyDatabase
SET ALLOW_SNAPSHOT_ISOLATION ON) in both database.
Following is the situation.
1) There is one SP sp1 ( it can be in any database d1 or d2), it updates d2 from d1.
2) d2 is used for reading by web, execept above SP sp1
3) d1 gets updation from web in readcommite isolation.
4) both database will be on same instence of mssql.
Q1) wanted to know how to implement the same thing in oracle 11x express edition.
Q2) is there any diffrence between snapshot isolation level of mssql and oracel.
any link would be help full.
yours sincerely>Q1) should i set the option to OFF after the process(ts) is complete
No keep it on.
>Q2) ALLOW_SNAPSHOT_ISOLATION ON , will affect other isolation level's transactions
No it will not affect any other transaction isolation level.
>Q3) is my choice of isolation level for process(ts) is correct or there can be any other solution.
Seems fine, although there are probably many other solutions.
David
David http://blogs.msdn.com/b/dbrowne/ -
hi,
I have enable snapshot isolation level, in my database all queries execute in read commited isolation only one big transaction uses snapshot isolation.
q1)i wanted to know if snapshot silation transaction is not running but database is enable for snapshot ,then will the normal
queries using read commited will create versions or not.
yours sincerley.Enabling snapshot isolation level on DB level does not change behavior of queries in any other isolation levels. In that option you are eliminating all blocking even between writers (assuming they do not update
the same rows) although it could lead to 3960 errors (data has been modified by other sessions).
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Turning On Snapshot Isolation Gotchas
Hello Experts,
We have been experiencing high number of Deadlocks while using MERGE statement and turning on Snapshot Isolation perfectly solves our problem and our throughput and concurrency didn't get affected at all.
We did load testing and monitored TempDB VersionStore size and it was nothing significant and we have 64 Gig Memory allocated in Prod Server. Our team did the reading and research primarily from these online sources.
My Question is "Is there any gotchas in turing on SnapShot Isolation you won't see right away?". I want learn from experiences before we venture into turning it on in our production Environment?. I saw some folks experienced 60 Gig Version Store
because there was 3 month old active transaction.
What kind of preventive and maintenance scripts would be useful to monitor the system and take corrective action?.
I have few scripts to monitor tempdb version store size, and peformon Transaction Counters. Is there any other better scripts/tools available?.
Kimberly Tripp Video on Isolation Levels :
http://download.microsoft.com/download/6/7/9/679B8E59-A014-4D88-9449-701493F2F9FD/HDI-ITPro-TechNet-mp4video-MCM_11_SnapshotIsolationLecture(4).m4v
Kendra Little on SnapShot Isolatioin :
http://www.brentozar.com/archive/2013/01/implementing-snapshot-or-read-committed-snapshot-isolation-in-sql-server-a-guide/
Microsoft Link: https://msdn.microsoft.com/en-us/library/ms188277(v=sql.105).aspx
https://msdn.microsoft.com/en-us/library/bb522682.aspx
SQL Team Link : http://www.sqlteam.com/article/transaction-isolation-and-the-new-snapshot-isolation-level
Idera Short article on TempDB : http://sqlmag.com/site-files/sqlmag.com/files/uploads/2014/01/IderaWP_Demystifyingtempdb.pdf
Jim Gray Example by Craig Freedman : http://blogs.msdn.com/b/craigfr/archive/2007/05/16/serializable-vs-snapshot-isolation-level.aspx
Thanks in advance.
~I90Runner
I90RunnerIt is unclear what isolation level have you enabled RCSI or SI?
Downsides:
Excessive tempdb usage due to version store activity. Think about session that deletes 1M rows. All those rows must be copied to version store regardless of session transaction isolation level and/or if there are other sessions
that running in optimistic isolation levels at the moment when deletion started.
Extra fragmentation – SQL Server adds 14-byte version tag (version store pointer) to the rows in the data files when they are modified. This tag stayed until index is rebuild
Development challenges – again, error 3960 with snapshot isolation level. Another example in both isolation levels – trigger or code based referential integrity. You can always solve it by adding with (READCOMMITTED) hint
if needed.
While switching to RCSI could be good emergency technique to remove blocking between readers and writers (if you can live with overhead AND readers are using read committed), I would suggest to find root cause of the blocking.
Confirm that you have locking issues – check if there are shared lock waits in wait stats, that there is no lock escalations that block readers, check that queries are optimized, etc.
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Transaction Isolation Level to Read UnCommited in Non OLTP Database
HI,
We are having a database which for NOT OLTP process. That is OLAP DB. Operation on that DB is only Select and (Incremental Insert - FOR DWH ) not Update/Delete and we are performing ROLAP operations in that DB.
By Default SQL Server DB isolation Level is READ COMMITTED.AS Our DB IS OLAP SQL Server DB we need to change the isolation level toRead Uncommited. We google it down but We can achive in
Transaction level only by SET isoaltion Level TO Read UNCOMMITED
or ALLOW_SNAPSHOT_ISOLATION ON or READ_COMMITTED_SNAPSHOT
Is there any other way if we can Change the Database isolation level to READ uncommitedfor Entire Database?, insteads of achiving in Transaction Level or With out enabling SET ALLOW_SNAPSHOT_ISOLATION ON or READ_COMMITTED_SNAPSHOT
Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.
Please use Marked as Answer if my post solved your problem and use Vote As Helpful if a post was useful.Hi,
My first question would be why do you want to change Isolation level to read uncommitted, are you aware about the repercussions you will get dirty data, a wrong data.
Isolation level is basically associated with the connection so is define in connection.
>> Transaction level only by SET isoaltion Level TO Read UNCOMMITED or ALLOW_SNAPSHOT_ISOLATION ON or READ_COMMITTED_SNAPSHOT
Be cautious Read UNCOMMITED and Snapshot isolation level are not same.The former is pessimistic Isolation level and later is Optimistic.Snapshot isolation levels are totally different from read uncommitted as snapshot Isolation level
uses row versioning.I guess you wont require snapshot isolation level in O:AP DB.
Please read below blog about setting Isolation level Server wide
http://blogs.msdn.com/b/ialonso/archive/2012/11/26/how-to-set-the-default-transaction-isolation-level-server-wide.aspx
Please mark this reply as the answer or vote as helpful, as appropriate, to make it useful for other readers
My TechNet Wiki Articles -
hi,
--DBCC FREEPROCCACHE
--DBCC DROPCLEANBUFFERS
CREATE TABLE #temp(ID BIGINT NOT NULL)
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRAN
INSERT INTO #temp (id) SELECT wid FROM w WHERE ss=1
UPDATE w SET ss =0 WHERE wid IN (SELECT id FROM #Temp)
COMMIT TRAN
IF (EXISTS(SELECT * FROM #temp))
BEGIN
SELECT 'P'
SET TRANSACTION ISOLATION LEVEL SNAPSHOT
BEGIN TRAN
insert into a ( a,b,c)
SELECT a , b ,c FROM w WHERE wid= 104300001201746884
COMMIT TRAN
END
Q1) changin isolation in this way is correct or not?
Q2) why i have chainged isolation is , because
this stmt was updated by other trnsaction also, and i also wanted to udpate it , so i made one repetable read and then snapshot.
UPDATE w SET ss=0 WHERE wid IN (SELECT id FROM #Temp)
DROP TABLE #temp
yours sincerleyhttp://blogs.msdn.com/b/craigfr/archive/2007/05/16/serializable-vs-snapshot-isolation-level.aspx
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Snapshot isolation in combination with service broker
Hi all,
I'm currently using the service broker in combination with snapshot isolation on the database.
The notification request is executed under read commited isolation. The code looks like this:
SqlDependency dependency = new SqlDependency(command, null, 0);
dependency.OnChange += eventHandler;
using (SqlConnection conn = new SqlConnection(connectionString))
using (SqlTransaction tran = conn.BeginTransaction(IsolationLevel.ReadCommitted))
command.Transaction = tran;
command.ExecuteNonQuery();
tran.Commit();
The request is successfully created and works fine at the first glance.
Now here is my problem:
I created a notification request that should monitor two objects. The query (executed under read committed) looks something like this:
SELECT Id, DataVersion FROM dbo.MyObjects WHERE Id = 1 OR Id = 2
Afterwards I delete both objects in separate nested transactions. Both of them are running under snapshot isolation. It looks something like this:
using (SqlConnection conn1 = new SqlConnection(connectionString))
conn1.Open();
using (SqlTransaction tran1 = connection1.BeginTransaction(IsolationLevel.Snapshot))
using (SqlConnection conn2 = new SqlConnection(connectionString))
conn2.Open();
using (SqlTransaction tran2 = conn2.BeginTransaction(IsolationLevel.Snapshot))
SqlCommand command2 = conn2.CreateCommand();
command2.Transaction = tran2;
command2.CommandText = "DELETE FROM MyObjects WHERE Id = 2";
command2.ExecuteNonQuery();
tran2.Commit();
SqlCommand command1 = conn1.CreateCommand();
command1.CommandText = "DELETE FROM MyObjects WHERE Id = 1";
command1.Transaction = tran1;
command1.ExecuteNonQuery();
tran1.Commit(); //-> Conflict exception
A conflict exception is raised during the commit of last transaction. The conflict seems to occur in the table "sys.query_notifcations_xxxxxxxxx". This is the exact message:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll
Additional information: Snapshot isolation transaction aborted due to update conflict. You cannot use snapshot isolation to access table 'sys.query_notification_45295271' directly or indirectly in database 'MyDatabase' to update, delete,
or insert the row that has been modified or deleted by another transaction. Retry the transaction or change the isolation level for the update/delete statement.
Is there any restriction for the service broker that prohibits the usage of snapshot isolation.
Thanks in advance.No, the error has nothing to do with Service Broker. Or for that matter, query notifications, which is the feature you are actually using. (Query notifications uses Service Broker, but Service Broker != Query notification.)
You would get the same error if you had a trigger in MyObjects that tried to update the same row for both deletions. A snapshot transaction gives you a consistent view of the database in a certain point in time. Consider this situation:
Snapshot transaction A that started at time T update a row R at time T2. Snapshot transaction B starts at time T1 updates the same row at time T3. Had they been regular non-snapshot transaction, transaction B would have been blocked already when it tried
to read R, but snapshot transactions do not get blocked. But if B would be permitted to update R, the update from transaction A would be lost. Assume that the update is an incremental one, for instance updating cash balance for an account. You can see that
this is not permittable.
In your case, the row R happens to be a row in an internal table for query notifications, but it is the application design which is the problem. There is no obvious reason to use snapshot isolation in your example since you are only deleting. And there is
even less reason to have two transactions and connections for the task.
Erland Sommarskog, SQL Server MVP, [email protected] -
Hello,
I'm new to the Oracle environment and have just started using PL/SQL on Oracle 8i. Where can I find info on how Oracle locks data and how transaction isolation levels are used? We've still not recvd our manuals so please any replies referring to manuals are not welcome!You could move forward balance into its own table. That was, the SELECT will not lock on the original table. Most of the running balance schemes that I have seen take a snapshot as of a given date (say, statement printing date) and record both the timestamp and the amount. Next month, you simply get last month's vaule and timestamp and query on transactions after that timestamp.
- Saish -
Snapshot isolation transaction aborted due to update conflict
Hi Forum,
Can anyone help me to give the solution for this below problem.
We are developing MVC3 application with SQL Server 2008, we are facing as
Snapshot isolation transaction aborted due to update conflict
Snapshot isolation transaction aborted due to update conflict. You cannot use snapshot isolation to access table 'dbo.Tb_M_Print' directly or indirectly in database 'DB_Production' to update, delete, or insert the row that has been modified or deleted
by another transaction. Retry the transaction or change the isolation level for the update/delete statement .
Please tell me the solution how to proceed for the above problem
Ramachange the isolation level for the update/delete statement .
The error message already mentions the solution.
See also MSDN
Lesson 1: Understanding the Available Transaction Isolation Levels => Update Conflicts
Olaf Helper
[ Blog] [ Xing] [ MVP] -
Locking issues with transaction-isolation levels
I believe that my program is suffering from some sort of deadlock, and I was hoping
for some feedback.
I am helping to develop a trading system
using EJBs, Oracle 9i, and Bea Weblogic 7.0. The system provides an entity EJB
called LiveOrder that exposes several finder methods, most of which return java.util.Collections
of LiveOrder EJBs.
In weblogic-ejb-jar.xml, I have set the transaction isolation-levels for these
finders to TRANSACTION_READ_COMMITTED_FOR_UPDATE (b/c TRANSACTION_SERIALIZABLE
isn't really supported by Oracle), in an effort to eliminate phantom reads, which
occur frequently if I do not use this isolation level. These finders all use transaction
attribute 'Required'.
It is my understanding that any transaction that calls any of these finders either
will lock the database if no other transaction already owns the lock, or will
wait until the lock is released if another transaction owns that lock. It also
is my understanding that a transaction that owns a lock will always release any
locks acquired upon expiration of that transaction (whether that be via commit
or via rollback).
However, this doesn't always appear the case: I have noticed occassionally that
several clients "hang," as they wait for the lock that, for some reason, is not
being released by its transaction. There do not appear to be any exceptions thrown
by the system prior to the system hanging, and the Weblogic administration tool
states that all transactions have been committed.
If it helps, I have included the general algorithm for the main (i.e., most expensive)
transaction:
1. a client calls a stateless session EJB's processOrder method (which should
implicitly start a new transaction, b/c this method has attibute 'RequiresNew')
2. the transaction invokes the LiveOrder finder method (this should lock the DB,
so subsequent callers should block until the lock is released).
3. the transaction invokes another LiveOrder finder method, returning a separate
set of data.
4. the transaction invokes a finder method from a separate entity EJB (called
Security), which maps to a "read-only" table in the DB (default transaction-isolation
level, Required attribute).
5. the transaction invokes a finder method from yet another separate entity EJB
(called SecurityMarketValues), which maps to some other table (not read-only)
in the DB (again, default transaction-isolation level, Required attribute).
6. the transaction writes to the SecurityMarketValues entity EJB.
7. the transaction writes to the LiveOrders retrieved from steps 2 and 3.
8. the transaction ends by exiting method processOrder (thus releasing the locks
on the LiveOrder table in the DB).
In the system, there also exist other transactions that occassionally call the
LiveOrder EJB finder methods, but only briefly to take a "snapshot" of the live
order table (i.e., these transactions do not make calls to other DB tables, and
close transactions almost immediately after starting them)
Like I mentioned before, the system sometimes works, and sometimes it hangs. Any
ideas? I'm running out...
Jon,
If there was an Oracle deadlock the DB would resolve it momentarily and
will ultimately choose one transaction and throw an exception so it's
not a DB deadlock.
Take a thread dump at the very moment your system seems to be hanging
and look at what the threads are doing.
From your description it's not very unlikely that those threads of
yours that take snapshots of the data will not disrupt the transactions
so you may be surprised by the thread dumps that this is actually what
happens -- those snapshot thread wait for some lock while holding locks
needed by you other threads and it just slows down the system.
Regards,
Dejan
Jon Gadzik wrote:
>I believe that my program is suffering from some sort of deadlock, and I was hoping
>for some feedback.
>
>I am helping to develop a trading system
>using EJBs, Oracle 9i, and Bea Weblogic 7.0. The system provides an entity EJB
>called LiveOrder that exposes several finder methods, most of which return java.util.Collections
>of LiveOrder EJBs.
>
>In weblogic-ejb-jar.xml, I have set the transaction isolation-levels for these
>finders to TRANSACTION_READ_COMMITTED_FOR_UPDATE (b/c TRANSACTION_SERIALIZABLE
>isn't really supported by Oracle), in an effort to eliminate phantom reads, which
>occur frequently if I do not use this isolation level. These finders all use transaction
>attribute 'Required'.
>
>It is my understanding that any transaction that calls any of these finders either
>will lock the database if no other transaction already owns the lock, or will
>wait until the lock is released if another transaction owns that lock. It also
>is my understanding that a transaction that owns a lock will always release any
>locks acquired upon expiration of that transaction (whether that be via commit
>or via rollback).
>
>However, this doesn't always appear the case: I have noticed occassionally that
>several clients "hang," as they wait for the lock that, for some reason, is not
>being released by its transaction. There do not appear to be any exceptions thrown
>by the system prior to the system hanging, and the Weblogic administration tool
>states that all transactions have been committed.
>
>If it helps, I have included the general algorithm for the main (i.e., most expensive)
>transaction:
>
>1. a client calls a stateless session EJB's processOrder method (which should
>implicitly start a new transaction, b/c this method has attibute 'RequiresNew')
>
>2. the transaction invokes the LiveOrder finder method (this should lock the DB,
>so subsequent callers should block until the lock is released).
>
>3. the transaction invokes another LiveOrder finder method, returning a separate
>set of data.
>
>4. the transaction invokes a finder method from a separate entity EJB (called
>Security), which maps to a "read-only" table in the DB (default transaction-isolation
>level, Required attribute).
>
>5. the transaction invokes a finder method from yet another separate entity EJB
>(called SecurityMarketValues), which maps to some other table (not read-only)
>in the DB (again, default transaction-isolation level, Required attribute).
>
>6. the transaction writes to the SecurityMarketValues entity EJB.
>
>7. the transaction writes to the LiveOrders retrieved from steps 2 and 3.
>
>8. the transaction ends by exiting method processOrder (thus releasing the locks
>on the LiveOrder table in the DB).
>
>
>In the system, there also exist other transactions that occassionally call the
>LiveOrder EJB finder methods, but only briefly to take a "snapshot" of the live
>order table (i.e., these transactions do not make calls to other DB tables, and
>close transactions almost immediately after starting them)
>
>Like I mentioned before, the system sometimes works, and sometimes it hangs. Any
>ideas? I'm running out...
>
>
>
>
-
SELECT hangs despite Snapshot Isolation
- I'm trying to learn isolation levels.
SET TRANSACTION ISOLATION LEVEL Read Snapshot
I thought this would allow me to issue a SELECT on a dirty row (I thought it would show me the clean version of the row). But my test failed - the SELECT hangs/pends. Why?
- First I dirtied a row:
if object_id('tblTestTrans') is not null drop table tblTestTrans
create table tbltestTrans (
id int
insert into tbltestTrans (id) values (1)
Begin Tran
Update tbltestTrans set id = 2
Then I ran a SELECT in a new query window:
ALTER DATABASE TestDb Set Allow_SnapShot_Isolation ON
SET TRANSACTION ISOLATION LEVEL Snapshot
select * from tblTestTrans -- hangs
The select hangs. Why?
Your test seems a little incomplete. You should set the connection which is starting transaction to snapshot before running an update. Then you can open another connection and set it to snapshot to see only the clean version of the table (with
only one record). -
Setting transaction isolation level on a replicated server stored procedure
I have a SQL server that has replication turned onto to another server which is our reporting server. Replication is real-time (or close to it). On the report server I have a stored procedure that runs from a SRS report. My question is it possible or advisable
or does it even make sense to set the "SET TRANSACTION ISOLATION LEVEL READ COMMITTED" on at the beginning of the stored procedure which selects data from the reporting server database? Is it possible for uncommitted data on the OLTP side of the
house to be replicated before it is committed? We are having data issues with a report and have exhausted all options and was wondering if dirty data maybe the issue since the same parameters work for a report 1 sec and then next it doesnt.Only committed transactions are replicated to the subscriber. But it is possible for the report to see dirty data if running in READ UNCOMMITTED or NOLOCK. You should run your reports in READ COMMITTED or SNAPSHOT isolation , and your replication
subscriber should be configured with READ COMMITTED SNAPSHOT ISLOATION eg
alter database MySubscriber set allow_snapshot_isolation on;
alter database MySubscriber set read_committed_snapshot on;
as recommended here
Enhance General Replication Performance.
David
David http://blogs.msdn.com/b/dbrowne/ -
Setting db isolation level on transaction without EJB
I'm using UserTransaction in the servlet container, to control XA transactions.
We're not using EJB. How do I set the database isolation level? I'm tempted
to use java.sql.Connection.setTransactionIsolation(). However, the Sun Javadoc
for that method says you can't call that after the transaction has started (which
makes sense). Right now, we're starting the transaction, getting a connection,
closing the connection, and committing the transaction. I guess that order won't
work if I want to set the isolation level. Or am I mixing apples and oranges
here? If I use UserTransaction, is it even appropriate to try to set the isolation
level on the connection?
All I really want to do is change the default isolation level. We do not need
different isolation levels for different use cases. (Not yet, anyway.) We might
have transactions against two different database instances or other resource managers.
That's why I want to use UserTransaction and XA transactions.
Thanks!
Steve Molitor
[email protected]
Only committed transactions are replicated to the subscriber. But it is possible for the report to see dirty data if running in READ UNCOMMITTED or NOLOCK. You should run your reports in READ COMMITTED or SNAPSHOT isolation , and your replication
subscriber should be configured with READ COMMITTED SNAPSHOT ISLOATION eg
alter database MySubscriber set allow_snapshot_isolation on;
alter database MySubscriber set read_committed_snapshot on;
as recommended here
Enhance General Replication Performance.
David
David http://blogs.msdn.com/b/dbrowne/ -
We have setup snapshot level isolation in our Berkeley DB XML database, and started getting the following errors during queries after a while:
PANIC: Cannot allocate memory
We set the max lockers at 10,000, max locks at 1,000,000 and max lock objects at 1,000,000 as well. We are also very careful to commit or abort every transaction initiated. All of our operations are done under the context of an explicit transaction. Could there be some memory leak? Should we be aware of some other caveats?
Thank you,
Alexander.Hi Alexander,
I would suggest running the application under a memory leak checker/debugger, such as Purify or Valgrind. If you do get something suspicious please report it.
Though, when running with snapshot isolation you have to be prepared for the cost that MVCC (MultiVersion Concurrency Control) implies, that is, larger cache size requirements.
Pages are being duplicated when a writer takes a read lock on a page, therefore operating on a copy of that page. This avoids the situation where other writers would block due to a read lock held on the page, but it also means that the cache will fill up faster. You might need a larger cache in order to hold the entire working set in memory.
Note that the need of more cache is amplified when you have a large number of concurrent active long-running transactions, as it increases the volume of active page versions (copies of pages that cannot safely be freed). In such situation, it may worth trying to run updates at serializable isolation and only run queries at snapshot isolation. The queries will not block updates, or vice versa, and the updates will not force page versions to be kept for long periods.
You should try keeping the transactions running under snapshot isolation as short as possible.
Of course, the recommended approach to resolve this issue is to increase the cache size, if possible. You can estimate how large your cache should be by taking a checkpoint, followed by a call to the DB_ENV->log_archive() method. The amount of cache required is approximately double the size of the remaining log files (that is, the log files that cannot be archived).
Also, along with increasing the cache size you may need to increase the number of maximum active transactions that the application supports.
Please review the following places for further information:
[http://www.oracle.com/technology/documentation/berkeley-db/db/programmer_reference/transapp_read.html#id1609299]
[http://www.oracle.com/technology/documentation/berkeley-db/db/gsg_txn/Java/isolation.html#snapshot_isolation]
Regards,
Andrei -
Can you set isolation levels of message-driven bean transactions?
The problem: I have 3 different message-driven beans which each get a different type of message, except for a field that is common to all. That field is used as the primary key of an entity object. The message-driven beans configured to use a container managed transaction. Each message-driven bean, in processing the message, first does a lookup by primary key to see if the object associated with the key exists, and if it does not, it requests the entity's home object to create it. After that, they do further processing. The problem is that sometimes all the beans simultaneously get a message, resulting in each bean checking for the entity object at about the same time, and if they fail to find it (because none of them has created it yet), each creates an object, all with the same primary key. This is not caught until the beans start to complete their onMessage method, which I believe results in the container committing the transaction. One of the transactions will be committed successfully, while the other two will fail, get rolled back, and then be retried with the same message. The second time through, the other beans will find the entity object (since it has been created and committed) and they will complete correctly. In the end, they right thing occurs, except that there is a troubling exception or 2 in the log telling about the constraint violation (with the primary key) and the rollback. If it was just me, that would be fine, but our customer does not like to see exceptions in the log; that indicates to him that something is wrong.
So, I am looking for someway to make sure that the actions of the message-driven beans are serialized. One suggestion from a colleague was to set the isolation level of the transactions being used by the container in processing the message-driven beans' onMessage method. However, the documentation does not mention any way to do this for a message-driven bean. Suggestions?
Is the use of a UserTransaction a better way to do this? If I acquire a UserTransaction within the onMessage method of a message-driven bean, can I set its isolation level? How would this work? When I get a UserTransaction, does each client get a different transaction, or do they all get the same one?(1) The WebLogic JMS "unit-of-order" feature is a heavily adopted feature that was specifically designed to handle similar use cases - see the JMS developer guide for extensive documentation. In your use case, if "key" is used to define UOO, then there's no limit on the number of keys that can be processed concurrently, but messages for any particular key will be processed single-threaded in the order in which they were first submitted.
Note that if you're using distributed destinations, the UOO feature is still fully supported - but the developer and/or administrator needs to decide whether to configure the destination to use "hash" or "path service" based routing (the JMS UOO edoc outlines the trade-offs).
(2) Another alternative is to use a single MDB with max-beans-free-pool that processes all three types (as the other poster suggested). I think this assumes all MDBs run on the same JVM.
(3) Another alternative is to use multiple queues, with a single MDB on each Q. Where some sort of hash algorithm is used to determine which Q is for the key. This approach is a "hand-coded" variant of the approach in (1) with "hash" based routing enabled...
(4) If all MDBs actually do run in the same JVM, a third alternative is to use code the application to use a common lock to protect each key, eg, something like:
// assume MyLock is simply a class with a "reference counter"
// assume some global "staticHM" hash map that is all MDBs can access
onMessage() {
MyLock lock = null;
key= msg.getKey();
synchronized(staticHM) {
lock = staticHM.get();
if (lock = null) {
lock = new lock();
staticHM.put(key, new lock());
lock.incRefCount();
try {
synchronized(lock) {
// only one onMessage will be able to lock a particular key at a time
do your work;
} finally {
synchronized(staticHT) {
if (lock.defRefCount() == 0) staticHM.remove(lock);
if (lock = null) staticHM.put(key);
If multiple threads get a message with the same key, then only one thread at a time will work on the key.
Hope this helps,
Tom
Maybe you are looking for
-
IPhoto won't open, error message appears, suggests reinstall but don't have disks!
The following message has just appeared: Dyld Error Message: Library not loaded: /Library/Frameworks/iLifeFaceRecognition.framework/Versions/A/iLifeFaceRecognit ion Referenced from: /Applications/iPhoto.app/Contents/MacOS/iPhoto Reason: image n
-
IPOD nano length of song and volume...
When I'm listening to a song it doesn't show the length of the time and how high the volume is. It used to show me, now it just has like 5 dots. Can someone please tell me what I should do to be able to see the length of the song again. Thanks
-
Itunes continues to say ipod appears to be corrupted.
One day i just connected my my ipod to my computer and itunes says that your ipod appears to be corrupted. So I clicked restore and the ipod restored and then appeared on itunes with the same message. Telling me to restore. I literally did this like
-
Would like Photoshop to open photos instead of Preview
How can I set it up so when I double click on a photo file, it will automatically open in Photoshop, instead of the Preview? Thanks.
-
Invalid/unknown SSL header was received from peer uma during SSL handshake
Hello, I get the following error when switching from https:// to http:// and clicking on the browser back button and performing the same action again in the https:// e.g In my https://uma:7040/test.jsp I perform an action and go to http://uma:7004/in