File 0812-Fixed-index-updates-on-updating-records.patch of Package erlang
From 335cefae70422d16d5f666101c414ce3bd1292e0 Mon Sep 17 00:00:00 2001
From: Dan Gudmundsson <dgud@erlang.org>
Date: Thu, 14 Nov 2019 08:13:01 +0100
Subject: [PATCH] Fixed index updates on updating records
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
By changing the order we can make it work for more types of indecies.
Thanks Sebastian SmyczyĆski.
ERL-1091
---
lib/mnesia/src/mnesia_index.erl | 2 +-
lib/mnesia/test/mnesia_dirty_access_test.erl | 2 +-
lib/mnesia/test/mnesia_index_plugin_test.erl | 23 +++++++++++++++++++++--
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/lib/mnesia/src/mnesia_index.erl b/lib/mnesia/src/mnesia_index.erl
index 6f1c21e3b9..0ab03adcd8 100644
--- a/lib/mnesia/src/mnesia_index.erl
+++ b/lib/mnesia/src/mnesia_index.erl
@@ -106,8 +106,8 @@ add_index2([{{Pos, Type}, Ixt} |Tail], SorB, Storage, Tab, K, Obj, OldRecs0) ->
[] -> %% when OldRecs1 =/= [] Update without modifying index field
add_index2(Tail, SorB, Storage, Tab, K, Obj, OldRecs1);
OldRecs -> %% Update
- put_index_vals(Type, Ixt, NewVals, K),
[del_ixes(Type, Ixt, ValsF, OldObj, K) || OldObj <- OldRecs],
+ put_index_vals(Type, Ixt, NewVals, K),
add_index2(Tail, SorB, Storage, Tab, K, Obj, OldRecs1)
end;
add_index2([], _, _, _Tab, _K, _Obj, _) -> ok.
diff --git a/lib/mnesia/test/mnesia_dirty_access_test.erl b/lib/mnesia/test/mnesia_dirty_access_test.erl
index 984f43582c..7aafbbb98b 100644
--- a/lib/mnesia/test/mnesia_dirty_access_test.erl
+++ b/lib/mnesia/test/mnesia_dirty_access_test.erl
@@ -116,7 +116,7 @@ end_per_group(_GroupName, Config) ->
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Errors in dirty activity should have stacktrace
-dirty_error_stacktrace(Config) ->
+dirty_error_stacktrace(_Config) ->
%% Custom errors should have stacktrace
try
mnesia:async_dirty(fun() -> error(custom_error) end)
diff --git a/lib/mnesia/test/mnesia_index_plugin_test.erl b/lib/mnesia/test/mnesia_index_plugin_test.erl
index 44fe047c50..ede35269ec 100644
--- a/lib/mnesia/test/mnesia_index_plugin_test.erl
+++ b/lib/mnesia/test/mnesia_index_plugin_test.erl
@@ -33,7 +33,8 @@
tab_with_multiple_plugin_indexes/1,
ix_match_w_plugin/1,
ix_match_w_plugin_ordered/1,
- ix_match_w_plugin_bag/1
+ ix_match_w_plugin_bag/1,
+ ix_update_w_plugin/1
]).
-export([ix_prefixes/3, % test plugin
@@ -59,7 +60,8 @@ all() ->
tab_with_multiple_plugin_indexes,
ix_match_w_plugin,
ix_match_w_plugin_ordered,
- ix_match_w_plugin_bag].
+ ix_match_w_plugin_bag,
+ ix_update_w_plugin].
groups() ->
[].
@@ -195,6 +197,23 @@ ix_match_w_plugin_bag(Config) when is_list(Config) ->
fill_and_test_index_match(im3, bag),
?verify_mnesia(Nodes, []).
+ix_update_w_plugin(suite) -> [];
+ix_update_w_plugin(Config) when is_list(Config) ->
+ [_N1] = Nodes = ?acquire_nodes(1, Config),
+ ok = add_plugin(),
+ {atomic, ok} = mnesia:create_table(im4, [{attributes, [k, v1, v2]},
+ {type, ordered_set},
+ {index, [{{pfx}, ordered},
+ {v1, ordered}]}]),
+
+ mnesia:dirty_write({im4, 1, "1234", "abcd"}),
+ ?match([{im4, 1, "1234", "abcd"}], mnesia:dirty_index_read(im4, <<"123">>, {pfx})),
+ ?match([{im4, 1, "1234", "abcd"}], mnesia:dirty_index_read(im4, <<"abc">>, {pfx})),
+ mnesia:dirty_write({im4, 1, "1234", "efgh"}),
+ ?match([{im4, 1, "1234", "efgh"}], mnesia:dirty_index_read(im4, <<"123">>, {pfx})),
+ ?match([{im4, 1, "1234", "efgh"}], mnesia:dirty_index_read(im4, <<"efg">>, {pfx})),
+ ?verify_mnesia(Nodes, []).
+
fill_and_test_index_match(Tab, Type) ->
[ok,ok,ok,ok,ok,ok,ok,ok,ok] =
[mnesia:dirty_write({Tab, K, V1, V2})
--
2.16.4