File tree Expand file tree Collapse file tree 5 files changed +34
-5
lines changed
fe/fe-core/src/main/java/com/starrocks Expand file tree Collapse file tree 5 files changed +34
-5
lines changed Original file line number Diff line number Diff line change @@ -495,8 +495,10 @@ public void execute() throws Exception {
495
495
httpResultSender = new HttpResultSender ((HttpConnectContext ) context );
496
496
}
497
497
498
- if (shouldMarkIdleCheck (parsedStmt )) {
499
- WarehouseIdleChecker .increaseRunningSQL (context .getCurrentWarehouseId ());
498
+ final boolean shouldMarkIdleCheck = shouldMarkIdleCheck (parsedStmt );
499
+ final long originWarehouseId = context .getCurrentWarehouseId ();
500
+ if (shouldMarkIdleCheck ) {
501
+ WarehouseIdleChecker .increaseRunningSQL (originWarehouseId );
500
502
}
501
503
try {
502
504
context .getState ().setIsQuery (parsedStmt instanceof QueryStatement );
@@ -807,8 +809,8 @@ public void execute() throws Exception {
807
809
// restore session variable in connect context
808
810
context .setSessionVariable (sessionVariableBackup );
809
811
810
- if (shouldMarkIdleCheck ( parsedStmt ) ) {
811
- WarehouseIdleChecker .decreaseRunningSQL (context . getCurrentWarehouseId () );
812
+ if (shouldMarkIdleCheck ) {
813
+ WarehouseIdleChecker .decreaseRunningSQL (originWarehouseId );
812
814
}
813
815
814
816
recordExecStatsIntoContext ();
Original file line number Diff line number Diff line change @@ -285,6 +285,17 @@ public Optional<Long> selectWorkerGroupByWarehouseId(long warehouseId) {
285
285
return workerGroupId ;
286
286
}
287
287
288
+ public long getWarehouseResumeTime (long warehouseId ) {
289
+ try (LockCloseable ignored = new LockCloseable (rwLock .readLock ())) {
290
+ Warehouse warehouse = idToWh .get (warehouseId );
291
+ if (warehouse == null ) {
292
+ return -1 ;
293
+ } else {
294
+ return warehouse .getResumeTime ();
295
+ }
296
+ }
297
+ }
298
+
288
299
private Optional <Long > selectWorkerGroupInternal (long warehouseId ) {
289
300
Warehouse warehouse = getWarehouse (warehouseId );
290
301
List <Long > ids = warehouse .getWorkerGroupIds ();
Original file line number Diff line number Diff line change @@ -72,4 +72,9 @@ public List<List<String>> getWarehouseNodesInfo() {
72
72
public ProcResult fetchResult () {
73
73
return new BaseProcResult ();
74
74
}
75
+
76
+ @ Override
77
+ public long getResumeTime () {
78
+ return -1L ;
79
+ }
75
80
}
Original file line number Diff line number Diff line change @@ -56,6 +56,8 @@ public void write(DataOutput out) throws IOException {
56
56
Text .writeString (out , json );
57
57
}
58
58
59
+ public abstract long getResumeTime ();
60
+
59
61
public abstract Long getAnyWorkerGroupId ();
60
62
61
63
public abstract List <Long > getWorkerGroupIds ();
Original file line number Diff line number Diff line change @@ -76,7 +76,16 @@ protected void runAfterCatalogReady() {
76
76
if (runningJobCnt == 0
77
77
&& lastFinishedJobTime <
78
78
System .currentTimeMillis () - Config .warehouse_idle_check_interval_seconds * 2000 ) {
79
- warehouseIdleTime .putIfAbsent (wId , System .currentTimeMillis ());
79
+ long resumeTime = GlobalStateMgr .getCurrentState ().getWarehouseMgr ().getWarehouseResumeTime (wId );
80
+ warehouseIdleTime .compute (wId , (k , v ) -> {
81
+ // If this is the first time to become idle, set idleTime to now.
82
+ // If resumed during an idle period, change idleTime to resumeTime.
83
+ if (v == null ) {
84
+ return System .currentTimeMillis ();
85
+ } else {
86
+ return v < resumeTime ? resumeTime : v ;
87
+ }
88
+ });
80
89
LOG .info ("warehouse: {} is idle, idle start time: {}" ,
81
90
wId , TimeUtils .longToTimeString (warehouseIdleTime .get (wId )));
82
91
} else {
You can’t perform that action at this time.
0 commit comments