Skip to content

Commit

Permalink
[Enhancement] reduce StarOSAgent lock contention (#34788)
Browse files Browse the repository at this point in the history
optimize the lock usage in prepare(), the serviceId will not be updated once non-empty.

Signed-off-by: Kevin Xiaohua Cai <caixiaohua@starrocks.com>
  • Loading branch information
kevincai authored Nov 10, 2023
1 parent 7b3dd61 commit 46e3509
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions fe/fe-core/src/main/java/com/starrocks/lake/StarOSAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,18 @@ public boolean init(StarManagerServer server) {
}

private void prepare() {
try (LockCloseable lock = new LockCloseable(rwLock.writeLock())) {
if (serviceId.equals("")) {
if (!serviceId.isEmpty()) {
return;
}

try (LockCloseable ignored = new LockCloseable(rwLock.readLock())) {
if (!serviceId.isEmpty()) {
return;
}
}

try (LockCloseable ignored = new LockCloseable(rwLock.writeLock())) {
if (serviceId.isEmpty()) {
getServiceId();
}
}
Expand Down

0 comments on commit 46e3509

Please sign in to comment.