private void SaveSynchronizationSourceInformation(FileSystemInfo sourceFileSystem, Etag lastSourceEtag) { var lastSynchronizationInformation = GetLastSynchronization(sourceFileSystem.Id); if (EtagUtil.IsGreaterThan(lastSynchronizationInformation.LastSourceFileEtag, lastSourceEtag)) { return; } var synchronizationSourceInfo = new SourceSynchronizationInformation { LastSourceFileEtag = lastSourceEtag, SourceServerUrl = sourceFileSystem.Url, DestinationServerId = Storage.Id }; var key = SynchronizationConstants.RavenSynchronizationSourcesBasePath + "/" + sourceFileSystem.Id; Storage.Batch(accessor => accessor.SetConfig(key, JsonExtensions.ToJObject(synchronizationSourceInfo))); if (Log.IsDebugEnabled) { Log.Debug("Saved last synchronized file ETag {0} from {1} ({2})", lastSourceEtag, sourceFileSystem.Url, sourceFileSystem.Id); } }
public void FinishSynchronization(string fileName, SynchronizationReport report, FileSystemInfo sourceFileSystem, Etag 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(sourceFileSystem.Id, new ReaderWriterLockSlim()).EnterWriteLock(); Storage.Batch(accessor => { SaveSynchronizationReport(fileName, accessor, report); FileLockManager.UnlockByDeletingSyncConfiguration(fileName, accessor); if (report.Exception == null) SaveSynchronizationSourceInformation(sourceFileSystem, sourceFileETag); }); } catch (Exception ex) { Log.ErrorException(string.Format("Failed to finish synchronization of a file '{0}' from {1}", fileName, sourceFileSystem), ex); } finally { synchronizationFinishLocks.GetOrAdd(sourceFileSystem.Id, new ReaderWriterLockSlim()).ExitWriteLock(); } }
public SynchronizationBehavior(string fileName, Etag sourceFileEtag, RavenJObject sourceMetadata, FileSystemInfo sourceFs, SynchronizationType type, RavenFileSystem fs) { this.fileName = fileName; this.sourceFileEtag = sourceFileEtag; this.sourceMetadata = sourceMetadata; this.sourceFs = sourceFs; this.type = type; this.fs = fs; }
public SynchronizationMultipartRequest(ISynchronizationServerClient synchronizationServerClient, FileSystemInfo fileSystemInfo, string fileName, RavenJObject sourceMetadata, Stream sourceStream, IList<RdcNeed> needList) { this.synchronizationServerClient = synchronizationServerClient; this.fileSystemInfo = fileSystemInfo; this.fileName = fileName; this.sourceMetadata = sourceMetadata; this.sourceStream = sourceStream; this.needList = needList; syncingBoundary = "syncing"; }
public SynchronizationMultipartRequest(ISynchronizationServerClient synchronizationServerClient, FileSystemInfo fileSystemInfo, string fileName, RavenJObject sourceMetadata, Stream sourceStream, IList <RdcNeed> needList) { this.synchronizationServerClient = synchronizationServerClient; this.fileSystemInfo = fileSystemInfo; this.fileName = fileName; this.sourceMetadata = sourceMetadata; this.sourceStream = sourceStream; this.needList = needList; syncingBoundary = "syncing"; }
public SynchronizationMultipartRequest(IAsyncFilesSynchronizationCommands destination, FileSystemInfo fileSystemInfo, string fileName, RavenJObject sourceMetadata, Stream sourceStream, IList<RdcNeed> needList) { this.destination = destination; this.fileSystemInfo = fileSystemInfo; this.fileName = fileName; this.sourceMetadata = sourceMetadata; this.sourceStream = sourceStream; this.needList = needList; syncingBoundary = "syncing"; }
public SynchronizationMultipartRequest(IAsyncFilesSynchronizationCommands destination, FileSystemInfo fileSystemInfo, string fileName, RavenJObject sourceMetadata, Stream sourceStream, IList <RdcNeed> needList) { this.destination = destination; this.fileSystemInfo = fileSystemInfo; this.fileName = fileName; this.sourceMetadata = sourceMetadata; this.sourceStream = sourceStream; this.needList = needList; syncingBoundary = "syncing"; }
protected SynchronizationWorkItem(string fileName, string sourceServerUrl, ITransactionalStorage storage) { Storage = storage; FileName = fileName; FileAndPagesInformation fileAndPages = null; Storage.Batch(accessor => fileAndPages = accessor.GetFile(fileName, 0, 0)); FileMetadata = fileAndPages.Metadata; FileSystemInfo = new FileSystemInfo { Id = Storage.Id, Url = sourceServerUrl }; conflictDetector = new ConflictDetector(); conflictResolver = new ConflictResolver(null, null); }
public void IncomingSynchronizationFinished(string fileName, FileSystemInfo sourceFileSystemInfo, Guid sourceFileETag) { ConcurrentDictionary <string, SynchronizationDetails> activeSourceTasks; if (activeIncomingSynchronizations.TryGetValue(sourceFileSystemInfo.Url, out activeSourceTasks) == false) { Log.Warn("Could not get an active synchronization queue for {0}", sourceFileSystemInfo.Url); return; } SynchronizationDetails removingItem; if (activeSourceTasks.TryRemove(fileName, out removingItem)) { Log.Debug("File '{0}' with ETag {1} was removed from an active incoming synchronizations for a source {2}", fileName, sourceFileETag, sourceFileSystemInfo); } }
public void IncomingSynchronizationStarted(string fileName, FileSystemInfo sourceFileSystemInfo, Guid sourceFileETag, SynchronizationType type) { var activeForDestination = activeIncomingSynchronizations.GetOrAdd(sourceFileSystemInfo.Url, new ConcurrentDictionary<string, SynchronizationDetails>()); var syncDetails = new SynchronizationDetails { DestinationUrl = sourceFileSystemInfo.Url, FileETag = sourceFileETag, FileName = fileName, Type = type }; if (activeForDestination.TryAdd(fileName, syncDetails)) { Log.Debug("File '{0}' with ETag {1} was added to an incoming active synchronization queue for a destination {2}", fileName, sourceFileETag, sourceFileSystemInfo.Url); } }
public void IncomingSynchronizationStarted(string fileName, FileSystemInfo sourceFileSystemInfo, Guid sourceFileETag, SynchronizationType type) { var activeForDestination = activeIncomingSynchronizations.GetOrAdd(sourceFileSystemInfo.Url, new ConcurrentDictionary <string, SynchronizationDetails>()); var syncDetails = new SynchronizationDetails { DestinationUrl = sourceFileSystemInfo.Url, FileETag = sourceFileETag, FileName = fileName, Type = type }; if (activeForDestination.TryAdd(fileName, syncDetails)) { Log.Debug("File '{0}' with ETag {1} was added to an incoming active synchronization queue for a destination {2}", fileName, sourceFileETag, sourceFileSystemInfo.Url); } }
private void SaveSynchronizationSourceInformation(FileSystemInfo sourceFileSystem, Etag lastSourceEtag) { var lastSynchronizationInformation = GetLastSynchronization(sourceFileSystem.Id); if (EtagUtil.IsGreaterThan(lastSynchronizationInformation.LastSourceFileEtag, lastSourceEtag)) { return; } var synchronizationSourceInfo = new SourceSynchronizationInformation { LastSourceFileEtag = lastSourceEtag, SourceServerUrl = sourceFileSystem.Url, DestinationServerId = Storage.Id }; var key = SynchronizationConstants.RavenSynchronizationSourcesBasePath + "/" + sourceFileSystem.Id; Storage.Batch(accessor => accessor.SetConfig(key, JsonExtensions.ToJObject(synchronizationSourceInfo))); Log.Debug("Saved last synchronized file ETag {0} from {1} ({2})", lastSourceEtag, sourceFileSystem.Url, sourceFileSystem.Id); }
public void IncomingSynchronizationFinished(string fileName, FileSystemInfo sourceFileSystemInfo, Guid sourceFileETag) { ConcurrentDictionary<string, SynchronizationDetails> activeSourceTasks; if (activeIncomingSynchronizations.TryGetValue(sourceFileSystemInfo.Url, out activeSourceTasks) == false) { Log.Warn("Could not get an active synchronization queue for {0}", sourceFileSystemInfo.Url); return; } SynchronizationDetails removingItem; if (activeSourceTasks.TryRemove(fileName, out removingItem)) { Log.Debug("File '{0}' with ETag {1} was removed from an active incoming synchronizations for a source {2}", fileName, sourceFileETag, sourceFileSystemInfo); } }
public async Task <SynchronizationReport> UpdateMetadataAsync(string fileName, RavenJObject metadata, FileSystemInfo sourceFileSystem) { using (var request = RequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(this, baseUrl + "/synchronization/UpdateMetadata/" + Uri.EscapeDataString(fileName), HttpMethod.Post, Credentials, Conventions)).AddOperationHeaders(OperationsHeaders)) { request.AddHeaders(metadata); request.AddHeader(SyncingMultipartConstants.SourceFileSystemInfo, sourceFileSystem.AsJson()); AsyncFilesServerClientExtension.AddEtagHeader(request, Etag.Parse(metadata.Value <string>(Constants.MetadataEtagField))); try { var response = (RavenJObject)await request.ReadResponseJsonAsync().ConfigureAwait(false); return(response.JsonDeserialization <SynchronizationReport>()); } catch (ErrorResponseException exception) { throw exception.SimplifyException(); } } }
public void FinishSynchronization(string fileName, SynchronizationReport report, FileSystemInfo sourceFileSystem, Etag 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(sourceFileSystem.Id, new ReaderWriterLockSlim()).EnterWriteLock(); Storage.Batch(accessor => { SaveSynchronizationReport(fileName, accessor, report); FileLockManager.UnlockByDeletingSyncConfiguration(fileName, accessor); if (report.Exception == null) { SaveSynchronizationSourceInformation(sourceFileSystem, sourceFileETag); } }); } catch (Exception ex) { Log.ErrorException(string.Format("Failed to finish synchronization of a file '{0}' from {1}", fileName, sourceFileSystem), ex); } finally { synchronizationFinishLocks.GetOrAdd(sourceFileSystem.Id, new ReaderWriterLockSlim()).ExitWriteLock(); } }
public async Task<SynchronizationReport> RenameAsync(string currentName, string newName, RavenJObject metadata, FileSystemInfo sourceFileSystem) { using (var request = RequestFactory.CreateHttpJsonRequest(new CreateHttpJsonRequestParams(this, baseUrl + "/synchronization/rename?filename=" + Uri.EscapeDataString(currentName) + "&rename=" + Uri.EscapeDataString(newName), "PATCH", Credentials, Conventions)).AddOperationHeaders(OperationsHeaders)) { request.AddHeaders(metadata); request.AddHeader(SyncingMultipartConstants.SourceFileSystemInfo, sourceFileSystem.AsJson()); AsyncFilesServerClientExtension.AddEtagHeader(request, Etag.Parse(metadata.Value<string>(Constants.MetadataEtagField))); try { var response = (RavenJObject)await request.ReadResponseJsonAsync().ConfigureAwait(false); return response.JsonDeserialization<SynchronizationReport>(); } catch (ErrorResponseException exception) { throw exception.SimplifyException(); } } }