couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ulises <ulises.cerv...@gmail.com>
Subject Config Validators
Date Tue, 13 Jan 2009 14:59:22 GMT
Hey all,

I'm in the process of writing configuration validators, i.e. a fun
that gets invoked when a change in a config parameter is requested via
PUT. The main machinery is in place in couch_config.erl and now
modules can register their validators through
couch_config:register_validator(fun f/3, {Section, Key}). Next time
couch_config receives a PUT with a value Value for {Section, Key} it
will invoke f(Section, Key, Value). In terms of code a module should
have

foo_validator("section", "key", Value) ->
  % do your validation here
  % if all went well return ok, else return {error, Msg}
  ok.

init( ... ) ->
  % do your init
  couch_config:register_validator(fun foo_validator/3, {"section", "key"}),
  % more stuff
  Reply.

It's fine and dandy and working. The issue to solve now is validating
parameter values before init (or before the module can actually start
doing useful stuff).

Here's the two options I came up with:

1) validate everything on load of parameter values (on couch_config)
and then signal a "config change" so that modules can reload and
change from a blank state to a configured state. This implies that
modules only register validators on init and then wait for signals
(somehow). That is: 2 inits. Not very nice really.

2) each module's init validates values coming from config (config
doesn't do any checking on load from file) and if any value is invalid
it deals with the error itself, registering validators still applies
for config changes. This would keep couch_config.erl simpler and
validating on init on each module is not such a big deal anyway as you
would ideally reuse the funs you've registered as validators.

If you have any suggestions please let me know, I'm planning on
implementing this tonight.

BTW, this whole validation thing was motivated by ticket 153
(https://issues.apache.org/jira/browse/COUCHDB-153).

U

Mime
View raw message