Skip to content

Commit

Permalink
Apply changes for MSSQL
Browse files Browse the repository at this point in the history
  • Loading branch information
arcusfelis committed May 14, 2024
1 parent f8f26af commit 3ca7a60
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/mod_last_rdbms.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,18 @@ prepare_cleanup_tasks(Records) ->
[{1, last_upsert, Rec} || Rec <- Singles2].

run_tasks_in_parallel(RunTaskF, AllTasks) ->
Workers = 8,
%% MSSQL fails with "Transaction (Process ID 52) was deadlocked on lock resources with
%% another process and has been chosen as the deadlock victim. Rerun the transaction"
Workers = case mongoose_rdbms:db_type() of mssql -> 1; _ -> 8 end,
TasksForWorkers = spread(Workers, AllTasks),
RunTasksF = fun(Tasks) -> lists:map(RunTaskF, Tasks) end,
Results = mongoose_lib:pmap(RunTasksF, TasksForWorkers, timer:minutes(1)),
[check_result(Res) || Res <- Results],
ok.

run_upsert(HostType, 1, QueryName, InsertParams, UpdateParams) ->
run_upsert(HostType, 1, QueryName, InsertParams = [S, U|_], UpdateParams) ->
{updated, _} = rdbms_queries:execute_upsert(HostType, QueryName,
InsertParams, UpdateParams, []);
InsertParams, UpdateParams, [S, U]);
run_upsert(HostType, _Count, QueryName, InsertParams, UpdateParams) ->
%% MySQL replace returns wrong numbers
{updated, _} = rdbms_queries:execute_upsert_many(HostType, QueryName,
Expand Down

0 comments on commit 3ca7a60

Please sign in to comment.