My application has mulitple dps with its own transaction cb registered . I see tcbs are being invoked for all transactions .
I had put some print statement in init(), commit(), abort() in my tcb implementation, and it is getting printed even when the transactions are happening for other dps. It doesn’t cause any error.
so If there are 3 tcbs each registered as part of 3 dps. would all three of them get called everytime there is any transaction ?
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
class TransCbs(object):
‘’’
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):
try:
maapi.attach(self._maapisocket, 0, tctx)
dp.trans_set_fd(tctx, self._workersocket)
print(" TRANS CALLBACK INIT DONE")
print("Transaction handle is %s" %(tctx.th))
return _confd.CONFD_OK
except:
traceback.print_excl()
def cb_finish(self, tctx):
maapi.detach(self._maapisocket, tctx)
print(" TRANS CALLBACK DONE")
return _confd.CONFD_OK
def cb_abort(self, tctx):
print "Transaction is being aborted"
return _confd.CONFD_OK
def cb_commit(self, tctx):
print "Transaction is being committed"
return _confd.CONFD_OK
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.