db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Matrigali <mikem_...@sbcglobal.net>
Subject Re: [PATCH] fix for derby-94 update locks are not being release on lock escalation.
Date Fri, 24 Dec 2004 03:05:34 GMT
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

thanks suresh, I will be commiting this change, just got finished
running all the tests on the code change.

The "storetests" directory is a nice place to add short bug fix tests,
In retrospect I wish I had just named it bugfix or something like that.
If anyone wants to go ahead and create a bug or jira suite that might be
more intuitive.

Unlike most of the tests all tests in this directory are run in the same
~ database, so the overhead of adding a single file which tests a single
change is very small.  I encourage anyone submitting a change that
affects the storage system to create a new .sql or .java test in this
directory.  Remember to name the tables you use something unique, and
clean up at the end of the test.

/mikem

Suresh Thalamati wrote:
| My earlier patch for this problem did not include the test case;
| Resubmitting the patch with a test case added to the store  regression
| suite.
|
| -suresht
|
| Suresh Thalamati wrote:
|
|
|>Problem:
|>Container group level locks were not getting released when lock is
|>escalated to table level exclusive lock. Locks were not getting released
|>even on commit/close of cursor   because once escalation process
|>acquires table level X lock successfully, container group lock policy is
|>set as NO-LOCKING state.
|>
|>Fix:
|>Attached Fix releases the container group level locks before setting
|>lock policy to  NO LOCKING mode when a table level X lock is acquired
|>because of escalation.
|>
|>-suresh
|>
|>
|>
|>
|>
|>
|
|
|
| ------------------------------------------------------------------------
|
| Index: java/engine/org/apache/derby/impl/store/raw/xact/RowLocking2.java
| ===================================================================
| --- java/engine/org/apache/derby/impl/store/raw/xact/RowLocking2.java
(revision 123029)
| +++ java/engine/org/apache/derby/impl/store/raw/xact/RowLocking2.java
(working copy)
| @@ -115,13 +115,17 @@
|              //
|
|
| -			if (lf.isLockHeld(t.getCompatibilitySpace(), t, container.getId(),
ContainerLock.CX) ||
| -				((!forUpdate) &&
| -                 lf.isLockHeld(t.getCompatibilitySpace(), t,
container.getId(), ContainerLock.CS)))
| +			if (lf.isLockHeld(t.getCompatibilitySpace(), t, container.getId(),
| +							  ContainerLock.CX))
| +			{
| +				//release any container group locks becuase CX container lock
will cover everthing.
| +				lf.unlockGroup(t.getCompatibilitySpace(), container.getUniqueId());
| +				container.setLockingPolicy(NO_LOCK);
| +			}else if ((!forUpdate) &&
| +					 lf.isLockHeld(t.getCompatibilitySpace(), t, container.getId(),
ContainerLock.CS))
|              {
| -                // move lock from container group to transaction group.
| -                if (!forUpdate)
| -                    lf.transfer(t.getCompatibilitySpace(), group, t);
| +                // move locks from container group to transaction group.
| +				lf.transfer(t.getCompatibilitySpace(), group, t);
|  				container.setLockingPolicy(NO_LOCK);
|  			}
|  		}
| Index:
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94.sql
| ===================================================================
| ---
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94.sql
(revision 0)
| +++
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94.sql
(revision 0)
| @@ -0,0 +1,39 @@
| +create view lock_table as select
| +cast(l.type as char(8)) as type,cast(lockcount as char(3)) as
| +cnt,mode,cast(tablename as char(12)) as tabname,cast(lockname as
char(10))
| +as lockname,state from new org.apache.derby.diag.LockTable() l ;
| +autocommit off;
| +create table derby94_t1(c1 int, c2 int not null primary key);
| +create table derby94_t2(c1 int);
| +insert into derby94_t1 values (0, 200), (1, 201), (2, 202), (3, 203),
(4, 204), (5, 205), (6, 206), (7, 207), (8, 208), (9, 209);
| +insert into derby94_t1 select c1+10 , c2 +10 from derby94_t1;
| +insert into derby94_t1 select c1+20 , c2 +20 from derby94_t1;
| +insert into derby94_t1 select c1+40 , c2 +40 from derby94_t1;
| +insert into derby94_t1 select c1+80 , c2 +80 from derby94_t1;
| +insert into derby94_t2 values (0), (1), (2), (3), (4), (5), (6), (7),
(8), (9);
| +commit;
| +get cursor c1 as 'select * from derby94_t1 FOR UPDATE of c1';
| +next c1;
| +update derby94_t1 set c1=c1+999 WHERE CURRENT OF c1;
| +next c1;
| +get cursor c2 as 'select *  from derby94_t2 FOR UPDATE of c1';
| +next c2 ;
| +
| +select * from lock_table order by tabname, type desc, mode, cnt,
lockname ;
| +--following insert should get X lock on derby94_t2 because of
escalation , but should leave U lock on derby94_t1 as it is
| +insert into derby94_t2 select c1 from derby94_t1 ;
| +select * from lock_table order by tabname, type desc, mode, cnt,
lockname ;
| +
| +--following update statement should escalate the locks on derby94_t1
to table level X lock
| +update derby94_t1 set c1=c1+999 ;
| +select * from lock_table order by tabname, type desc, mode, cnt,
lockname ;
| +close c1 ;
| +close c2 ;
| +commit ;
| +--following lock table dump should not show any  locks, above commit
should have release them
| +select * from lock_table order by tabname, type desc, mode, cnt,
lockname;
| +drop table derby94_t1;
| +drop table derby94_t2;
| +commit;
| +--end derby-94 case
| +
| Index:
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94_derby.properties
| ===================================================================
| ---
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94_derby.properties
(revision 0)
| +++
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/derby94_derby.properties
(revision 0)
| @@ -0,0 +1,2 @@
| +#modify the lock escalation threshold to smaller value to make
testing simple
| +derby.locks.escalationThreshold=102
| Index:
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/copyfiles.ant
| ===================================================================
| ---
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/copyfiles.ant
(revision 123029)
| +++
java/testing/org/apache/derbyTesting/functionTests/tests/storetests/copyfiles.ant
(working copy)
| @@ -4,3 +4,5 @@
|  st_schema_app.properties
|  st_1.sql
|  st_b5772.sql
| +derby94.sql
| +derby94_derby.properties
| Index:
java/testing/org/apache/derbyTesting/functionTests/master/derby94.out
| ===================================================================
| ---
java/testing/org/apache/derbyTesting/functionTests/master/derby94.out
(revision 0)
| +++
java/testing/org/apache/derbyTesting/functionTests/master/derby94.out
(revision 0)
| @@ -0,0 +1,83 @@
| +ij> create view lock_table as select
| +cast(l.type as char(8)) as type,cast(lockcount as char(3)) as
| +cnt,mode,cast(tablename as char(12)) as tabname,cast(lockname as
char(10))
| +as lockname,state from new org.apache.derby.diag.LockTable() l ;
| +0 rows inserted/updated/deleted
| +ij> autocommit off;
| +ij> create table derby94_t1(c1 int, c2 int not null primary key);
| +0 rows inserted/updated/deleted
| +ij> create table derby94_t2(c1 int);
| +0 rows inserted/updated/deleted
| +ij> insert into derby94_t1 values (0, 200), (1, 201), (2, 202), (3,
203), (4, 204), (5, 205), (6, 206), (7, 207), (8, 208), (9, 209);
| +10 rows inserted/updated/deleted
| +ij> insert into derby94_t1 select c1+10 , c2 +10 from derby94_t1;
| +10 rows inserted/updated/deleted
| +ij> insert into derby94_t1 select c1+20 , c2 +20 from derby94_t1;
| +20 rows inserted/updated/deleted
| +ij> insert into derby94_t1 select c1+40 , c2 +40 from derby94_t1;
| +40 rows inserted/updated/deleted
| +ij> insert into derby94_t1 select c1+80 , c2 +80 from derby94_t1;
| +80 rows inserted/updated/deleted
| +ij> insert into derby94_t2 values (0), (1), (2), (3), (4), (5), (6),
(7), (8), (9);
| +10 rows inserted/updated/deleted
| +ij> commit;
| +ij> get cursor c1 as 'select * from derby94_t1 FOR UPDATE of c1';
| +ij> next c1;
| +C1         |C2
| +-----------------------
| +0          |200
| +ij> update derby94_t1 set c1=c1+999 WHERE CURRENT OF c1;
| +1 row inserted/updated/deleted
| +ij> next c1;
| +C1         |C2
| +-----------------------
| +1          |201
| +ij> get cursor c2 as 'select *  from derby94_t2 FOR UPDATE of c1';
| +ij> next c2 ;
| +C1
| +-----------
| +0
| +ij> select * from lock_table order by tabname, type desc, mode, cnt,
lockname ;
| +TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE
| +------------------------------------------------
| +TABLE   |2   |IX  |DERBY94_T1  |Tablelock |GRANT
| +ROW     |1   |U   |DERBY94_T1  |(1,8)     |GRANT
| +ROW     |1   |X   |DERBY94_T1  |(1,7)     |GRANT
| +TABLE   |1   |IX  |DERBY94_T2  |Tablelock |GRANT
| +ROW     |1   |U   |DERBY94_T2  |(1,7)     |GRANT
| +ij> --following insert should get X lock on derby94_t2 because of
escalation , but should leave U lock on derby94_t1 as it is
| +insert into derby94_t2 select c1 from derby94_t1 ;
| +160 rows inserted/updated/deleted
| +ij> select * from lock_table order by tabname, type desc, mode, cnt,
lockname ;
| +TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE
| +------------------------------------------------
| +TABLE   |3   |IX  |DERBY94_T1  |Tablelock |GRANT
| +ROW     |1   |U   |DERBY94_T1  |(1,8)     |GRANT
| +ROW     |1   |X   |DERBY94_T1  |(1,7)     |GRANT
| +TABLE   |4   |IX  |DERBY94_T2  |Tablelock |GRANT
| +TABLE   |1   |X   |DERBY94_T2  |Tablelock |GRANT
| +ij> --following update statement should escalate the locks on
derby94_t1 to table level X lock
| +update derby94_t1 set c1=c1+999 ;
| +160 rows inserted/updated/deleted
| +ij> select * from lock_table order by tabname, type desc, mode, cnt,
lockname ;
| +TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE
| +------------------------------------------------
| +TABLE   |8   |IX  |DERBY94_T1  |Tablelock |GRANT
| +TABLE   |1   |X   |DERBY94_T1  |Tablelock |GRANT
| +TABLE   |4   |IX  |DERBY94_T2  |Tablelock |GRANT
| +TABLE   |1   |X   |DERBY94_T2  |Tablelock |GRANT
| +ij> close c1 ;
| +ij> close c2 ;
| +ij> commit ;
| +ij> --following lock table dump should not show any  locks, above
commit should have release them
| +select * from lock_table order by tabname, type desc, mode, cnt,
lockname;
| +TYPE    |CNT |MODE|TABNAME     |LOCKNAME  |STATE
| +------------------------------------------------
| +ij> drop table derby94_t1;
| +0 rows inserted/updated/deleted
| +ij> drop table derby94_t2;
| +0 rows inserted/updated/deleted
| +ij> commit;
| +ij> --end derby-94 case
| +;
| +ij>
| Index:
java/testing/org/apache/derbyTesting/functionTests/suites/storetests.runall
| ===================================================================
| ---
java/testing/org/apache/derbyTesting/functionTests/suites/storetests.runall
(revision 123029)
| +++
java/testing/org/apache/derbyTesting/functionTests/suites/storetests.runall
(working copy)
| @@ -1,3 +1,4 @@
|  storetests/st_schema.sql
|  storetests/st_1.sql
|  storetests/st_b5772.sql
| +storetests/derby94.sql
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBy4d8EpeslyHqPs0RAqDdAKDulfisAqifdyuI6KCfnjm0snvREACfdrO6
TcWlEZyQRkV1rz+b6z/GSzA=
=0IqR
-----END PGP SIGNATURE-----

Mime
View raw message