views:

283

answers:

4

From this post. One obvious problem is scalability/performance. What are the other problems that transactions use will provoke?

Could you say there are two sets of problems, one for long running transactions and one for short running ones? If yes, how would you define them?

EDIT: Deadlock is another problem, but data inconsistency might be worse, depending on the application domain. Assuming a transaction-worthy domain (banking, to use the canonical example), deadlock possibility is more like a cost to pay for ensuring data consistency, rather than a problem with transactions use, or you would disagree? If so, what other solutions would you use to ensure data consistency which are deadlock free?

+1  A: 

One issue with transactions is that it's possible (unlikely, but possible) to get deadlocks in the DB. You do have to understand how your database works, locks, transacts, etc in order to debug these interesting/frustrating problems.

Adam Davis
A: 

I think the major issue is at the design level. At what level or levels within my application do I utilise transactions.

For example I could:

  • Create transactions within stored procedures,
  • Use the data access API (ADO.NET) to control transactions
  • Use some form of implicit rollback higher in the application
  • A distributed transaction in (via DTC / COM+).

Using more then one of these levels in the same application often seems to create performance and/or data integrity issues.

Ash
+2  A: 

You can get deadlocks even without using explicit transactions. For one thing, most relational databases will apply an implicit transaction to each statement you execute.

Deadlocks are fundamentally caused by acquiring multiple locks, and any activity that involves acquiring more than one lock can deadlock with any other activity that involves acquiring at least two of the same locks as the first activity. In a database transaction, some of the acquired locks may be held longer than they would otherwise be held -- to the end of the transaction, in fact. The longer locks are held, the greater the chance for a deadlock. This is why a longer-running transaction has a greater chance of deadlock than a shorter one.

Curt Hagenlocher
One of the stuffs most people dont understand is that writers always have an exclusive lock whether they are part of an explicit transaction or not..
Gulzar
+2  A: 

It depends a lot on the transactional implementation inside your database and may also depend on the transaction isolation level you use. I'm assuming "repeatable read" or higher here. Holding transactions open for a long time (even ones which haven't modified anything) forces the database to hold on to deleted or updated rows of frequently-changing tables (just in case you decide to read them) which could otherwise be thrown away.

Also, rolling back transactions can be really expensive. I know that in MySQL's InnoDB engine, rolling back a big transaction can take FAR longer than committing it (we've seen a rollback take 30 minutes).

Another problem is to do with database connection state. In a distributed, fault-tolerant application, you can't ever really know what state a database connection is in. Stateful database connections can't be maintained easily as they could fail at any moment (the application needs to remember what it was in the middle of doing it and redo it). Stateless ones can just be reconnected and have the (atomic) command re-issued without (in most cases) breaking state.

MarkR