summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjiangph <jiangph@cn.ibm.com>2019-08-23 18:24:01 +0800
committerjiangph <jiangph@cn.ibm.com>2019-08-24 00:26:26 +0800
commite9e8ae5a0f4bffdb1109f9a008a7d43624ee9c63 (patch)
tree1749b4e7586e8b3961e2c73a87a8fa9447ebc031
parent2affa90130e27da038363d4941cf8cb539cf4948 (diff)
downloadcouchdb-keep-dbprop-after-rewriting-shardmap.tar.gz
Keep database property after overwriting shard mapkeep-dbprop-after-rewriting-shardmap
-rw-r--r--src/chttpd/test/eunit/chttpd_db_test.erl24
-rw-r--r--src/mem3/src/mem3_util.erl16
2 files changed, 39 insertions, 1 deletions
diff --git a/src/chttpd/test/eunit/chttpd_db_test.erl b/src/chttpd/test/eunit/chttpd_db_test.erl
index 17250199a..c819bdf6e 100644
--- a/src/chttpd/test/eunit/chttpd_db_test.erl
+++ b/src/chttpd/test/eunit/chttpd_db_test.erl
@@ -73,6 +73,7 @@ all_test_() ->
fun should_not_return_update_seq_when_unset_on_all_docs/1,
fun should_return_correct_id_on_doc_copy/1,
fun should_return_400_for_bad_engine/1,
+ fun should_not_change_db_proper_after_rewriting_shardmap/1,
fun should_succeed_on_all_docs_with_queries_keys/1,
fun should_succeed_on_all_docs_with_queries_limit_skip/1,
fun should_succeed_on_all_docs_with_multiple_queries/1,
@@ -297,6 +298,29 @@ should_return_400_for_bad_engine(_) ->
end)}.
+should_not_change_db_proper_after_rewriting_shardmap(_) ->
+ {timeout, ?TIMEOUT, ?_test(begin
+ TmpDb = ?tempdb(),
+ Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
+ Port = mochiweb_socket_server:get(chttpd, port),
+ AdmPort = mochiweb_socket_server:get(couch_httpd, port),
+
+ BaseUrl = lists:concat(["http://", Addr, ":", Port, "/", ?b2l(TmpDb)]),
+ Url = BaseUrl ++ "?partitioned=true&q=1",
+ {ok, 201, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"),
+
+ ShardDbName = ?l2b(config:get("mem3", "shards_db", "_dbs")),
+ {ok, ShardDb} = mem3_util:ensure_exists(ShardDbName),
+ {ok, #doc{body = {Props}}} = couch_db:open_doc(
+ ShardDb, TmpDb, [ejson_body]),
+ Shards = mem3_util:build_shards(TmpDb, Props),
+
+ {Prop2} = ?JSON_DECODE(?JSON_ENCODE({Props})),
+ Shards2 = mem3_util:build_shards(TmpDb, Prop2),
+ ?assertEqual(Shards2, Shards)
+ end)}.
+
+
should_succeed_on_all_docs_with_queries_keys(Url) ->
{timeout, ?TIMEOUT, ?_test(begin
[create_doc(Url, "testdoc" ++ ?i2l(I)) || I <- lists:seq(1, 10)],
diff --git a/src/mem3/src/mem3_util.erl b/src/mem3/src/mem3_util.erl
index e8cba5d7b..3fc9b4f8e 100644
--- a/src/mem3/src/mem3_util.erl
+++ b/src/mem3/src/mem3_util.erl
@@ -221,11 +221,25 @@ get_engine_opt(DocProps) ->
get_props_opt(DocProps) ->
case couch_util:get_value(<<"props">>, DocProps) of
{Props} when is_list(Props) ->
- [{props, Props}];
+ [{props, db_props_from_json(Props)}];
_ ->
[]
end.
+db_props_from_json([]) ->
+ [];
+
+db_props_from_json([{<<"partitioned">>, Value} | Rest]) ->
+ [{partitioned, Value} | db_props_from_json(Rest)];
+
+db_props_from_json([{<<"hash">>, [MBin, FBin, A]} | Rest]) ->
+ M = binary_to_existing_atom(MBin, utf8),
+ F = binary_to_existing_atom(FBin, utf8),
+ [{hash, [M, F, A]} | db_props_from_json(Rest)];
+
+db_props_from_json([{K, V} | Rest]) ->
+ [{K, V} | db_props_from_json(Rest)].
+
n_val(undefined, NodeCount) ->
n_val(config:get("cluster", "n", "3"), NodeCount);
n_val(N, NodeCount) when is_list(N) ->