Hi,
I have a multi-threaded confd application with separate threads for
- subscription
- control
- Separate worker thread for Notification, Action and operational data
I am running into cdb_start_session errors while trying to do the following operations in parallel
- Get operation on operational data thread
- Edit-config operation on subscription thread.
As per the recommendation in the start up guide, i am using the following API for cdb_start_session with mutl-threading
cdb_read_any_session() API:
bool started = false;
int status = CONFD_OK;
while (!started) {
/* Retry to create a new CDB read session if there are some write
* transaction occurring in parallel */
if ((status = cdb_start_session(sock, type)) != CONFD_OK) {
if (confd_errno != CONFD_ERR_LOCKED) {
LogMsg("Failed to start cbd session with confd errno %s",
confd_strerror(confd_errno));
return status;
} else {
sleep(1);
}
} else {
started = true;
}
}
Get operation in operational data thread- does set_namespace:
if ((status = cdb_read_any_session(datasock,
CDB_RUNNING)) != CONFD_OK)
{
return status;
}
cdb_set_namespace(datasock, ona100__ns);
edit-config in Subscription thread:
if ((status = cdb_read_subscription_socket(subsock,
sub_points,
&reslen)) != CONFD_OK)
{
LogMsg("terminate sub_read: %d", status);
goto ctl_thr_cleanup;
}
if (reslen > 0)
{
if ((status = cdb_start_read_any_session(datasock,
CDB_RUNNING)) != CONFD_OK)
{
LogMsg("Cannot start datasock session");
goto ctl_thr_cleanup;
}
if ((status = cdb_set_namespace(datasock, ona100__ns)) != CONFD_OK)
{
LogMsg("Cannot set namespace");
goto ctl_thr_cleanup;
}
Error Log
I have seen two different error codes, 18 and 21.
cdb_read_any_session(): Failed to start cbd session with confd errno 21 (Bad protocol usage or unexpected retval), status -1.
cdb_read_any_session(): Failed to start cbd session with confd errno 18 (internal error), status -1.
Can you please help me to understand what is error means and why I would run into this? Is there any problem with the usage of cdb_read_any_session() API.
I see it is suggested to use cdb_start_session2(CDB_LOCK_SESSION | CDB_LOCK_WAIT) as an alternate for cdb_start_session with a loop, but i do not understand if there any implementation difference with that.
Appreciate some help on this.
- Kapil