List pagination locking for state-data changes
Changed semantics of locking: instead of relying of locking running-db, an automatic lock bound to a session is maintained. When the session closes the lock is released.
This commit is contained in:
parent
197fc16e69
commit
eea6d549f6
5 changed files with 25 additions and 19 deletions
|
|
@ -592,11 +592,16 @@ get_list_pagination(clicon_handle h,
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else {/* Check if running locked (by this session) */
|
else {/* Check if running locked (by this session) */
|
||||||
if ((iddb = xmldb_islocked(h, "running")) != 0 &&
|
if ((iddb = xmldb_islocked(h, PAGINATE_STATE_LOCK)) != 0){
|
||||||
iddb == ce->ce_id)
|
if (iddb == ce->ce_id)
|
||||||
|
locked = 1;
|
||||||
|
else
|
||||||
|
locked = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
xmldb_lock(h, PAGINATE_STATE_LOCK, ce->ce_id);
|
||||||
locked = 1;
|
locked = 1;
|
||||||
else
|
}
|
||||||
locked = 0;
|
|
||||||
if ((ret = clixon_pagination_cb_call(h, xpath, locked,
|
if ((ret = clixon_pagination_cb_call(h, xpath, locked,
|
||||||
offset, limit,
|
offset, limit,
|
||||||
xret)) < 0)
|
xret)) < 0)
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,11 @@
|
||||||
#ifndef _CLIXON_BACKEND_PLUGIN_H_
|
#ifndef _CLIXON_BACKEND_PLUGIN_H_
|
||||||
#define _CLIXON_BACKEND_PLUGIN_H_
|
#define _CLIXON_BACKEND_PLUGIN_H_
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Constants
|
||||||
|
*/
|
||||||
|
#define PAGINATE_STATE_LOCK "paginate-state-lock"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Types
|
* Types
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -309,15 +309,16 @@ pagination_limit(pagination_data pd)
|
||||||
return ((pagination_data_t *)pd)->pd_limit;
|
return ((pagination_data_t *)pd)->pd_limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Get pagination data: locked parameter
|
/*! Get pagination data: locked parameter for state data
|
||||||
*
|
*
|
||||||
* Pagination can use a lock/transaction mechanism
|
* A "paginate" lock is set for a specific session when list-pagination is in progress.
|
||||||
* If locking is not used, the plugin cannot expect more pagination calls, and no state or
|
* If locking is set, the pagination is part of a session transaction and the plugin may
|
||||||
* caching should be used
|
* cache state (such as a cache) and can expect more pagination calls until the "paginate"
|
||||||
* If locking is used, the pagination is part of a session transaction and the plugin may cache
|
* db-lock is released.
|
||||||
* state (such as a cache) and can expect more pagination calls until the running db-lock is
|
*
|
||||||
* released, (see ca_lockdb)
|
* If you want to do the same for config data, it is recommended to use lock-db on
|
||||||
* The transaction is the regular lock/unlock db of running-db of a specific session.
|
* the appropriate database, but this risks of indefinite blocking, as long as the
|
||||||
|
* session endures.
|
||||||
* @param[in] pd Pagination userdata
|
* @param[in] pd Pagination userdata
|
||||||
* @retval locked 0: unlocked/stateless 1: locked by this caller
|
* @retval locked 0: unlocked/stateless 1: locked by this caller
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -919,7 +919,6 @@ cli_pagination(clicon_handle h,
|
||||||
uint32_t limit = 0;
|
uint32_t limit = 0;
|
||||||
cxobj **xvec = NULL;
|
cxobj **xvec = NULL;
|
||||||
size_t xlen;
|
size_t xlen;
|
||||||
int locked = 0;
|
|
||||||
|
|
||||||
if (cvec_len(argv) != 5){
|
if (cvec_len(argv) != 5){
|
||||||
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
|
clicon_err(OE_PLUGIN, 0, "Expected usage: <xpath> <prefix> <namespace> <format> <limit>");
|
||||||
|
|
@ -949,9 +948,6 @@ cli_pagination(clicon_handle h,
|
||||||
}
|
}
|
||||||
if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL)
|
if ((nsc = xml_nsctx_init(prefix, namespace)) == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
if (clicon_rpc_lock(h, "running") < 0)
|
|
||||||
goto done;
|
|
||||||
locked++;
|
|
||||||
for (i = 0;; i++){
|
for (i = 0;; i++){
|
||||||
if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc,
|
if (clicon_rpc_get_pageable_list(h, "running", xpath, nsc,
|
||||||
CONTENT_ALL,
|
CONTENT_ALL,
|
||||||
|
|
@ -1004,8 +1000,6 @@ cli_pagination(clicon_handle h,
|
||||||
} /* for i */
|
} /* for i */
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (locked)
|
|
||||||
clicon_rpc_unlock(h, "running");
|
|
||||||
if (xvec)
|
if (xvec)
|
||||||
free(xvec);
|
free(xvec);
|
||||||
if (xret)
|
if (xret)
|
||||||
|
|
|
||||||
|
|
@ -545,6 +545,7 @@ example_statefile(clicon_handle h,
|
||||||
* @param[in] xpath Registered XPath using canonical prefixes
|
* @param[in] xpath Registered XPath using canonical prefixes
|
||||||
* @param[in] userargs Per-call user arguments
|
* @param[in] userargs Per-call user arguments
|
||||||
* @param[in] arg Per-path user argument
|
* @param[in] arg Per-path user argument
|
||||||
|
* @see example_lockdb
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
example_pagination(void *h0,
|
example_pagination(void *h0,
|
||||||
|
|
@ -667,7 +668,7 @@ example_lockdb(clicon_handle h,
|
||||||
|
|
||||||
/* Part of cached pagination example
|
/* Part of cached pagination example
|
||||||
*/
|
*/
|
||||||
if (strcmp(db, "running") == 0 && lock == 0 &&
|
if (strcmp(db, PAGINATE_STATE_LOCK) == 0 && lock == 0 &&
|
||||||
_state && _state_file && _state_file_cached && _state_file_transaction){
|
_state && _state_file && _state_file_cached && _state_file_transaction){
|
||||||
if (_state_xml_cache){
|
if (_state_xml_cache){
|
||||||
xml_free(_state_xml_cache);
|
xml_free(_state_xml_cache);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue