 |
|
 |
|
Next: Trigger events on Database mirrors
|
| Author |
Message |
External

Since: Jan 12, 2006 Posts: 60
|
(Msg. 1) Posted: Wed Jan 18, 2006 4:13 pm
Post subject: Using MARS with JDBC Driver Archived from groups: microsoft>public>sqlserver>jdbcdriver (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 19, 2006 Posts: 6
|
(Msg. 2) Posted: Thu Jan 19, 2006 9:58 am
Post subject: Re: Using MARS with JDBC Driver [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Snapshot concurrency will help, but it won't solve our problem. Our database
access follows the following rules:
1) All writes are done in the same canonical order to prevent write/write
deadlocks.
2) No reads can occur after the first write to prevent read/write deadlocks
(although we still get them when running against SQL Server. (NOTE: Reads
may occur after acquiring an UPDATE lock, because we know that we have
synchronized with other transactions that could be accessing the same data.)
Our solution to #2 was to retry the SELECT, because we know that the SELECT
will be chosen as the deadlock victim because no writes have occurred in that
transaction. (We also assert that to be the case and we have never found
otherwise.) We get these deadlocks because the canonical order for writes
places foreign key tables after the table with the primary key, while the
optimizer will often choose the foreign key table as the outer table when
doing a foreign key/primary key join. This is where snapshot concurrency
will help us.
There are places in our application where we need to synchronize across app
servers. We do that by acquiring UPDATE locks in the database. The way that
we do that for other databases is to issue a SELECT FOR UPDATE (or the
equivalent syntax) on a unique key, fetch the first row and then leave the
ResultSet open until we are ready to commit the transaction. This gives us
the behavior that we want in other databases, including Oracle. In Oracle,
the SELECT FOR UPDATE will attempt to read the current value, even when
running with snapshot concurrency.
With SQL Server 2000, we have to do an UPDATE instead of a SELECT FOR
UPDATE. Unfortunately, we've found that it is possible for 2 instances of
the same UPDATE to deadlock because of the index locking. We've also seen
cases where 2 instances of the same transaction will deadlock. In those
cases, the transactions were of the form:
1. Acquire UPDATE lock
2. Issue SELECT accessing row that we just locked
....
In the cases that we saw (and sent to Microsoft), one of the transactions
was blocked on the SELECT by another transaction that was blocked on the
UPDATE. It seemed incredible that a transaction that had just updated a row
was blocked trying to read that same row.
Using a second connection to acquire the UPDATE lock will not work here,
because it will be in a different lock space. It seems like using snapshot
concurrency may help here, but we would still need to issue an UPDATE to get
the UPDATE lock, instead of a SELECT FOR UPDATE. In that case, we would
still face the risk of having concurrent updates to the same row deadlock.
As I said before, we've eliminated the deadlocks that we were seeing in our
largest application and in our concurrency stess tests, but we get a large
number of deadlocks in our small internal application that is built on the
same framework and that has only a couple of users.
My understanding of the client side caching that you are describing is that
no locks would be maintained from the SELECT FOR UPDATE because the ResultSet
will not be positioned on a row within the server. >> Stay informed about: Using MARS with JDBC Driver |
|
| Back to top |
|
 |  |
External

Since: Jan 19, 2006 Posts: 6
|
(Msg. 3) Posted: Thu Jan 19, 2006 12:30 pm
Post subject: Re: Using MARS with JDBC Driver [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
> > In the cases that we saw (and sent to Microsoft), one of the transactions
> > was blocked on the SELECT by another transaction that was blocked on the
> > UPDATE. It seemed incredible that a transaction that had just updated a
> > row
> > was blocked trying to read that same row.
>
> I assume this is where the MARS discussion came up, the only likely
> explanation here is that the driver you were using at the time supported
> fake MARS by using a separate connection under the covers for the second
> select. Since the new connection does not run under the same transaction
> context as the first connection you would effectively lock yourself in what
> appears to be the same connection.
>
This is not correct. We were using the jdbc driver that came with SQL
Server 2000. The deadlock was between 2 concurrent instances of the same
transaction, each using only 1 connection, not a self deadlock. The deadlock
was due to the fact that SQL Server still acquires locks on indexes.
> > With SQL Server 2000, we have to do an UPDATE instead of a SELECT FOR
> > UPDATE.
> This should have been similar to executing a resultSet with
> java.sql.ResultSet.TYPE_FORWARD_ONLY, java.sql.ResultSet.CONCUR_UPDATABLE.
> You mentioned something about server side cursor not scaling the way you
> expected, could you elaborate on this? We are actually looking at Oracle
> compatibility options for future releases of the JDBC driver and one of the
> options on the table was to convert FOR UPDATE queries in client side
> statements into server cursor based forward only updatable resultsets under
> the covers.
>
The problem with SelectMethod=cursor was that we were getting some terrible
query plans. I tried adding the primary key to some of the indexes, because
unique indexes were required for cursors when I worked at Sybase. This fixed
some of the problems, but there were a ton of problems. I undid that change
and switched to SelectMethod=direct and the problems with the bad query plans
went away. >> Stay informed about: Using MARS with JDBC Driver |
|
| Back to top |
|
 |  |
External

Since: Jan 19, 2006 Posts: 1
|
(Msg. 4) Posted: Thu Jan 19, 2006 3:13 pm
Post subject: Re: Using MARS with JDBC Driver [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
Perhaps I am missing something, however, have you tried using a SELECT
statement with the (UPDLOCK) hint? That way you don't have to actually change
any data, but you still acquire the update lock. Should be the same as SELECT
FOR UPDATE in oracle, no?
Sam Wilson
"Jerry Brenner" wrote:
> Snapshot concurrency will help, but it won't solve our problem. Our database
> access follows the following rules:
> 1) All writes are done in the same canonical order to prevent write/write
> deadlocks.
> 2) No reads can occur after the first write to prevent read/write deadlocks
> (although we still get them when running against SQL Server. (NOTE: Reads
> may occur after acquiring an UPDATE lock, because we know that we have
> synchronized with other transactions that could be accessing the same data.)
>
> Our solution to #2 was to retry the SELECT, because we know that the SELECT
> will be chosen as the deadlock victim because no writes have occurred in that
> transaction. (We also assert that to be the case and we have never found
> otherwise.) We get these deadlocks because the canonical order for writes
> places foreign key tables after the table with the primary key, while the
> optimizer will often choose the foreign key table as the outer table when
> doing a foreign key/primary key join. This is where snapshot concurrency
> will help us.
>
> There are places in our application where we need to synchronize across app
> servers. We do that by acquiring UPDATE locks in the database. The way that
> we do that for other databases is to issue a SELECT FOR UPDATE (or the
> equivalent syntax) on a unique key, fetch the first row and then leave the
> ResultSet open until we are ready to commit the transaction. This gives us
> the behavior that we want in other databases, including Oracle. In Oracle,
> the SELECT FOR UPDATE will attempt to read the current value, even when
> running with snapshot concurrency.
>
> With SQL Server 2000, we have to do an UPDATE instead of a SELECT FOR
> UPDATE. Unfortunately, we've found that it is possible for 2 instances of
> the same UPDATE to deadlock because of the index locking. We've also seen
> cases where 2 instances of the same transaction will deadlock. In those
> cases, the transactions were of the form:
> 1. Acquire UPDATE lock
> 2. Issue SELECT accessing row that we just locked
> ...
>
> In the cases that we saw (and sent to Microsoft), one of the transactions
> was blocked on the SELECT by another transaction that was blocked on the
> UPDATE. It seemed incredible that a transaction that had just updated a row
> was blocked trying to read that same row.
>
> Using a second connection to acquire the UPDATE lock will not work here,
> because it will be in a different lock space. It seems like using snapshot
> concurrency may help here, but we would still need to issue an UPDATE to get
> the UPDATE lock, instead of a SELECT FOR UPDATE. In that case, we would
> still face the risk of having concurrent updates to the same row deadlock.
> As I said before, we've eliminated the deadlocks that we were seeing in our
> largest application and in our concurrency stess tests, but we get a large
> number of deadlocks in our small internal application that is built on the
> same framework and that has only a couple of users.
>
> My understanding of the client side caching that you are describing is that
> no locks would be maintained from the SELECT FOR UPDATE because the ResultSet
> will not be positioned on a row within the server. >> Stay informed about: Using MARS with JDBC Driver |
|
| Back to top |
|
 |  |
External

Since: Jan 12, 2006 Posts: 60
|
(Msg. 5) Posted: Fri Jan 20, 2006 10:10 am
Post subject: Re: Using MARS with JDBC Driver [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
|
|
| Back to top |
|
 |  |
External

Since: Jan 20, 2006 Posts: 3
|
(Msg. 6) Posted: Fri Jan 20, 2006 5:49 pm
Post subject: Re: Using MARS with JDBC Driver [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
If you do a BEGIN TRAN before the select (which would be necessary for the
lock to hold until you conduct the update) or if you are running with
autocommit turned off then the locks should be held for the duration of your
connection (regardless of cursor status) or until you commit.
"Wes Clark" wrote:
> (Replying for Jerry Brenner) Yes. That’s what we did when running in cursor
> mode. We can’t do that in direct mode because we need to keep the ResultSet
> open. >> Stay informed about: Using MARS with JDBC Driver |
|
| Back to top |
|
 |  |
External

Since: Jan 19, 2006 Posts: 6
|
(Msg. 7) Posted: Mon Jan 23, 2006 1:36 pm
Post subject: Re: Using MARS with JDBC Driver [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
|
|
|
You are correct. My understanding of how the locking should work when
running at READ COMMITTED, based on my time at various database vendors, is
that the UPDATE lock should be downgraded to a SHARE lock and then released
when the cursor advances if no positioned update occurred. However, that's
not how SQL Server or Oracle works. (The UPDATE locks are maintained until
the commit.) So I will be changing our code and it looks like we won't need
MARS after all.
Thanks,
Jerry
"Sam Wilson" wrote:
> If you do a BEGIN TRAN before the select (which would be necessary for the
> lock to hold until you conduct the update) or if you are running with
> autocommit turned off then the locks should be held for the duration of your
> connection (regardless of cursor status) or until you commit.
>
> "Wes Clark" wrote:
>
> > (Replying for Jerry Brenner) Yes. That’s what we did when running in cursor
> > mode. We can’t do that in direct mode because we need to keep the ResultSet
> > open. >> Stay informed about: Using MARS with JDBC Driver |
|
| Back to top |
|
 |  |
| Related Topics: | JDBC Driver for SQL 7.0 ? - Hi; I'm installing an application that requires a JDBC driver for SQL Server. The thing is I am running SQL Server 7.0 and a look at Microsoft seems to show there are lots of these drivers for SQL 2000 but not for 7.0 I know little about these things -...
New JDBC Driver 1/19/06 & SSL ? - Does the today release new JDBC Driver support SSL encryption ?
JDBC 2005 Driver - Hi guys, I'm finding that if I run a query that returns a large amount of data I get java heap crashes. I have already set the jvm heap size but it's made no difference. Below is an exception trace - any comments appreciated! Thanks Shane << Ca...
SQL 2K JDBC driver with WebSphere - Hi, I am trying to use SQL 2K JDBC driver SP3 in WebSphere app server. I created an new JDBC provider, point the class path to where msbase.jar, mssqlserver.jar, and msutil.jar files are. I did not put anything in the "Native Library Path"....
SQL Error with CTP JDBC Driver 1.1 - Starting up our application server encounters an error with the 1.1 CTP JDBC driver against a SQL Server 2005 SP1 server. The identical process succeeds with the 1.0 driver. The error received is: "The conversion from VARCHAR to CHAR is unsuppo... |
|
You can post new topics in this forum You can reply to topics in this forum You can edit your posts in this forum You can delete your posts in this forum You can vote in polls in this forum
|
|
|
|
 |
|
|