Within the same client application process (or the same thread), there is only one set of transaction callbacks that can be registered with a given daemon context and they will be shared by all your data provider callpoints that are registered with the same daemon context.
If you would like to have different transaction callbacks for each of your data provider callpoints, you will need to write separate applications (or multiple threads) for each of them.
This is my tcb
Transaction callback needed by confd
def __init__(self, workersocket,maapisocket):
self._workersocket = workersocket
self._maapisocket = maapisocket
print(" TRANS CALLBACK CLASS INSTANCE CREATED")
def cb_init(self, tctx):
maapi.attach(self._maapisocket, 0, tctx)
print(" TRANS CALLBACK INIT DONE")
print("Transaction handle is %s" %(tctx.th))
def cb_finish(self, tctx):
print(" TRANS CALLBACK DONE")
def cb_abort(self, tctx):
print "Transaction is being aborted"
def cb_commit(self, tctx):
print "Transaction is being committed"
So all the above print statements are getting printed for any transaction that happed. The data callbacks are invoked correctly.
So do the tcb methods get invoked for any transaction, or is it a bug in my code ?
Yes, all of the transaction callbacks for configuration data will always be invoked for all transactions. This isn’t a bug in your code.
The intention with the transaction callback is that it allows you to orchestrate transactions with multiple sources of data (external data i.e not CDB), ConfD implements a two-phase commit protocol towards all data sources that participate in a transaction. Thus so you have the possibility e.g from a prepare callback abort the transaction.