davisp commented on a change in pull request #1789: New Feature: Database Partitions URL: https://github.com/apache/couchdb/pull/1789#discussion_r242694597
########## File path: src/couch/src/couch_partition.erl ########## @@ -0,0 +1,156 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(couch_partition). + + +-export([ + extract/1, + from_docid/1, + is_member/2, + + start_key/1, + end_key/1, + + validate_dbname/2, + validate_docid/1, + validate_partition/1, + + hash/1 +]). + + +-include_lib("couch/include/couch_db.hrl"). + + +extract(Value) when is_binary(Value) -> + case binary:split(Value, <<":">>) of + [Partition, Rest] -> + {Partition, Rest}; + _ -> + undefined + end; + +extract(_) -> + undefined. + + +from_docid(DocId) -> + case extract(DocId) of + undefined -> + throw({illegal_docid, <<"doc id must be of form partition:id">>}); + {Partition, _} -> + Partition + end. + + +is_member(DocId, Partition) -> + case extract(DocId) of + {Partition, _} -> + true; + _ -> + false + end. + + +start_key(Partition) -> + <<Partition/binary, ":">>. + + +end_key(Partition) -> + <<Partition/binary, ";">>. + + +validate_dbname(DbName, Options) when is_list(DbName) -> + validate_dbname(?l2b(DbName), Options); +validate_dbname(DbName, Options) when is_binary(DbName) -> + Props = couch_util:get_value(props, Options, []), + IsPartitioned = couch_util:get_value(partitioned, Props, false), + + if not IsPartitioned -> ok; true -> + + DbsDbName = config:get("mem3", "shards_db", "_dbs"), Review comment: Not entirely sure though that's a different PR if so. The places its used I think make it look like not but I dunno as I've not used it in this PR. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
