public void NotifyOfPrepared(Guid transactionId, DateTime timeStamp, TransactionalStatus status) { var pos = commitQueue.Find(transactionId, timeStamp); if (pos != -1) { var localEntry = commitQueue[pos]; if (localEntry.Role != CommitRole.LocalCommit) { logger.Error(666, $"transaction abort due to internal error in {nameof(NotifyOfPrepared)}: Wrong commit type"); throw new InvalidOperationException($"Wrong commit type: {localEntry.Role}"); } if (status == TransactionalStatus.Ok) { localEntry.WaitCount--; storageWorker.Notify(); } else { AbortCommits(status, pos); this.RWLock.Notify(); } } else { // this message has arrived ahead of the commit request - we need to remember it if (this.unprocessedPreparedMessages == null) { this.unprocessedPreparedMessages = new Dictionary <DateTime, PMessages>(); } PMessages info; if (!this.unprocessedPreparedMessages.TryGetValue(timeStamp, out info)) { this.unprocessedPreparedMessages[timeStamp] = info = new PMessages(); } if (status == TransactionalStatus.Ok) { info.Count++; } else { info.Status = status; } // TODO fix memory leak if corresponding commit messages never arrive } }
public async Task NotifyOfPrepared(Guid transactionId, DateTime timeStamp, TransactionalStatus status) { var pos = commitQueue.Find(transactionId, timeStamp); if (logger.IsEnabled(LogLevel.Trace)) { logger.LogTrace("NotifyOfPrepared - TransactionId:{TransactionId} Timestamp:{Timestamp}, TransactionalStatus{TransactionalStatus}", transactionId, timeStamp, status); } if (pos != -1) { var localEntry = commitQueue[pos]; if (localEntry.Role != CommitRole.LocalCommit) { logger.LogError($"Transaction abort due to internal error in {nameof(NotifyOfPrepared)}: Wrong commit type"); throw new InvalidOperationException($"Wrong commit type: {localEntry.Role}"); } if (status == TransactionalStatus.Ok) { localEntry.WaitCount--; storageWorker.Notify(); } else { await AbortCommits(status, pos); this.RWLock.Notify(); } } else { // this message has arrived ahead of the commit request - we need to remember it if (!this.unprocessedPreparedMessages.TryGetValue(timeStamp, out PreparedMessages info)) { this.unprocessedPreparedMessages[timeStamp] = info = new PreparedMessages(status); } if (status == TransactionalStatus.Ok) { info.Count++; } else { info.Status = status; } // TODO fix memory leak if corresponding commit messages never arrive } }