You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2018/08/06 18:52:11 UTC
[couchdb] 02/06: Enforce partition:id format in doc ids
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch user-partitioned-dbs-4
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 172ef1099ad17d14ea2228461526f94a10634959
Author: Robert Newson <rn...@apache.org>
AuthorDate: Thu Aug 2 14:41:03 2018 +0100
Enforce partition:id format in doc ids
---
src/couch/src/couch_doc.erl | 26 ++++++++++++++++++++++----
src/couch/test/fixtures/test.couch | Bin 16482 -> 0 bytes
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/src/couch/src/couch_doc.erl b/src/couch/src/couch_doc.erl
index f960ec5..9caa5ee 100644
--- a/src/couch/src/couch_doc.erl
+++ b/src/couch/src/couch_doc.erl
@@ -133,6 +133,12 @@ from_json_obj_validate(EJson) ->
from_json_obj_validate(EJson, DbName) ->
MaxSize = config:get_integer("couchdb", "max_document_size", 4294967296),
Doc = from_json_obj(EJson, DbName),
+ case is_binary(DbName) andalso mem3:is_partitioned(DbName) of
+ true ->
+ couch_doc:validate_docid(Doc#doc.id, DbName);
+ false ->
+ ok
+ end,
case couch_ejson_size:encoded_size(Doc#doc.body) =< MaxSize of
true ->
validate_attachment_sizes(Doc#doc.atts),
@@ -199,11 +205,23 @@ parse_revs(_) ->
validate_docid(DocId, DbName) ->
- case DbName =:= ?l2b(config:get("mem3", "shards_db", "_dbs")) andalso
- lists:member(DocId, ?SYSTEM_DATABASES) of
- true ->
+ SystemId = DbName =:= ?l2b(config:get("mem3", "shards_db", "_dbs")) andalso
+ lists:member(DocId, ?SYSTEM_DATABASES),
+ Partitioned = is_binary(DbName) andalso mem3:is_partitioned(DbName),
+ case {SystemId, Partitioned} of
+ {true, _} ->
ok;
- false ->
+ {false, true} ->
+ case binary:split(DocId, <<":">>) of
+ [<<"_design/", _/binary>> | _Rest] ->
+ validate_docid(DocId);
+ [Partition, Rest] ->
+ ok = validate_docid(Partition),
+ validate_docid(Rest);
+ _ ->
+ throw({illegal_docid, <<"doc id must be of form partition:id">>})
+ end;
+ {false, false} ->
validate_docid(DocId)
end.
diff --git a/src/couch/test/fixtures/test.couch b/src/couch/test/fixtures/test.couch
deleted file mode 100644
index 32c79af..0000000
Binary files a/src/couch/test/fixtures/test.couch and /dev/null differ