iilyak commented on PR #4291:
URL: https://github.com/apache/couchdb/pull/4291#issuecomment-1362991997

   JFYI 
   In case if there is an intend to run two backends at the same time.
   Instead of relying on `config:get_boolean("nouveau", "enable", false).` it 
should be possible to enable/disable nouveau on per databases basis using 
feature flags. The feature flags are compiled down into an erlang module and 
therefore very efficient (if performance is the concern).
   
   At the moment the feature flags are used for partition queries. However they 
can be used here as well. In order to make them work the `subject` need to be 
passed to the check function. Currently supported subjects are defined 
[here](https://github.com/apache/couchdb/blob/main/src/couch/src/couch_flags.erl#L109:L122).
 The check for a feature flag look like `couch_flags:is_enabled(nouveau, 
Subject)`. In order to make it work for `#idx{}` and `#index{}` records we 
would need to extract the database name.
   
   ```erlang
   is_nouveau(#index{dbname = Subject}) ->
        couch_flags:is_enabled(nouveau, Subject);
   is_nouveau(#idx{dbname = Subject}) ->
        couch_flags:is_enabled(nouveau, Subject).
   ```
   
   The configuration for feature flag is done in ini files as follows.
   
   ```ini
   [feature_flags]
   ; This enables nouveau for databases with given prefix. 
   nouveau||my_database* = true
   ```
   
   Supporting another type of a subject also supported via EPI. 
   
   ```erlang
   -module(nouveue_plugin_feature_flags).
   
   -export([
       rules/0,
       subject_key/1
   ]).
   
   rules() ->
       [].
   
   subject_key(#idx{dbname = Subject}) ->
      Subject;
   subject_key(#index{dbname = Subject}) ->
      Subject;    
   subject_key(_) ->
       no_decision.
   ```
   
   ```erlang
   -module(nouveau_epi).
   
   -behaviour(couch_epi_plugin).
   
   ....
   providers() ->
       [
            {chttpd_handlers, nouveau_httpd_handlers},
            {feature_flags, nouveau_plugin_feature_flags}
       ].
   
   ```
   
   The only two places in the PR which are hard to do are in `nouveau_api.erl` 
since in these case we don't have access to database name.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to