public override void ClearLock(string name) { if (LockPrefix != null) { name = LockPrefix + "-" + name; } var flag1 = _remoteDirectory.FileExists(name); bool flag2; if (_remoteDirectory.FileExists(name)) { _remoteDirectory.DeleteFile(name); flag2 = true; } else { flag2 = false; } if (flag1 && !flag2) { throw new IOException("Cannot delete " + name); } }
public override void Release() { try { var flag1 = IsLocked(); bool flag2; if (IsLocked()) { _remoteDirectory.DeleteFile(_lockFile); flag2 = true; } else { flag2 = false; } if (flag1 && !flag2) { throw new LockReleaseFailedException("failed to delete " + _lockFile); } } catch (Exception ex) { Trace.WriteLine($"ERROR {ex.ToString()} Error while releasing lock"); throw; } }
/// <summary>Removes an existing file in the syncDirectory. </summary> public override void DeleteFile(string name) { //We're going to try to remove this from the cache syncDirectory first, // because the IndexFileDeleter will call this file to remove files // but since some files will be in use still, it will retry when a reader/searcher // is refreshed until the file is no longer locked. So we need to try to remove // from local storage first and if it fails, let it keep throwing the IOExpception // since that is what Lucene is expecting in order for it to retry. //If we remove the main storage file first, then this will never retry to clean out // local storage because the FileExist method will always return false. try { if (CacheDirectory.FileExists(name + ".blob")) { CacheDirectory.DeleteFile(name + ".blob"); } if (CacheDirectory.FileExists(name)) { CacheDirectory.DeleteFile(name); SetDirty(); } } catch (IOException ex) { //This will occur because this file is locked, when this is the case, we don't really want to delete it from the master either because // if we do that then this file will never get removed from the cache folder either! This is based on the Deletion Policy which the // IndexFileDeleter uses. We could implement our own one of those to deal with this scenario too but it seems the easiest way it to just // let this throw so Lucene will retry when it can and when that is successful we'll also clear it from the master LoggingService.Log(new LogEntry(LogLevel.Error, ex, $"Exception thrown while deleting file {name} for {RootFolder}")); throw; } //if we've made it this far then the cache directly file has been successfully removed so now we'll do the master RemoteDirectory.DeleteFile(name); SetDirty(); }