public void JoinTransaction()
            {
                TransactionInfo info = TransactionContext.GetRequiredTransactionInfo <TransactionInfo>();

                logger.Info($"Grain {grain} is joining transaction {info.TransactionId}.");

                // are we already part of the transaction?
                if (this.transactions.Contains(info.TransactionId))
                {
                    return;
                }

                TransactionalResourceVersion readVersion;

                if (!TryGetVersion(info.TransactionId, out readVersion))
                {
                    throw new OrleansTransactionVersionDeletedException(info.TransactionId.ToString());
                }

                if (info.IsReadOnly && readVersion.TransactionId > this.stableVersion)
                {
                    throw new OrleansTransactionUnstableVersionException(info.TransactionId.ToString());
                }

                info.RecordRead(transactionalResource, readVersion, this.stableVersion);

                writeLowerBound = Math.Max(writeLowerBound, info.TransactionId - 1);

                if (this.version.TransactionId > info.TransactionId || this.writeLowerBound >= info.TransactionId)
                {
                    throw new OrleansTransactionWaitDieException(info.TransactionId.ToString());
                }

                TransactionalResourceVersion nextVersion = TransactionalResourceVersion.Create(info.TransactionId,
                                                                                               this.version.TransactionId == info.TransactionId ? this.version.WriteNumber + 1 : 1);

                info.RecordWrite(transactionalResource, this.version, this.stableVersion);

                this.version = nextVersion;

                this.transactions.Remove(info.TransactionId);
            }
 private bool TryGetVersion(long transactionId, out TransactionalResourceVersion readVersion)
 {
     readVersion = this.version;
     return(this.version.TransactionId <= transactionId);
 }