Skip to content

Commit

Permalink
[BugFix] remove threadLocal after operation (StarRocks#34758)
Browse files Browse the repository at this point in the history
Signed-off-by: packy92 <wangchao@starrocks.com>
  • Loading branch information
packy92 committed Nov 18, 2023
1 parent b1c0f30 commit 8e4414a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fe/fe-core/src/main/java/com/starrocks/qe/StmtExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,12 @@ private void executeAnalyze(AnalyzeStmt analyzeStmt, AnalyzeStatus analyzeStatus
statsConnectCtx.getSessionVariable().setStatisticCollectParallelism(
context.getSessionVariable().getStatisticCollectParallelism());
statsConnectCtx.setThreadLocalInfo();
executeAnalyze(statsConnectCtx, analyzeStmt, analyzeStatus, db, table);
try {
executeAnalyze(statsConnectCtx, analyzeStmt, analyzeStatus, db, table);
} finally {
ConnectContext.remove();
}

}

private void executeAnalyze(ConnectContext statsConnectCtx, AnalyzeStmt analyzeStmt, AnalyzeStatus analyzeStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

package com.starrocks.scheduler;

import com.starrocks.qe.ConnectContext;
import com.starrocks.scheduler.persist.TaskRunStatus;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -56,6 +57,7 @@ public void executeTaskRun(TaskRun taskRun) {
status.setErrorCode(-1);
status.setErrorMessage(ex.toString());
} finally {
ConnectContext.remove();
status.setFinishTime(System.currentTimeMillis());
}
return status.getState();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class ColumnBasicStatsCacheLoader implements AsyncCacheLoader<ColumnStats
throw e;
} catch (Exception e) {
throw new CompletionException(e);
} finally {
ConnectContext.remove();
}
}, executor);
}
Expand Down Expand Up @@ -105,6 +107,8 @@ public class ColumnBasicStatsCacheLoader implements AsyncCacheLoader<ColumnStats
throw e;
} catch (Exception e) {
throw new CompletionException(e);
} finally {
ConnectContext.remove();
}
}, executor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ CompletableFuture<Optional<Histogram>> asyncLoad(@NonNull ColumnStatsCacheKey ca
throw e;
} catch (Exception e) {
throw new CompletionException(e);
} finally {
ConnectContext.remove();
}
}, executor);
}
Expand Down Expand Up @@ -107,6 +109,8 @@ CompletableFuture<Optional<Histogram>> asyncLoad(@NonNull ColumnStatsCacheKey ca
throw e;
} catch (Exception e) {
throw new CompletionException(e);
} finally {
ConnectContext.remove();
}
}, executor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class TableStatsCacheLoader implements AsyncCacheLoader<TableStatsCacheKe
throw e;
} catch (Exception e) {
throw new CompletionException(e);
} finally {
ConnectContext.remove();
}
}, executor);
}
Expand Down Expand Up @@ -84,6 +86,8 @@ public class TableStatsCacheLoader implements AsyncCacheLoader<TableStatsCacheKe
throw e;
} catch (Exception e) {
throw new CompletionException(e);
} finally {
ConnectContext.remove();
}
}, executor);
}
Expand Down

0 comments on commit 8e4414a

Please sign in to comment.