|
How to handle distributed transactions
My following question is not specific to Ice, but concerns a general issue in distributed computing.
For our DMS we need transactions which write files to a fileserver and simultaneously the corresponding metadata to a database. The file upload is handled by an interface CFileUpload(). This interface first writes the file to a temporary location on the file server, so that it can easily be removed in case of a failure.
CFileUpload::commit() transfers the file to the persistent area on the file server and writes the metadata into the database. It can however not commit the database transaction as within that same transaction other database operations are executed via other interfaces to create other objects which may be associated with the file. For the client, the whole shebang must look like one transaction - either all the database objects and all uploaded files are committet or nothing of all. But how to hook this together?
I suggested to proceed like this:
---------------
class CDMSSessionI : virtual public CDMSSession {
...
CFileUploadSequence openFileUploads;
CDatabaseSession* dbSession;
void registerFileUpload(CFileUploadPtr pFileUPload) {
openFileUploads.push_back(pFileUpload);
}
void commit() {
foreach pFileUpload in openFileUploads { // Pseudocode
pFileUpload->commit();
}
dbSession->commit();
}
...
};
...
CFileUploadI::CFileUploadI(Ice::Current& current) {
CDMSSessionI* pSess = getDMSSessionFromCurrent(current);
pSess->registerFileUpload(this);
}
-----------------
So CFileUpload registers itself at the DMS Session which it uses to enable that DMS Session to commit all relevant file uploads within it's commit() method.
Our project team is not sure if this is the best approach as for simplicity, elegance and encapsulation. Can you comment on it? Should you have a better idea, it would be welcome, of course!
And by the way, can you give us an estimated target date for the release of Ice 1.6?
Thanks! Robert.
|