多个客户(志腾永盛、奔鑫达等)的服务端长时间运行后出现:
16:45:02 StoredProc EXEC GetPrimaryBinLoc → 锁超时
16:45:30 SELECT * FROM V_PURTDDetail → 锁超时
16:45:41 SELECT * FROM V_PURTDDetail → 锁超时
16:45:49 SELECT * FROM V_PURTDDetail → 锁超时
16:46:06 SELECT * FROM V_PURTDDetail → 锁超时
文件: Library\ServerCore\UniDataAccessUnit.pas
文件: Library\ServerCore\ADODataAccessUnit.pas
改动: 在 GetDataPack() 中,将 Active := True 的直接 try-except 改为最多 3 次重试循环(每次间隔 3 秒):
for I := 0 to 2 do
begin
try
Active := True;
Break; // 查询成功,跳出重试循环
except
on E: Exception do
begin
if (I < 2) and ((Pos('锁请求超时', E.Message) > 0) or
(Pos('已超过了锁请求超时时段', E.Message) > 0)) then
begin
// 关闭当前查询, 等 3 秒, 重新执行
Active := False;
Sleep(3000);
SQL.Clear;
SQL.Add(strSQL);
Self.WriteLog(Format('锁超时重试 %d/2: %s', [I+1, strSQL]), False);
end
else
begin
// 非锁超时或最终仍失败 → 记录日志后退出
...
Exit;
end;
end;
end;
end;
效果: 临时锁阻塞自动重试 2 次,6 秒内自动恢复,用户无感。
文件: ERPServer\fMain.pas
改动:
private
FDailyRestartHour: Integer; // 0=禁用, 1~23=凌晨几点重启
FLastRestartDate: TDateTime; // 上次重启日期, 防止一天内重复
FDailyRestartHour := FIniConfig.ReadInteger('System', 'DailyRestartHour', 0);
if (FDailyRestartHour > 0) and (FDailyRestartHour <= 23) then
begin
today := Trunc(Date);
if (FLastRestartDate < today) then
begin
DecodeTime(Time, curHour, curMin, curSec, curMSec);
if (curHour >= FDailyRestartHour) and (curHour <= FDailyRestartHour + 1) then
begin
Self.StopServer();
Sleep(2000);
Self.StartServer();
FLastRestartDate := today;
Exit;
end;
end;
end;
INI 配置(在 ERPServer.exe 同目录的 INI 文件中):
[System]
DailyRestartHour=3 ; 每天凌晨 3 点自动重启, 0=禁用
效果: 服务器每天定时重启一次,释放内存和数据库连接池资源,避免长期运行积压锁。
| 修改文件 | 影响范围 |
|---|---|
| `UniDataAccessUnit.pas` | BlueWhaleServerCore.bpl |
| `ADODataAccessUnit.pas` | BlueWhaleServerCore.bpl |
| `ERPServer/fMain.pas` | ERPServer.exe |
DailyRestartHour=0(禁用),老客户无缝升级无影响DailyRestartHour=3 即可启用凌晨 3 点每日重启