Optimization of xldb_put

Added flags parameter to default functions
removed call to bind
This commit is contained in:
Olof hagsand 2024-02-06 09:27:51 +01:00
parent 23dcb58758
commit d660c01a58
16 changed files with 50 additions and 60 deletions

View file

@ -24,6 +24,7 @@ Expected: February 2024
* All clixon applications added command-line option `-V` for printing version * All clixon applications added command-line option `-V` for printing version
* New ca_version callback for customized version output * New ca_version callback for customized version output
* Optimization: * Optimization:
* Improved performance of GET and PUT operations
* Optimized datastore access by ensuring REPORT_ALL in memory and EXPLICIT in file * Optimized datastore access by ensuring REPORT_ALL in memory and EXPLICIT in file
* Added mountpoint cache as yang flag `YANG_FLAG_MTPOINT_POTENTIAL` * Added mountpoint cache as yang flag `YANG_FLAG_MTPOINT_POTENTIAL`
* Optimized `yang_find`, especially namespace lookup * Optimized `yang_find`, especially namespace lookup
@ -46,6 +47,10 @@ Users may have to change how they access the system
### C/CLI-API changes on existing features ### C/CLI-API changes on existing features
Developers may need to change their code Developers may need to change their code
* Added flags parameter to default functions:
* `xml_default_recurse(...)` -> `xml_default_recurse(..., 0)`
* `xml_defaults_nopresence(...)` -> `xml_default_nopresence(..., 0)`
* Also renamed (_defaults_ -> _default_)
* Changed function name: `choice_case_get()` -> `yang_choice_case_get()` * Changed function name: `choice_case_get()` -> `yang_choice_case_get()`
* New `clixon-lib@2024-01-01.yang` revision * New `clixon-lib@2024-01-01.yang` revision
* Removed container creators, reverted from 6.5 * Removed container creators, reverted from 6.5

View file

@ -285,7 +285,7 @@ startup_common(clixon_handle h,
if (xml_global_defaults(h, xt, NULL, NULL, yspec, 0) < 0) if (xml_global_defaults(h, xt, NULL, NULL, yspec, 0) < 0)
goto done; goto done;
/* Apply default values (removed in clear function) */ /* Apply default values (removed in clear function) */
if (xml_default_recurse(xt, 0) < 0) if (xml_default_recurse(xt, 0, 0) < 0)
goto done; goto done;
/* Handcraft transition with with only add tree */ /* Handcraft transition with with only add tree */
@ -421,7 +421,7 @@ startup_commit(clixon_handle h,
if (plugin_transaction_commit_done_all(h, td) < 0) if (plugin_transaction_commit_done_all(h, td) < 0)
goto done; goto done;
/* Remove global defaults and empty non-presence containers */ /* Remove global defaults and empty non-presence containers */
if (xml_defaults_nopresence(td->td_target, 2) < 0) if (xml_default_nopresence(td->td_target, 2, 0) < 0)
goto done; goto done;
/* [Delete and] create running db */ /* [Delete and] create running db */
if (xmldb_exists(h, "running") == 1){ if (xmldb_exists(h, "running") == 1){

View file

@ -950,7 +950,7 @@ get_common(clixon_handle h,
if (xml_global_defaults(h, xret, nsc, xpath, yspec, 1) < 0) if (xml_global_defaults(h, xret, nsc, xpath, yspec, 1) < 0)
goto done; goto done;
/* Apply default values */ /* Apply default values */
if (xml_default_recurse(xret, 1) < 0) if (xml_default_recurse(xret, 1, 0) < 0)
goto done; goto done;
break; break;
} }

View file

@ -389,7 +389,7 @@ clixon_plugin_statedata_all(clixon_handle h,
goto done; goto done;
/* Remove global defaults and empty non-presence containers */ /* Remove global defaults and empty non-presence containers */
/* XXX: only for state data and according to with-defaults setting */ /* XXX: only for state data and according to with-defaults setting */
if (xml_defaults_nopresence(x, 2) < 0) if (xml_default_nopresence(x, 2, 0) < 0)
goto done; goto done;
if (xpath_first(x, nsc, "%s", xpath) != NULL){ if (xpath_first(x, nsc, "%s", xpath) != NULL){
if ((ret = netconf_trymerge(x, yspec, xret)) < 0) if ((ret = netconf_trymerge(x, yspec, xret)) < 0)

View file

@ -613,7 +613,7 @@ cli_show_common(clixon_handle h,
) < 0) ) < 0)
goto done; goto done;
/* Remove empty containers */ /* Remove empty containers */
if (xml_defaults_nopresence(xt, 2) < 0) if (xml_default_nopresence(xt, 2, 0) < 0)
goto done; goto done;
} }
if (fromroot) if (fromroot)

View file

@ -763,7 +763,7 @@ restconf_config_init(clixon_handle h,
goto done; goto done;
} }
/* Apply default values (removed in clear function) */ /* Apply default values (removed in clear function) */
if (xml_default_recurse(xrestconf, 0) < 0) if (xml_default_recurse(xrestconf, 0, 0) < 0)
goto done; goto done;
if ((x = xpath_first(xrestconf, nsc, "enable")) != NULL && if ((x = xpath_first(xrestconf, nsc, "enable")) != NULL &&
(enable = xml_body(x)) != NULL){ (enable = xml_body(x)) != NULL){

View file

@ -66,9 +66,7 @@ int xmldb_delete(clixon_handle h, const char *db);
int xmldb_create(clixon_handle h, const char *db); int xmldb_create(clixon_handle h, const char *db);
/* utility functions */ /* utility functions */
int xmldb_db_reset(clixon_handle h, const char *db); int xmldb_db_reset(clixon_handle h, const char *db);
cxobj *xmldb_cache_get(clixon_handle h, const char *db); cxobj *xmldb_cache_get(clixon_handle h, const char *db);
int xmldb_modified_get(clixon_handle h, const char *db); int xmldb_modified_get(clixon_handle h, const char *db);
int xmldb_modified_set(clixon_handle h, const char *db, int value); int xmldb_modified_set(clixon_handle h, const char *db, int value);
int xmldb_empty_get(clixon_handle h, const char *db); int xmldb_empty_get(clixon_handle h, const char *db);

View file

@ -49,10 +49,9 @@ typedef enum yang_class yang_class;
/* /*
* Prototypes * Prototypes
*/ */
int xml_default_recurse(cxobj *xn, int state); int xml_default_recurse(cxobj *xn, int state, int flag);
int xml_default_recurse_flag(cxobj *xn, int state, int flag);
int xml_global_defaults(clixon_handle h, cxobj *xn, cvec *nsc, const char *xpath, yang_stmt *yspec, int state); int xml_global_defaults(clixon_handle h, cxobj *xn, cvec *nsc, const char *xpath, yang_stmt *yspec, int state);
int xml_defaults_nopresence(cxobj *xn, int purge); int xml_default_nopresence(cxobj *xn, int mode, int flag);
int xml_add_default_tag(cxobj *x, uint16_t flags); int xml_add_default_tag(cxobj *x, uint16_t flags);
int xml_flag_state_default_value(cxobj *x, uint16_t flag); int xml_flag_state_default_value(cxobj *x, uint16_t flag);
int xml_flag_default_value(cxobj *x, uint16_t flag); int xml_flag_default_value(cxobj *x, uint16_t flag);

View file

@ -713,7 +713,7 @@ xmldb_populate(clixon_handle h,
if (xml_global_defaults(h, x, NULL, "/", yspec, 0) < 0) if (xml_global_defaults(h, x, NULL, "/", yspec, 0) < 0)
goto done; goto done;
/* Add default recursive values */ /* Add default recursive values */
if (xml_default_recurse(x, 0) < 0) if (xml_default_recurse(x, 0, 0) < 0)
goto done; goto done;
} }
retval = ret; retval = ret;

View file

@ -729,7 +729,7 @@ xmldb_get_cache(clixon_handle h,
if (xml_global_defaults(h, x0t, nsc, xpath, yspec, 0) < 0) if (xml_global_defaults(h, x0t, nsc, xpath, yspec, 0) < 0)
goto done; goto done;
/* Add default recursive values */ /* Add default recursive values */
if (xml_default_recurse(x0t, 0) < 0) if (xml_default_recurse(x0t, 0, 0) < 0)
goto done; goto done;
} /* x0t == NULL */ } /* x0t == NULL */
else else
@ -893,7 +893,7 @@ xmldb_get0(clixon_handle h,
goto done; goto done;
if (ret == 0) if (ret == 0)
goto fail; goto fail;
if (xml_defaults_nopresence(x, 2) < 0) if (xml_default_nopresence(x, 2, 0) < 0)
goto done; goto done;
*xret = x; *xret = x;
x = NULL; x = NULL;

View file

@ -517,7 +517,7 @@ text_modify(clixon_handle h,
goto fail; goto fail;
if (createstr != NULL && if (createstr != NULL &&
(op == OP_REPLACE || op == OP_MERGE || op == OP_CREATE)){ (op == OP_REPLACE || op == OP_MERGE || op == OP_CREATE)){
if (x0 == NULL || xml_defaults_nopresence(x0, 0)){ /* does not exist or is default */ if (x0 == NULL || xml_default_nopresence(x0, 0, 0)){ /* does not exist or is default */
if (strcmp(createstr, "false")==0){ if (strcmp(createstr, "false")==0){
/* RFC 8040 4.6 PATCH: /* RFC 8040 4.6 PATCH:
* If the target resource instance does not exist, the server MUST NOT create it. * If the target resource instance does not exist, the server MUST NOT create it.
@ -774,7 +774,7 @@ text_modify(clixon_handle h,
switch(op){ switch(op){
case OP_CREATE: case OP_CREATE:
if (x0 && xml_flag(x0, XML_FLAG_DEFAULT)==0){ if (x0 && xml_flag(x0, XML_FLAG_DEFAULT)==0){
if (xml_defaults_nopresence(x0, 0) == 0){ if (xml_default_nopresence(x0, 0, 0) == 0){
if (netconf_data_exists(cbret, "Data already exists; cannot create new resource") < 0) if (netconf_data_exists(cbret, "Data already exists; cannot create new resource") < 0)
goto done; goto done;
goto fail; goto fail;
@ -1267,15 +1267,6 @@ xmldb_put(clixon_handle h,
xml_name(x0), DATASTORE_TOP_SYMBOL); xml_name(x0), DATASTORE_TOP_SYMBOL);
goto done; goto done;
} }
/* XXX Ad-hoc:
* In yang mounts yang specs may not be available
* in initial parsing, but may be at a later stage.
* But it should be possible to find a more precise triggering
*/
if (clicon_option_bool(h, "CLICON_YANG_SCHEMA_MOUNT")){
if ((ret = xml_bind_yang(h, x0, YB_MODULE, yspec, NULL)) < 0)
goto done;
}
/* Here x0 looks like: <config>...</config> */ /* Here x0 looks like: <config>...</config> */
xnacm = clicon_nacm_cache(h); xnacm = clicon_nacm_cache(h);
permit = (xnacm==NULL); permit = (xnacm==NULL);
@ -1302,16 +1293,15 @@ xmldb_put(clixon_handle h,
if (xml_apply(x0, CX_ELMNT, xml_mark_added_ancestors, (void*)(XML_FLAG_ADD|XML_FLAG_DEL)) < 0) if (xml_apply(x0, CX_ELMNT, xml_mark_added_ancestors, (void*)(XML_FLAG_ADD|XML_FLAG_DEL)) < 0)
goto done; goto done;
/* Remove empty non-presence containers recursively. /* Remove empty non-presence containers recursively.
* XXX should use xml_Mark_added_ancestors algorithm that xml_default_recurse uses for only
*/ */
if (xml_defaults_nopresence(x0, 3) < 0) if (xml_default_nopresence(x0, 3, XML_FLAG_ADD|XML_FLAG_DEL) < 0)
goto done; goto done;
/* Complete defaults in incoming x1 /* Complete defaults in incoming x1
*/ */
if (xml_global_defaults(h, x0, nsc, "/", yspec, 0) < 0) if (xml_global_defaults(h, x0, nsc, "/", yspec, 0) < 0)
goto done; goto done;
/* Add default recursive values */ /* Add default recursive values */
if (xml_default_recurse_flag(x0, 0, XML_FLAG_ADD|XML_FLAG_DEL) < 0) if (xml_default_recurse(x0, 0, XML_FLAG_ADD|XML_FLAG_DEL) < 0)
goto done; goto done;
/* Clear flags from previous steps */ /* Clear flags from previous steps */
if (xml_apply(x0, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset, if (xml_apply(x0, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,

View file

@ -450,7 +450,7 @@ parse_configfile(clixon_handle h,
} }
} }
} }
if (xml_default_recurse(xt, 0) < 0) if (xml_default_recurse(xt, 0, 0) < 0)
goto done; goto done;
if ((ret = xml_yang_validate_add(h, xt, &xerr)) < 0) if ((ret = xml_yang_validate_add(h, xt, &xerr)) < 0)
goto done; goto done;

View file

@ -408,7 +408,7 @@ xml_yang_validate_rpc(clixon_handle h,
goto done; /* error or validation fail */ goto done; /* error or validation fail */
if (ret == 0) if (ret == 0)
goto fail; goto fail;
if (expanddefault && xml_default_recurse(xn, 0) < 0) if (expanddefault && xml_default_recurse(xn, 0, 0) < 0)
goto done; goto done;
} }
// ok: /* pass validation */ // ok: /* pass validation */
@ -469,7 +469,7 @@ xml_yang_validate_rpc_reply(clixon_handle h,
goto done; /* error or validation fail */ goto done; /* error or validation fail */
if (ret == 0) if (ret == 0)
goto fail; goto fail;
if (xml_default_recurse(xn, 0) < 0) if (xml_default_recurse(xn, 0, 0) < 0)
goto done; goto done;
} }
// ok: /* pass validation */ // ok: /* pass validation */

View file

@ -1051,7 +1051,6 @@ xml_child_append(cxobj *xp,
* @param[in] pos Position * @param[in] pos Position
* @retval 0 OK * @retval 0 OK
* @retval -1 Error * @retval -1 Error
* @see xml_child_append * @see xml_child_append
* @note does not do anything with child, you may need to set its parent, etc * @note does not do anything with child, you may need to set its parent, etc
*/ */

View file

@ -388,21 +388,6 @@ xml_default(yang_stmt *yt,
return retval; return retval;
} }
/*! Recursively fill in default values in an XML tree
*
* @param[in] xt XML tree
* @param[in] state If set expand defaults also for state data, otherwise only config
* @retval 0 OK
* @retval -1 Error
* @see xml_global_defaults
*/
int
xml_default_recurse(cxobj *xn,
int state)
{
return xml_default_recurse_flag(xn, state, 0x0);
}
/*! Selectively recursively fill in default values in an XML tree using flags /*! Selectively recursively fill in default values in an XML tree using flags
* *
* Skip nodes that are not either CHANGE or "flag" (typically ADD|DEL) * Skip nodes that are not either CHANGE or "flag" (typically ADD|DEL)
@ -416,9 +401,9 @@ xml_default_recurse(cxobj *xn,
* @see xml_default_recurse * @see xml_default_recurse
*/ */
int int
xml_default_recurse_flag(cxobj *xn, xml_default_recurse(cxobj *xn,
int state, int state,
int flag) int flag)
{ {
int retval = -1; int retval = -1;
yang_stmt *yn; yang_stmt *yn;
@ -444,7 +429,7 @@ xml_default_recurse_flag(cxobj *xn,
if (!state && !yang_config(y)) if (!state && !yang_config(y))
continue; continue;
} }
if (xml_default_recurse_flag(x, state, flag) < 0) if (xml_default_recurse(x, state, flag) < 0)
goto done; goto done;
} }
skip: skip:
@ -567,20 +552,23 @@ xml_global_defaults(clixon_handle h,
/*! Recursively find empty nopresence containers and default leaves, optionally purge /*! Recursively find empty nopresence containers and default leaves, optionally purge
* *
* Semantics of mode parameter somewhat complex
* @param[in] xn XML tree * @param[in] xn XML tree
* @param[in] purge 0: Dont remove any nodes * @param[in] mode 0: Dont remove any nodes
* 1: Remove config sub-nodes that are empty non-presence container or default leaf * 1: Remove config sub-nodes that are empty non-presence container or default leaf
* 2: Remove all sub-nodes that are empty non-presence container or default leaf * 2: Remove all sub-nodes that are empty non-presence container or default leaf
* 3: Remove all sub-nodes that are empty non-presence containers * 3: Remove all sub-nodes that are empty non-presence containers
* @param[in] flag If set only traverse nodes marked with flag (or CHANGE)
* @retval 1 Node is an (recursive) empty non-presence container or default leaf * @retval 1 Node is an (recursive) empty non-presence container or default leaf
* @retval 0 Other node * @retval 0 Other node
* @retval -1 Error * @retval -1 Error
* @note xn is not itself removed if purge * @note xn is not itself removed if mode
* @note for purge=1 are removed only if config or no yang spec(!) * @note for mode=1 are removed only if config or no yang spec(!)
*/ */
int int
xml_defaults_nopresence(cxobj *xn, xml_default_nopresence(cxobj *xn,
int purge) int mode,
int flag)
{ {
int retval = -1; int retval = -1;
cxobj *x; cxobj *x;
@ -592,6 +580,17 @@ xml_defaults_nopresence(cxobj *xn,
enum rfc_6020 keyw; enum rfc_6020 keyw;
int config = 1; int config = 1;
if (flag){
if (xml_flag(xn, XML_FLAG_CHANGE) != 0)
; /* continue */
else if (xml_flag(xn, flag) != 0){
flag = 0x0; /* Pass all */
}
else{
retval = 0;
goto done;
}
}
if ((yn = xml_spec(xn)) != NULL){ if ((yn = xml_spec(xn)) != NULL){
keyw = yang_keyword_get(yn); keyw = yang_keyword_get(yn);
if (keyw == Y_CONTAINER && if (keyw == Y_CONTAINER &&
@ -599,7 +598,7 @@ xml_defaults_nopresence(cxobj *xn,
rmx = 1; rmx = 1;
else if (keyw == Y_LEAF && else if (keyw == Y_LEAF &&
xml_flag(xn, XML_FLAG_DEFAULT) && xml_flag(xn, XML_FLAG_DEFAULT) &&
purge != 3) mode != 3)
rmx = 1; rmx = 1;
config = yang_config_ancestor(yn); config = yang_config_ancestor(yn);
} }
@ -608,10 +607,10 @@ xml_defaults_nopresence(cxobj *xn,
xprev = NULL; xprev = NULL;
while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) { while ((x = xml_child_each(xn, x, CX_ELMNT)) != NULL) {
/* 1: node is empty non-presence or default leaf (eg rmx) */ /* 1: node is empty non-presence or default leaf (eg rmx) */
if ((ret = xml_defaults_nopresence(x, purge)) < 0) if ((ret = xml_default_nopresence(x, mode, flag)) < 0)
goto done; goto done;
if (ret == 1){ if (ret == 1){
switch (purge){ switch (mode){
case 1: /* config nodes only */ case 1: /* config nodes only */
if (!config) if (!config)
break; break;

View file

@ -119,7 +119,7 @@ xml2output_wdef(cxobj *x,
switch (wdef){ switch (wdef){
case WITHDEFAULTS_EXPLICIT: case WITHDEFAULTS_EXPLICIT:
case WITHDEFAULTS_TRIM: case WITHDEFAULTS_TRIM:
/* inline of xml_defaults_nopresence() /* inline of xml_default_nopresence()
and xml_flag_state_default_value() and xml_flag_state_default_value()
*/ */
switch(yang_keyword_get(y)){ switch(yang_keyword_get(y)){