-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: How to handle DB-based optimistic concurrency control?
PostPosted: Wed Nov 26, 2003 8:26 pm 
Newbie

Joined: Tue Nov 25, 2003 5:05 pm
Posts: 18
Hello folks,

has anyone used hibernate with a database that uses optimistic concurrency control (OCC) to guarantee transaction isolation (especially with JTA)?

ciao
Sven

For those of you who might not remember db based occ a short refresher:
A database has to take care that transaction A can not read dirty data from transaction B. The majority of current commercial databases use locking that means if A modifies data1 and B accesses data1 B has to wait until A is ready (very simplified). In a database with OCC every transaction has a read and write set and every transaction can read and write every data it wants. Everytime a datum is read(written) it is inserted into the readset(writeset). As there is no locking transaction B might have some dirty data of transaction A. So there must be some mechanism that ensures that only one transaction is committed to the database. This mechanism happens on commit where the read/writeset of each transaction is compared with each other. If there are no overlapping items the transaction can commit. If there are overlapping items one transaction is rolled back.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 10:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Sounds like you are talking about what is usually called the "mulit-version concurrency model". Both Oracle and Postgres work this way. Hibernate was architected especially so that you may take advantage of the high scalability of multi-version concurrency model. So Hibernate never does locking in the middle tier.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 26, 2003 10:54 pm 
Newbie

Joined: Tue Nov 25, 2003 5:05 pm
Posts: 18
gavin wrote:
Sounds like you are talking about what is usually called the "mulit-version concurrency model". Both Oracle and Postgres work this way. Hibernate was architected especially so that you may take advantage of the high scalability of multi-version concurrency model. So Hibernate never does locking in the middle tier.


Multi-version concurrency has nothing to do with occ. In MVC you create copies of the modified data. With occ you have only _one_ version that can be read/written by multiple transactions. An occ database will never deadlock.

Databases that do occ are e.g.
MimerSQL www.mimer.com
Frontbase www.frontbase.com

I'm asking this question because not every library works with occ. Normally you would write
Code:
  // For "normal" locking
  insertData();
  updateDate();
  commit();

  // With optimistic concurrency control you must write
  final int MAXTRIES=3;
  int i = 0;
  while (i<MAXTRIES)  {
    insertData();
    updateDate();
   
    try {
      commit();
      break;
    }
    catch (SQLException e) {
       // check if we got a "locking" problem and try again until maxtries
       if (e.sqlcode="ROLLEDBACK") i++;
       else throw e;
    }
    if (i == MAXTRIES)
      throw new SQLException ("Have tried too much for this transaction!");
  }


The code should indicate that code written for "normal" locking will not work without modifications with occ (of course the code is not wrong - it's rather suboptimal).

For a high level description of occ see
http://developer.mimer.com/features/feature_15.htm

There are also some (very old) papers about occ in the VLDB journal.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.