Skip to content

Commit 8242295

Browse files
authored
[BugFix] Fix DeleteMgr use Read Lock in the scope of IS Lock bug (StarRocks#48784)
Signed-off-by: HangyuanLiu <[email protected]>
1 parent e859640 commit 8242295

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

fe/fe-core/src/main/java/com/starrocks/common/util/concurrent/lock/LockType.java

+13
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ public boolean isConflict(LockType requestedType) {
6565
return !CONFLICT_MATRIX[id][requestedType.id];
6666
}
6767

68+
public boolean isIntentionLock() throws NotSupportLockException {
69+
switch (id) {
70+
case 0:
71+
case 1:
72+
return false;
73+
case 2:
74+
case 3:
75+
return true;
76+
}
77+
78+
throw new NotSupportLockException("Lock Internal Error");
79+
}
80+
6881
@Override
6982
public String toString() {
7083
if (id == 0) {

fe/fe-core/src/main/java/com/starrocks/common/util/concurrent/lock/MultiUserLock.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ private LockGrantType tryLock(LockHolder lockHolderRequest) throws LockException
103103
* The outer layer has already obtained the intention lock,
104104
* and the inner layer code should not apply for read-write locks.
105105
*/
106-
if ((lockOwnerLockType == LockType.INTENTION_SHARED || lockOwnerLockType == LockType.INTENTION_EXCLUSIVE)
107-
&& (lockRequestLockType == LockType.READ || lockRequestLockType == LockType.WRITE)) {
108-
throw new NotSupportLockException("Can't request " + lockRequestLockType
109-
+ " in the scope of " + lockOwnerLockType + ", " + lockOwner.getLocker().getLockerStackTrace());
106+
107+
if (lockOwnerLockType.isIntentionLock() && !lockRequestLockType.isIntentionLock()) {
108+
throw new NotSupportLockException("Can't request Database " + lockRequestLockType + " Lock ("
109+
+ lockHolderRequest.getLocker().getLockerStackTrace() + ")"
110+
+ " in the scope of Database " + lockOwnerLockType
111+
+ "Lock (" + lockOwner.getLocker().getLockerStackTrace() + ")");
110112
}
111113

112114
/*

fe/fe-core/src/main/java/com/starrocks/load/DeleteMgr.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void process(DeleteStmt stmt) throws DdlException, QueryStateException {
190190
try {
191191
List<Partition> partitions = Lists.newArrayList();
192192
Locker locker = new Locker();
193-
locker.lockTablesWithIntensiveDbLock(db, Lists.newArrayList(table.getId()), LockType.READ);
193+
locker.lockDatabase(db, LockType.READ);
194194
try {
195195
if (!table.isOlapOrCloudNativeTable()) {
196196
throw new DdlException("Delete is not supported on " + table.getType() + " table");
@@ -212,7 +212,7 @@ public void process(DeleteStmt stmt) throws DdlException, QueryStateException {
212212
}
213213
throw new DdlException(t.getMessage(), t);
214214
} finally {
215-
locker.unLockTablesWithIntensiveDbLock(db, Lists.newArrayList(table.getId()), LockType.READ);
215+
locker.unLockDatabase(db, LockType.READ);
216216
}
217217

218218
deleteJob.run(stmt, db, table, partitions);

0 commit comments

Comments
 (0)