CDB Session - Why we need two lock levels

Hi Everyone,

We are using CDB Session to save the operational Data in CDB. So, here to start the CDB Session we have used the locks to avoid any data discrepancy and also, while saving the data to CDB we have used setValues() from CdbSession class.

**Starting the CDB Session **

CdbSession cdbSessionObject = cdb.startSession(CdbDBType.CDB_OPERATIONAL, EnumSet.of(CdbLockType.LOCK_REQUEST,CdbLockType.LOCK_PARTIAL,CdbLockType.LOCK_WAIT));

Save Method

public synchronized void setValues(ConfXMLParam[] params, ConfPath path)

So, here our ask is why there is locking at two levels - one we are achieving with Locks while starting the cdb session and second with the synchronized setValues method. Can you please elaborate this.

Hi,

Two different mechanisms.

  1. A synchronized method is a way to, for example, avoid that you send requests on the same shared socket from multiple threads and receive a reply that was intended for another thread. For more details, see for example: Synchronized Methods (The Java™ Tutorials > Essential Java Classes > Concurrency)

  2. cdb.startSession on the operational data store together with LOCK_REQUEST is a write lock intended to prevent another CDB/MAAPI client from changing the data that you are writing to. If you, for example, are calling setValues() multiple times and do not want some other client to change the data in-between your setValues() calls, and/or if you want an operational data subscriber to receive a subscription notification.
    See ConfD UG “CDB subscriptions” from “Subscriptions towards the operational data…”

I suggest you begin with describing what you are trying to do and need a solution for instead of a perceived issue with the Java CDB API.

Hi,

We are using Maapi Session in our current implementation but as per the confD team recommendation, CDB Session will have a better time improvement over the Maapi session for operational Data.

Now, we are working on the same to replace the Maapi with CDB Session but as such no improvement seen moving from Maapi to CDB Session for Operational Data.

So, our thought process was like may be due to synchronized we are not getting that expected time improvement with the CDB session.

Is this the correct expectation that we will have better time improvement with the CDB session over the Maapi for Operational Data?

See my reply here: CDB Session - Unable to Fetch the Existing Element - #4 by cohult