public override long Execute(DocumentsOperationContext context, TransactionOperationsMerger.RecordingState recording) { var count = 0; foreach (T id in _documentIds) { _cancellationToken.ThrowIfCancellationRequested(); _token.Delay(); if (_rateGate != null && _rateGate.WaitToProceed(0) == false) { NeedWait = true; break; } count++; var command = _commandToExecute(id); try { Processed += command?.Execute(context, recording) ?? 0; } finally { if (command is IDisposable d) { d.Dispose(); } } if (_batchSize != null && Processed >= _batchSize) { break; } if (_maxTransactionSizeInPages != null && context.Transaction.InnerTransaction.LowLevelTransaction.NumberOfModifiedPages + context.Transaction.InnerTransaction.LowLevelTransaction.AdditionalMemoryUsageSize.GetValue(SizeUnit.Bytes) / Constants.Storage.PageSize > _maxTransactionSizeInPages) { break; } } var tx = context.Transaction.InnerTransaction.LowLevelTransaction; tx.OnDispose += _ => { if (tx.Committed == false) { return; } for (int i = 0; i < count; i++) { _documentIds.Dequeue(); } }; return(Processed); }
public override int Execute(DocumentsOperationContext context, TransactionOperationsMerger.RecordingState recording) { while (_documentIds.Count > 0) { _cancellationToken.ThrowIfCancellationRequested(); _token.Delay(); if (_rateGate != null && _rateGate.WaitToProceed(0) == false) { NeedWait = true; break; } var id = _documentIds.Dequeue(); var command = _commandToExecute(id); try { var count = command?.Execute(context, recording) ?? 0; Processed += count; } finally { if (command is IDisposable d) { d.Dispose(); } } if (_batchSize != null && Processed >= _batchSize) { break; } if (_maxTransactionSizeInPages != null && context.Transaction.InnerTransaction.LowLevelTransaction.NumberOfModifiedPages + context.Transaction.InnerTransaction.LowLevelTransaction.TotalEncryptionBufferSize.GetValue(SizeUnit.Bytes) / Constants.Storage.PageSize > _maxTransactionSizeInPages) { break; } } return(Processed); }