Beispiel #1
0
        private void FinishSynchronization(string fileName, SynchronizationReport report, ServerInfo sourceServer, Guid sourceFileETag)
        {
            try
            {
                // we want to execute those operation in a single batch but we also have to ensure that
                // Raven/Synchronization/Sources/sourceServerId config is modified only by one finishing synchronization at the same time
                SynchronizationFinishLocks.GetOrAdd(sourceServer.Id, new ReaderWriterLockSlim()).EnterWriteLock();
                SynchronizationTask.IncomingSynchronizationFinished(fileName, sourceServer, sourceFileETag);

                Storage.Batch(accessor =>
                {
                    SaveSynchronizationReport(fileName, accessor, report);
                    FileLockManager.UnlockByDeletingSyncConfiguration(fileName, accessor);

                    if (report.Exception == null)
                    {
                        SaveSynchronizationSourceInformation(sourceServer, sourceFileETag, accessor);
                    }
                });
            }
            catch (Exception ex)
            {
                Log.ErrorException(
                    string.Format("Failed to finish synchronization of a file '{0}' from {1}", fileName, sourceServer), ex);
            }
            finally
            {
                SynchronizationFinishLocks.GetOrAdd(sourceServer.Id, new ReaderWriterLockSlim()).ExitWriteLock();
            }
        }
Beispiel #2
0
        public void AssertFileIsNotBeingSynced(string fileName)
        {
            Storage.Batch(accessor =>
            {
                if (FileLockManager.TimeoutExceeded(fileName, accessor))
                {
                    FileLockManager.UnlockByDeletingSyncConfiguration(fileName, accessor);
                }
                else
                {
                    Log.Debug("Cannot execute operation because file '{0}' is being synced", fileName);

                    throw new SynchronizationException(string.Format("File {0} is being synced", fileName));
                }
            });
        }
        protected void AssertFileIsNotBeingSynced(string fileName, IStorageActionsAccessor accessor,
                                                  bool wrapByResponseException = false)
        {
            if (FileLockManager.TimeoutExceeded(fileName, accessor))
            {
                FileLockManager.UnlockByDeletingSyncConfiguration(fileName, accessor);
            }
            else
            {
                Log.Debug("Cannot execute operation because file '{0}' is being synced", fileName);

                var beingSyncedException = new SynchronizationException(string.Format("File {0} is being synced", fileName));

                if (wrapByResponseException)
                {
                    throw new HttpResponseException(Request.CreateResponse((HttpStatusCode)420, beingSyncedException));
                }

                throw beingSyncedException;
            }
        }