private async Task <bool> PersistCommit(long transactionId) { transactionId = Math.Max(this.highCommitTransactionId, transactionId); if (transactionId <= this.metadata.StableVersion.TransactionId) { // Transaction commit already persisted. return(true); } // find version related to this transaction LogRecord <TState> stableRecord = this.log.First(kvp => kvp.Key <= transactionId).Value; TransactionalResourceVersion stableversion = stableRecord.Version; TState stableState = stableRecord.NewVal; // Trim the logs to remove old versions. // Note that we try to keep the highest version that is below or equal to the ReadOnlyTransactionId // so that we can use it to serve read only transactions. long highestKey = transactionId; foreach (var key in this.log.Keys) { if (key > this.transactionAgent.ReadOnlyTransactionId) { break; } highestKey = key; } if (this.log.Count != 0) { List <KeyValuePair <long, LogRecord <TState> > > records = this.log.TakeWhile(kvp => kvp.Key < highestKey).ToList(); if (this.logger.IsEnabled(LogLevel.Debug)) { records.ForEach(kvp => this.logger.Debug("Removing committed transaction from log: transactionId: {1}", kvp.Key)); } records.ForEach(kvp => this.log.Remove(kvp.Key)); } Metadata newMetadata = new Metadata() { StableVersion = stableversion, HighestVersion = this.version, HighestReadTransactionId = this.highestReadTransactionId, }; this.eTag = await this.storage.Confirm(StateName, this.eTag, newMetadata.ToString(), stableversion.ToString()); this.metadata = newMetadata; this.commitedState = stableState; UpdateActiveState(); return(true); }
private async Task <bool> PersistCommit(long transactionId) { transactionId = Math.Max(this.highCommitTransactionId, transactionId); if (transactionId <= this.metadata.StableVersion.TransactionId) { // Transaction commit already persisted. return(true); } // find version related to this transaction TransactionalResourceVersion stableversion = this.log.First(kvp => kvp.Key <= transactionId).Value.Version; // Trim the logs to remove old versions. // Note that we try to keep the highest version that is below or equal to the ReadOnlyTransactionId // so that we can use it to serve read only transactions. long highestKey = transactionId; foreach (var key in this.log.Keys) { if (key > this.transactionAgent.ReadOnlyTransactionId) { break; } highestKey = key; } if (this.log.Count != 0) { List <KeyValuePair <long, LogRecord <TState> > > records = this.log.TakeWhile(kvp => kvp.Key < highestKey).ToList(); records.ForEach(kvp => this.log.Remove(kvp.Key)); } this.metadata.StableVersion = stableversion; this.metadata.HighestVersion = this.version; this.metadata.HighestReadTransactionId = this.highestReadTransactionId; this.eTag = await this.storage.Confirm(StateName, this.eTag, this.metadata.ToString(), stableversion.ToString()); return(true); }