public void InitializeDtcTxContext()
{
// initialize the logger with the current Resource Manager Id
RecoveryLogger.Initialize(ResourceManagerId);
KeyValuePair<XATransactionId, byte[]>[] localRecoverables = RecoveryLogger.GetRecoverables();
if (localRecoverables.Length == 0)
{
Tracer.Debug("Did not detect any open DTC transaction records on disk.");
// No local data so anything stored on the broker can't be recovered here.
return;
}
XATransactionId[] recoverables = TryRecoverBrokerTXIds();
if (recoverables.Length == 0)
{
Tracer.Debug("Did not detect any recoverable transactions at Broker.");
// Broker has no recoverable data so nothing to do here, delete the
// old recovery log as its stale.
RecoveryLogger.Purge();
return;
}
List<KeyValuePair<XATransactionId, byte[]>> matches = new List<KeyValuePair<XATransactionId, byte[]>>();
foreach(XATransactionId recoverable in recoverables)
{
foreach(KeyValuePair<XATransactionId, byte[]> entry in localRecoverables)
{
if(entry.Key.Equals(recoverable))
{
Tracer.DebugFormat("Found a matching TX on Broker to stored Id: {0} reenlisting.", entry.Key);
matches.Add(entry);
}
}
}
if (matches.Count != 0)
{
this.recoveryComplete = new CountDownLatch(matches.Count);
foreach (KeyValuePair<XATransactionId, byte[]> recoverable in matches)
{
this.transactionId = recoverable.Key;
Tracer.Info("Reenlisting recovered TX with Id: " + this.transactionId);
this.currentEnlistment =
TransactionManager.Reenlist(ResourceManagerGuid, recoverable.Value, this);
}
this.recoveryComplete.await();
Tracer.Debug("All Recovered TX enlistments Reports complete, Recovery Complete.");
TransactionManager.RecoveryComplete(ResourceManagerGuid);
return;
}
// The old recovery information doesn't match what's on the broker so we
// should discard it as its stale now.
RecoveryLogger.Purge();
}