davisp commented on a change in pull request #1789: New Feature: Database 
Partitions
URL: https://github.com/apache/couchdb/pull/1789#discussion_r242682989
 
 

 ##########
 File path: src/mango/src/mango_idx.erl
 ##########
 @@ -329,6 +339,87 @@ gen_name(Idx, Opts0) ->
     mango_util:enc_hex(Sha).
 
 
+get_idx_partitioned(Opts) ->
+    case proplists:get_value(partitioned, Opts) of
+        B when is_boolean(B) ->
+            B;
+        default ->
+            undefined
+    end.
+
+
+set_ddoc_partitioned(DDoc, Idx) ->
+    % We have to verify that the new index being added
+    % to this design document either matches the current
+    % ddoc's design options *or* this is a new design doc
+    #doc{
+        id = DDocId,
+        revs = Revs,
+        body = {BodyProps}
+    } = DDoc,
+    OldDOpts = couch_util:get_value(<<"options">>, BodyProps),
+    OldOpt = case OldDOpts of
+        {OldDOptProps} when is_list(OldDOptProps) ->
+            couch_util:get_value(<<"partitioned">>, OldDOptProps);
+        _ ->
+            undefined
+    end,
+    % If new matches old we're done
+    if Idx#idx.partitioned == OldOpt -> DDoc; true ->
+        % If we're creating a ddoc then we can set the options
+        case Revs == {0, []} of
+            true when Idx#idx.partitioned /= undefined ->
+                set_ddoc_partitioned_option(DDoc, Idx#idx.partitioned);
+            true when Idx#idx.partitioned == undefined ->
+                DDoc;
+            false ->
+                ?MANGO_ERROR({partitioned_option_mismatch, DDocId})
+        end
+    end.
+
+
+set_ddoc_partitioned_option(DDoc, Partitioned) ->
+    #doc{
+        body = {BodyProps}
+    } = DDoc,
+    NewProps = case couch_util:get_value(<<"options">>, BodyProps) of
 
 Review comment:
   BodyProps is user provided input so there's no guarantee that the 
`partitioned` key was provided in the JSON blob.

----------------------------------------------------------------
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

Reply via email to