Esempio n. 1
0
        public RemoteDirectoryIndexInput(RemoteDirectoryIndexInput cloneInput)
        {
            _name = cloneInput._name;
            _remoteSyncDirectory = cloneInput._remoteSyncDirectory;

            if (string.IsNullOrWhiteSpace(_name))
            {
                throw new ArgumentNullException(nameof(cloneInput._name));
            }
            if (_remoteSyncDirectory == null)
            {
                throw new ArgumentNullException(nameof(cloneInput._remoteSyncDirectory));
            }

            _fileMutex = SyncMutexManager.GrabMutex(cloneInput._remoteSyncDirectory, cloneInput._name);
            _fileMutex.WaitOne();

            try
            {
#if FULLDEBUG
                Trace.WriteLine($"Creating clone for {cloneInput._name}");
#endif
                _indexInput = cloneInput._indexInput.Clone() as IndexInput;
            }
            catch (Exception)
            {
                // sometimes we get access denied on the 2nd stream...but not always. I haven't tracked it down yet
                // but this covers our tail until I do
                Trace.TraceError($"Dagnabbit, falling back to memory clone for {cloneInput._name}");
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
 public RemoteSimpleLock(string lockFile, RemoteSyncDirectory syncDirectory, IRemoteDirectory remoteDirectory)
 {
     if (syncDirectory == null)
     {
         throw new ArgumentNullException(nameof(syncDirectory));
     }
     if (string.IsNullOrWhiteSpace(lockFile))
     {
         throw new ArgumentException("Value cannot be null or whitespace.", nameof(lockFile));
     }
     _lockFile           = lockFile;
     _azureSyncDirectory = syncDirectory;
     _remoteDirectory    = remoteDirectory;
 }
Esempio n. 3
0
        protected override void Dispose(bool isDiposing)
        {
            _fileMutex.WaitOne();
            try
            {
#if FULLDEBUG
                Trace.WriteLine($"CLOSED READSTREAM local {_name}");
#endif
                _indexInput.Dispose();
                _indexInput          = null;
                _remoteSyncDirectory = null;
                GC.SuppressFinalize(this);
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
 public RemoteDirectoryIndexOutput(RemoteSyncDirectory azureSyncDirectory, string name,
                                   ILoggingService loggingService)
 {
     //NOTE: _name was null here, is this intended? https://github.com/azure-contrib/AzureDirectory/issues/19 I have changed this to be correct now
     _name = name;
     _azureSyncDirectory   = azureSyncDirectory ?? throw new ArgumentNullException(nameof(azureSyncDirectory));
     _azureRemoteDirectory = _azureSyncDirectory.RemoteDirectory;
     _fileMutex            = SyncMutexManager.GrabMutex(_azureSyncDirectory, _name);
     _fileMutex.WaitOne();
     try
     {
         // create the local cache one we will operate against...
         _indexOutput = CacheDirectory.CreateOutput(_name);
     }
     finally
     {
         _fileMutex.ReleaseMutex();
     }
 }
Esempio n. 5
0
        public RemoteDirectoryIndexInput(RemoteSyncDirectory azuredirectory, IRemoteDirectory helper, string name,
                                         ILoggingService loggingService)
        {
            _name = name;
            _name = _name.Split(new string[] { "%2F" }, StringSplitOptions.RemoveEmptyEntries).Last();
            _remoteSyncDirectory = azuredirectory ?? throw new ArgumentNullException(nameof(azuredirectory));
#if FULLDEBUG
            Trace.WriteLine($"opening {_name} ");
#endif
            _fileMutex = SyncMutexManager.GrabMutex(_remoteSyncDirectory, _name);
            _fileMutex.WaitOne();
            try
            {
                var fileName = _name;

                var fFileNeeded = false;
                if (!CacheDirectory.FileExists(fileName))
                {
                    fFileNeeded = true;
                }
                else
                {
                    var cachedLength   = CacheDirectory.FileLength(fileName);
                    var blobProperties = helper.GetFileProperties(fileName);


                    if (cachedLength != blobProperties.Item1)
                    {
                        fFileNeeded = true;
                    }
                    else
                    {
                        // cachedLastModifiedUTC was not ouputting with a date (just time) and the time was always off
                        var unixDate = CacheDirectory.FileModified(fileName);
                        var start    = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
                        var cachedLastModifiedUtc = start.AddMilliseconds(unixDate).ToUniversalTime();

                        if (cachedLastModifiedUtc != blobProperties.Item2)
                        {
                            var timeSpan = blobProperties.Item2.Subtract(cachedLastModifiedUtc);
                            if (timeSpan.TotalSeconds > 1)
                            {
                                fFileNeeded = true;
                            }
                            else
                            {
#if FULLDEBUG
                                Trace.WriteLine(timeSpan.TotalSeconds);
#endif
                                // file not needed
                            }
                        }
                    }
                }

                // if the file does not exist
                // or if it exists and it is older then the lastmodified time in the blobproperties (which always comes from the blob storage)
                if (fFileNeeded)
                {
                    helper.SyncFile(CacheDirectory, fileName, azuredirectory.CompressBlobs);

                    // and open it as an input
                    _indexInput = CacheDirectory.OpenInput(fileName);
                }
                else
                {
#if FULLDEBUG
                    Trace.WriteLine($"Using cached file for {_name}");
#endif

                    // open the file in read only mode
                    _indexInput = CacheDirectory.OpenInput(fileName);
                }
            }
            finally
            {
                _fileMutex.ReleaseMutex();
            }
        }
Esempio n. 6
0
 public RemoteDirectorySimpleLockFactory(RemoteSyncDirectory azureSyncDirectory, IRemoteDirectory remoteDirectory)
 {
     _azureSyncDirectory = azureSyncDirectory;
     _remoteDirectory    = remoteDirectory;
 }
 public IndexInput GetIndexInput(RemoteSyncDirectory azuredirectory, IRemoteDirectory helper, string name, ILoggingService loggingService)
 {
     return(new RemoteDirectoryIndexInput(azuredirectory, helper, name, loggingService));
 }
 public IndexOutput CreateIndexOutput(RemoteSyncDirectory azureSyncDirectory, string name, ILoggingService loggingService)
 {
     return(new RemoteDirectoryIndexOutput(azureSyncDirectory, name, loggingService));
 }