Skip to content

Commit 3f74424

Browse files
irfanHaslandedmichalvasko
authored andcommitted
ds plugins OPTIMIZE pass req xpaths to load_cb
load_cb can be xpath aware for operational datastore, and fetch only the required data for the datastore plugins that support it. Implemented support: 1. redis DS plugin supports this for all datastores. 2. mongo ds plugin supports this except for operational datastore. - ietf-origin metadata must be explicitly retrieved for each path. - this is not implemented yet, so all data will be retrieved. 3. json ds plugin - unimplemented. ignores passed xpaths. This has the benefit of optimally loading only the requested data, and not constructing the entire module datatree, if only a small part is being read. Further, it can reduce the amount of time modules remain read locked, when they have large amount of data, and occasional readers of small data.
1 parent c4f4ccc commit 3f74424

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

src/modinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ sr_module_oper_data_load(struct sr_mod_info_mod_s *mod, sr_conn_ctx_t *conn, sr_
13761376
}
13771377
/* load push oper data for the session from the datastore plugin if cache was empty */
13781378
if (!mod_data && (err_info = sr_module_file_data_append(mod->ly_mod, mod->ds_handle, SR_DS_OPERATIONAL,
1379-
oper_push_dup[i].cid, oper_push_dup[i].sid, NULL, 0, &mod_data))) {
1379+
oper_push_dup[i].cid, oper_push_dup[i].sid, mod->xpaths, mod->xpath_count, &mod_data))) {
13801380
goto cleanup;
13811381
}
13821382
} else {

src/plugins/ds_mongo.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,13 +396,14 @@ srpds_get_access(mongoc_collection_t *module, char **owner, char **group, mode_t
396396
* @param[in] ctx Libyang context.
397397
* @param[in] xpaths Array of XPaths.
398398
* @param[in] xpath_cnt XPath count.
399+
* @param[in] oper_ds Flag if the filter is for loading operational data and special handling is needed.
399400
* @param[out] is_valid Whether the @p xpath_filter is valid.
400401
* @param[out] xpath_filter XPath filter for the database.
401402
* @return NULL on success;
402403
* @return Sysrepo error info on error.
403404
*/
404405
static sr_error_info_t *
405-
srpds_process_load_paths(struct ly_ctx *ctx, const char **xpaths, uint32_t xpath_cnt, int *is_valid, bson_t *xpath_filter)
406+
srpds_process_load_paths(struct ly_ctx *ctx, const char **xpaths, uint32_t xpath_cnt, int oper_ds, int *is_valid, bson_t *xpath_filter)
406407
{
407408
sr_error_info_t *err_info = NULL;
408409
uint32_t i;
@@ -416,6 +417,17 @@ srpds_process_load_paths(struct ly_ctx *ctx, const char **xpaths, uint32_t xpath
416417
bson_init(xpath_filter);
417418
bson_append_array_begin(xpath_filter, "$or", 3, &top);
418419

420+
if (oper_ds) {
421+
/*
422+
* TODO
423+
* xpath filtering is unimplemented for MONGO DS operational datastore.
424+
* /sysrepo:discard-items and metadata (ietf-origin) needs to be explicitly retrieved.
425+
*
426+
* So, just fetch all the data until then.
427+
*/
428+
goto cleanup;
429+
}
430+
419431
/* create new data node for lyd_find_path to work correctly */
420432
if (lyd_new_path(NULL, ctx, "/ietf-yang-library:yang-library", NULL, 0, &ctx_node) != LY_SUCCESS) {
421433
ERRINFO(&err_info, plugin_name, SR_ERR_LY, "lyd_new_path()", "");
@@ -3399,7 +3411,7 @@ srpds_mongo_load(const struct lys_module *mod, sr_datastore_t ds, sr_cid_t cid,
33993411
goto cleanup;
34003412
}
34013413

3402-
if ((err_info = srpds_process_load_paths(mod->ctx, xpaths, xpath_count, &is_valid, &xpath_filter))) {
3414+
if ((err_info = srpds_process_load_paths(mod->ctx, xpaths, xpath_count, (ds == SR_DS_OPERATIONAL), &is_valid, &xpath_filter))) {
34033415
goto cleanup;
34043416
}
34053417

src/plugins/ds_redis.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2641,12 +2641,13 @@ srpds_load_and_copy_data(redisContext *ctx, const char *mod_ns_src, const char *
26412641
* @param[in] ctx Libyang context.
26422642
* @param[in] xpaths Array of XPaths.
26432643
* @param[in] xpath_cnt XPath count.
2644+
* @param[in] oper_ds Flag if the filter is for loading operational data and special handling is needed.
26442645
* @param[out] xpath_filter Final query filter.
26452646
* @return NULL on success;
26462647
* @return Sysrepo error info on error.
26472648
*/
26482649
static sr_error_info_t *
2649-
srpds_process_load_paths(struct ly_ctx *ctx, const char **xpaths, uint32_t xpath_cnt, char **xpath_filter)
2650+
srpds_process_load_paths(struct ly_ctx *ctx, const char **xpaths, uint32_t xpath_cnt, int oper_ds, char **xpath_filter)
26502651
{
26512652
sr_error_info_t *err_info = NULL;
26522653
uint32_t i;
@@ -2740,6 +2741,19 @@ srpds_process_load_paths(struct ly_ctx *ctx, const char **xpaths, uint32_t xpath
27402741
path = NULL;
27412742
}
27422743

2744+
if (xpath_cnt && oper_ds) {
2745+
/* explicitly add discard-items to the query for operational datastore */
2746+
if ((err_info = srpds_escape_string(plugin_name, "/sysrepo:discard-items", &escaped_path))) {
2747+
goto cleanup;
2748+
}
2749+
if (asprintf(&tmp, "%s | %s*", *xpath_filter, escaped_path) == -1) {
2750+
ERRINFO(&err_info, plugin_name, SR_ERR_NO_MEMORY, "asprintf()", strerror(errno));
2751+
goto cleanup;
2752+
}
2753+
free(*xpath_filter);
2754+
*xpath_filter = tmp;
2755+
}
2756+
27432757
cleanup:
27442758
if (err_info) {
27452759
free(*xpath_filter);
@@ -3897,7 +3911,7 @@ srpds_redis_load(const struct lys_module *mod, sr_datastore_t ds, sr_cid_t cid,
38973911
goto cleanup;
38983912
}
38993913

3900-
if ((err_info = srpds_process_load_paths(mod->ctx, xpaths, xpath_count, &xpath_filter))) {
3914+
if ((err_info = srpds_process_load_paths(mod->ctx, xpaths, xpath_count, (ds == SR_DS_OPERATIONAL), &xpath_filter))) {
39013915
goto cleanup;
39023916
}
39033917

0 commit comments

Comments
 (0)