Skip to content
Snippets Groups Projects
user avatar
Aleksandr Lyapunov authored
Introduce field constraints - limitaions for particular fields.
Each constraint must refer to a function in _func space. For the
first step we expect lua functions with body there.

Field constraint checks are very close to field type checks, so
it's natural to implement them in tuple formats. On the other hand
tuple formats belong to tuple library, that does not include
functions (func.h/c etc), so constraints are split into two parts:
- a part in tuple library that implements arbitrary constraints
 with pointers to functions that actually check constraints.
- a part in box library which uses the part above, sets particular
 check functions and handles alter etc.

There are two not-so-obvious problems that are solved here:
 - Functions in _func space must be preserved while used by such
 constraints. Func pinning is used for this purpose.
 - During initial recovery constraits are created before _func
 space recovery, so we have to pospone constraint initialization.

One can set up constraint for any field in tuple format with one
or several functions that must be present in _func space:
space:format{name='a', constraint='func1'}
space:format{name='a', constraint={name1='func1'}}
space:format{name='a', constraint={name1='func1', name2='func2'}}

So constraint(s) can be set by one function name or by lua table
with function name values. Each consraints has a name that can be
specified directly (with string key in table) or imlicitly set to
the name of function.

The check function receives two arguments: the checking value and
the name of the constraint. Also the name of the failed constraint
is present in raised exception.

The only way to pass the constraint is to return true from its
function. All other values and exception are treated as failure
(exeptions are also logged).

NO_DOC=see later commits
NO_CHANGELOG=see later commits
ed9b982d
History
Name Last commit Last update