Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: gengjun-git <[email protected]>
  • Loading branch information
gengjun-git committed Dec 12, 2024
1 parent 0efede1 commit b505109
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
27 changes: 23 additions & 4 deletions fe/fe-core/src/main/java/com/starrocks/warehouse/IdleStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,30 @@ public class IdleStatus {
@SerializedName("isClusterIdle")
boolean isClusterIdle;

@SerializedName("idleWarehouses")
List<Long> idleWarehouses;
@SerializedName("clusterIdleTime")
long clusterIdleTime;

public IdleStatus(boolean isClusterIdle, List<Long> idleWarehouses) {
@SerializedName("warehouses")
List<WarehouseStatus> warehouses;

public IdleStatus(boolean isClusterIdle, long clusterIdleTime, List<WarehouseStatus> warehouses) {
this.isClusterIdle = isClusterIdle;
this.idleWarehouses = idleWarehouses;
this.clusterIdleTime = clusterIdleTime;
this.warehouses = warehouses;
}

public static class WarehouseStatus {
@SerializedName("id")
long id;
@SerializedName("isIdle")
boolean isIdle;
@SerializedName("idleTime")
long idleTime;

public WarehouseStatus(long id, boolean isIdle, long idleTime) {
this.id = id;
this.isIdle = isIdle;
this.idleTime = idleTime;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class WarehouseIdleChecker extends FrontendDaemon {

private static final ConcurrentMap<Long, AtomicLong> LAST_FINISHED_JOB_TIME = new ConcurrentHashMap<>();

private static final ConcurrentMap<Long, Boolean> WAREHOUSE_IDLE = new ConcurrentHashMap<>();
private static final ConcurrentMap<Long, Long> WAREHOUSE_IDLE_TIME = new ConcurrentHashMap<>();

public WarehouseIdleChecker() {
super("WarehouseIdleChecker", Config.warehouse_idle_check_interval_seconds * 1000);
Expand Down Expand Up @@ -69,9 +69,9 @@ protected void runAfterCatalogReady() {
&& runningAlterJob == 0
&& lastFinishedJobTime.get() <
System.currentTimeMillis() - Config.warehouse_idle_check_interval_seconds * 1000) {
WAREHOUSE_IDLE.put(wId, true);
WAREHOUSE_IDLE_TIME.put(wId, System.currentTimeMillis());
} else {
WAREHOUSE_IDLE.put(wId, false);
WAREHOUSE_IDLE_TIME.remove(wId);
}
}
}
Expand Down Expand Up @@ -103,16 +103,19 @@ public IdleStatus getIdleStatus() {
List<Long> warehouseIds = GlobalStateMgr.getCurrentState().getWarehouseMgr().getAllWarehouseIds();

boolean isClusterIdle = true;
List<Long> idleWarehouses = new ArrayList<>();
List<IdleStatus.WarehouseStatus> warehouses = new ArrayList<>(warehouseIds.size());
long latestWarehouseIdleTime = -1L;
for (long wId : warehouseIds) {
boolean isIdle = WAREHOUSE_IDLE.getOrDefault(wId, false);
if (isIdle) {
idleWarehouses.add(wId);
} else {
Long wIdleTime = WAREHOUSE_IDLE_TIME.getOrDefault(wId, -1L);
if (wIdleTime == -1L) {
isClusterIdle = false;
} else {
latestWarehouseIdleTime = Math.max(latestWarehouseIdleTime, wIdleTime);
}

warehouses.add(new IdleStatus.WarehouseStatus(wId, wIdleTime == -1L, wIdleTime));
}

return new IdleStatus(isClusterIdle, idleWarehouses);
return new IdleStatus(isClusterIdle, isClusterIdle ? latestWarehouseIdleTime : -1, warehouses);
}
}

0 comments on commit b505109

Please sign in to comment.