예제 #1
0
        private void ExecuteBatch(Action <IStorageActionsAccessor> action)
        {
            var snapshotRef   = new Reference <SnapshotReader>();
            var writeBatchRef = new Reference <WriteBatch>();

            try
            {
                snapshotRef.Value   = tableStorage.CreateSnapshot();
                writeBatchRef.Value = new WriteBatch {
                    DisposeAfterWrite = false
                };                                                                  // prevent from disposing after write to allow read from batch OnStorageCommit
                var storageActionsAccessor = new StorageActionsAccessor(tableStorage, writeBatchRef, snapshotRef, idGenerator, bufferPool, uuidGenerator, fileCodecs);
                if (disableBatchNesting.Value == null)
                {
                    current.Value = storageActionsAccessor;
                }

                action(storageActionsAccessor);
                storageActionsAccessor.Commit();

                tableStorage.Write(writeBatchRef.Value);
            }
            finally
            {
                if (snapshotRef.Value != null)
                {
                    snapshotRef.Value.Dispose();
                }

                if (writeBatchRef.Value != null)
                {
                    writeBatchRef.Value.Dispose();
                }
            }
        }
예제 #2
0
        private void ExecuteBatch(Action <IStorageActionsAccessor> action)
        {
            if (current.Value != null)
            {
                action(current.Value);
                return;
            }

            using (var snapshot = tableStorage.CreateSnapshot())
            {
                var writeBatchRef = new Reference <WriteBatch>();
                try
                {
                    writeBatchRef.Value = new WriteBatch {
                        DisposeAfterWrite = false
                    };
                    using (var storageActionsAccessor = new StorageActionsAccessor(tableStorage, writeBatchRef, snapshot, idGenerator, bufferPool))
                    {
                        current.Value = storageActionsAccessor;

                        action(storageActionsAccessor);
                        storageActionsAccessor.Commit();

                        tableStorage.Write(writeBatchRef.Value);
                    }
                }
                finally
                {
                    if (writeBatchRef.Value != null)
                    {
                        writeBatchRef.Value.Dispose();
                    }
                }
            }
        }
        private void ExecuteBatch(Action<IStorageActionsAccessor> action)
        {
            if (current.Value != null)
            {
                action(current.Value);
                return;
            }

            using (var snapshot = tableStorage.CreateSnapshot())
            {
                var writeBatchRef = new Reference<WriteBatch>();
                try
                {
                    writeBatchRef.Value = new WriteBatch { DisposeAfterWrite = false };
                    using (var storageActionsAccessor = new StorageActionsAccessor(tableStorage, writeBatchRef, snapshot, idGenerator, bufferPool))
                    {
                        current.Value = storageActionsAccessor;

                        action(storageActionsAccessor);
                        storageActionsAccessor.Commit();

                        tableStorage.Write(writeBatchRef.Value);
                    }
                }
                finally
                {
                    if (writeBatchRef.Value != null)
                    {
                        writeBatchRef.Value.Dispose();
                    }
                }
            }
        }
예제 #4
0
        private void ExecuteBatch(Action<IStorageActionsAccessor> action)
        {
            var snapshotRef = new Reference<SnapshotReader>();
            var writeBatchRef = new Reference<WriteBatch>();

            try
            {
                snapshotRef.Value = tableStorage.CreateSnapshot();
                writeBatchRef.Value = new WriteBatch { DisposeAfterWrite = false }; // prevent from disposing after write to allow read from batch OnStorageCommit
                var storageActionsAccessor = new StorageActionsAccessor(tableStorage, writeBatchRef, snapshotRef, idGenerator, bufferPool, uuidGenerator, fileCodecs);
                if (disableBatchNesting.Value == null)
                    current.Value = storageActionsAccessor;

                action(storageActionsAccessor);
                storageActionsAccessor.Commit();

                tableStorage.Write(writeBatchRef.Value);
            }
            finally
            {
                if (snapshotRef.Value != null)
                    snapshotRef.Value.Dispose();

                if (writeBatchRef.Value != null)
                    writeBatchRef.Value.Dispose();
            }
        }
예제 #5
0
        private void ExecuteBatch(Action <IStorageActionsAccessor> action)
        {
            var snapshotRef   = new Reference <SnapshotReader>();
            var writeBatchRef = new Reference <WriteBatch>();

            var errorInUserAction = false;

            try
            {
                snapshotRef.Value   = tableStorage.CreateSnapshot();
                writeBatchRef.Value = new WriteBatch {
                    DisposeAfterWrite = false
                };                                                                  // prevent from disposing after write to allow read from batch OnStorageCommit
                var storageActionsAccessor = new StorageActionsAccessor(tableStorage, writeBatchRef, snapshotRef, idGenerator, bufferPool, uuidGenerator, fileCodecs);
                if (disableBatchNesting.Value == null)
                {
                    current.Value = storageActionsAccessor;
                }

                errorInUserAction = true;
                action(storageActionsAccessor);
                errorInUserAction = false;
                storageActionsAccessor.Commit();

                tableStorage.Write(writeBatchRef.Value);
            }
            catch (Exception e)
            {
                var exception = e;
                var ae        = e as AggregateException;
                if (ae != null)
                {
                    exception = ae.ExtractSingleInnerException();
                }

                Exception _;
                if (TransactionalStorageHelper.IsVoronOutOfMemoryException(exception) ||
                    TransactionalStorageHelper.IsWriteConflict(e, out _))
                {
                    throw;
                }

                if (errorInUserAction == false)
                {
                    Log.ErrorException("Failed to execute transaction. Most likely something is really wrong here.", e);
                }

                throw;
            }
            finally
            {
                if (snapshotRef.Value != null)
                {
                    snapshotRef.Value.Dispose();
                }

                if (writeBatchRef.Value != null)
                {
                    writeBatchRef.Value.Dispose();
                }
            }
        }