Clixon config option CLICON_XMLDB_CACHE renamed to CLICON_DATASTORE_CACHE and changed type from boolean to datastore_cache

This commit is contained in:
Olof hagsand 2019-05-09 14:25:16 +02:00
parent 70221742f7
commit 99b7a1fe5b
13 changed files with 207 additions and 150 deletions

View file

@ -336,7 +336,10 @@ from_client_get_config(clicon_handle h,
if ((xfilter = xml_find(xe, "filter")) != NULL)
if ((xpath = xml_find_value(xfilter, "select"))==NULL)
xpath="/";
if (xmldb_get(h, db, xpath, &xret, NULL) < 0){
/* Note xret can be pruned by nacm below (and change name),
* so zero-copy cant be used
*/
if (xmldb_get(h, db, xpath, 1, &xret, NULL) < 0){
if (netconf_operation_failed(cbret, "application", "read registry")< 0)
goto done;
goto ok;
@ -800,14 +803,16 @@ from_client_get(clicon_handle h,
if ((xfilter = xml_find(xe, "filter")) != NULL)
if ((xpath = xml_find_value(xfilter, "select"))==NULL)
xpath="/";
/* Get config */
if (xmldb_get(h, "running", xpath, &xret, NULL) < 0){
/* Get config
* Note xret can be pruned by nacm below and change name and
* metrged with state data, so zero-copy cant be used
*/
if (xmldb_get(h, "running", xpath, 1, &xret, NULL) < 0){
if (netconf_operation_failed(cbret, "application", "read registry")< 0)
goto done;
goto ok;
}
/* Get state data from plugins as defined by plugin_statedata(), if any */
assert(xret);
clicon_err_reset();
if ((ret = client_statedata(h, xpath, &xret)) < 0)
goto done;

View file

@ -182,7 +182,7 @@ startup_common(clicon_handle h,
if ((msd = modstate_diff_new()) == NULL)
goto done;
clicon_debug(1, "Reading startup config from %s", db);
if (xmldb_get1(h, db, "/", &xt, msd) < 0)
if (xmldb_get(h, db, "/", 0, &xt, msd) < 0)
goto done;
/* Clear flags xpath for get */
xml_apply0(xt, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
@ -276,7 +276,7 @@ startup_validate(clicon_handle h,
if (ret == 0)
goto fail;
/* Clear cached trees from default values and marking */
if (xmldb_get1_clear(h, db) < 0)
if (xmldb_get_clear(h, td->td_target) < 0)
goto done;
if (xtr){
*xtr = td->td_target;
@ -285,11 +285,7 @@ startup_validate(clicon_handle h,
retval = 1;
done:
if (td){
if (clicon_option_bool(h, "CLICON_XMLDB_CACHE")){
/* xmldb_get1 requires free only if not cache */
td->td_target = NULL;
td->td_src = NULL;
}
xmldb_get_free(h, &td->td_target);
transaction_free(td);
}
return retval;
@ -332,7 +328,7 @@ startup_commit(clicon_handle h,
if (plugin_transaction_commit(h, td) < 0)
goto done;
/* Clear cached trees from default values and marking */
if (xmldb_get1_clear(h, db) < 0)
if (xmldb_get_clear(h, td->td_target) < 0)
goto done;
/* [Delete and] create running db */
@ -356,11 +352,7 @@ startup_commit(clicon_handle h,
retval = 1;
done:
if (td){
if (clicon_option_bool(h, "CLICON_XMLDB_CACHE")){
/* xmldb_get1 requires free only if not cache */
td->td_target = NULL;
td->td_src = NULL;
}
xmldb_get_free(h, &td->td_target);
transaction_free(td);
}
return retval;
@ -398,7 +390,7 @@ from_validate_common(clicon_handle h,
goto done;
}
/* This is the state we are going to */
if (xmldb_get1(h, candidate, "/", &td->td_target, NULL) < 0)
if (xmldb_get(h, candidate, "/", 0, &td->td_target, NULL) < 0)
goto done;
/* Clear flags xpath for get */
@ -416,7 +408,7 @@ from_validate_common(clicon_handle h,
/* 2. Parse xml trees
* This is the state we are going from */
if (xmldb_get1(h, "running", "/", &td->td_src, NULL) < 0)
if (xmldb_get(h, "running", "/", 0, &td->td_src, NULL) < 0)
goto done;
/* Clear flags xpath for get */
xml_apply0(td->td_src, CX_ELMNT, (xml_applyfn_t*)xml_flag_reset,
@ -521,9 +513,9 @@ candidate_commit(clicon_handle h,
goto done;
/* Clear cached trees from default values and marking */
if (xmldb_get1_clear(h, candidate) < 0)
if (xmldb_get_clear(h, td->td_target) < 0)
goto done;
if (xmldb_get1_clear(h, "running") < 0)
if (xmldb_get_clear(h, td->td_src) < 0)
goto done;
/* Optionally write (potentially modified) tree back to candidate
@ -559,11 +551,8 @@ candidate_commit(clicon_handle h,
if (retval < 1 && td)
plugin_transaction_abort(h, td);
if (td){
if (clicon_option_bool(h, "CLICON_XMLDB_CACHE")){
/* xmldb_get1 requires free only if not cache */
td->td_target = NULL;
td->td_src = NULL;
}
xmldb_get_free(h, &td->td_target);
xmldb_get_free(h, &td->td_src);
transaction_free(td);
}
return retval;
@ -749,9 +738,9 @@ from_client_validate(clicon_handle h,
goto ok;
}
/* Clear cached trees from default values and marking */
if (xmldb_get1_clear(h, db) < 0)
if (xmldb_get_clear(h, td->td_target) < 0)
goto done;
if (xmldb_get1_clear(h, "running") < 0)
if (xmldb_get_clear(h, td->td_src) < 0)
goto done;
/* Optionally write (potentially modified) tree back to candidate */
@ -768,12 +757,9 @@ from_client_validate(clicon_handle h,
if (retval < 0 && td)
plugin_transaction_abort(h, td);
if (td){
if (clicon_option_bool(h, "CLICON_XMLDB_CACHE")){
/* xmldb_get1 requires free only if not cache */
td->td_target = NULL;
td->td_src = NULL;
}
transaction_free(td);
xmldb_get_free(h, &td->td_target);
xmldb_get_free(h, &td->td_src);
transaction_free(td);
}
return retval;
} /* from_client_validate */

View file

@ -102,13 +102,12 @@ db_merge(clicon_handle h,
cxobj *xt = NULL;
/* Get data as xml from db1 */
if (xmldb_get(h, (char*)db1, NULL, &xt, NULL) < 0)
if (xmldb_get(h, (char*)db1, NULL, 0, &xt, NULL) < 0)
goto done;
/* Merge xml into db2. Without commit */
retval = xmldb_put(h, (char*)db2, OP_MERGE, xt, clicon_username_get(h), cbret);
done:
if (xt)
xml_free(xt);
xmldb_get_free(h, &xt);
return retval;
}
@ -270,8 +269,7 @@ startup_extraxml(clicon_handle h,
ok:
retval = 1;
done:
if (xt && !clicon_option_bool(h, "CLICON_XMLDB_CACHE"))
xml_free(xt);
xmldb_get_free(h, &xt);
if (xmldb_delete(h, db) != 0 && errno != ENOENT)
return -1;
return retval;