예제 #1
0
        public void PulseTransaction()
        {
            try
            {
                storageActionsAccessor.ExecuteBeforeStorageCommit();

                storage.Write(writeBatch.Value);

                writeBatch.Value.Dispose();

                var hasOpenedIterators = snapshot.Value.HasOpenedIterators;

                snapshot.Value.Dispose();
                if (hasOpenedIterators)
                {
                    throw new InvalidOperationException("Cannot pulse transaction when we have iterators opened");
                }

                snapshot.Value = storage.CreateSnapshot();

                writeBatch.Value = new WriteBatch {
                    DisposeAfterWrite = writeBatch.Value.DisposeAfterWrite
                };
            }
            finally
            {
                storageActionsAccessor.ExecuteAfterStorageCommit();
            }
        }
예제 #2
0
        private Action 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(uuidGenerator, _documentCodecs,
                                                                        documentCacher, writeBatchRef, snapshotRef,
                                                                        tableStorage, this, bufferPool);

                if (disableBatchNesting.Value == null)
                {
                    current.Value = storageActionsAccessor;
                }

                action(storageActionsAccessor);
                storageActionsAccessor.SaveAllTasks();
                storageActionsAccessor.ExecuteBeforeStorageCommit();

                tableStorage.Write(writeBatchRef.Value);

                try
                {
                    return(storageActionsAccessor.ExecuteOnStorageCommit);
                }
                finally
                {
                    storageActionsAccessor.ExecuteAfterStorageCommit();
                }
            }
            finally
            {
                if (snapshotRef.Value != null)
                {
                    snapshotRef.Value.Dispose();
                }

                if (writeBatchRef.Value != null)
                {
                    writeBatchRef.Value.Dispose();
                }
            }
        }
예제 #3
0
        public void PulseTransaction()
        {
            try
            {
                storageActionsAccessor.ExecuteBeforeStorageCommit();

                storage.Write(writeBatch.Value);

                snapshot.Value.Dispose();
                writeBatch.Value.Dispose();

                snapshot.Value   = storage.CreateSnapshot();
                writeBatch.Value = new WriteBatch {
                    DisposeAfterWrite = writeBatch.Value.DisposeAfterWrite
                };
            }
            finally
            {
                storageActionsAccessor.ExecuteAfterStorageCommit();
            }
        }
예제 #4
0
        private Action 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(uuidGenerator, _documentCodecs,
                                                                        documentCacher, writeBatchRef, snapshotRef,
                                                                        tableStorage, this, bufferPool);

                if (disableBatchNesting.Value == null)
                {
                    current.Value = storageActionsAccessor;
                }

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

                storageActionsAccessor.SaveAllTasks();
                storageActionsAccessor.ExecuteBeforeStorageCommit();

                tableStorage.Write(writeBatchRef.Value);

                try
                {
                    return(storageActionsAccessor.ExecuteOnStorageCommit);
                }
                finally
                {
                    storageActionsAccessor.ExecuteAfterStorageCommit();
                }
            }
            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();
                }
            }
        }
예제 #5
0
        private Action 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(uuidGenerator, _documentCodecs,
                                                                        documentCacher, writeBatchRef, snapshotRef,
                                                                        tableStorage, this, bufferPool);

                if (disableBatchNesting.Value == null)
                    current.Value = storageActionsAccessor;

                action(storageActionsAccessor);
                storageActionsAccessor.SaveAllTasks();
				storageActionsAccessor.ExecuteBeforeStorageCommit();

				tableStorage.Write(writeBatchRef.Value);

	            try
	            {
		            return storageActionsAccessor.ExecuteOnStorageCommit;
	            }
	            finally
	            {
					storageActionsAccessor.ExecuteAfterStorageCommit();
	            }
            }
            finally
            {
                if (snapshotRef.Value != null)
                    snapshotRef.Value.Dispose();

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