internal LuceneDirectory MakeRAMDirectoryPhysical(RAMDirectory ramDir, string indexFolder) { var newDir = new LuceneCodecDirectory(indexFolder, new AbstractIndexCodec[0]); LuceneDirectory.Copy(ramDir, newDir, false); WriteIndexVersion(newDir); return(newDir); }
/// <summary> /// Copies the provided list of files from the <paramref name="source"/> <see cref="Directory"/> to the /// <paramref name="target"/> <see cref="Directory"/>, if they are not the same. /// </summary> /// <exception cref="IOException"></exception> public static void CopyFiles(Directory source, Directory target, IList <string> files) { if (source.Equals(target)) { return; } foreach (string file in files) { source.Copy(target, file, file, IOContext.READ_ONCE); } }
public virtual void RevisionReady(string version, IDictionary <string, IList <RevisionFile> > revisionFiles, IDictionary <string, IList <string> > copiedFiles, IDictionary <string, Directory> sourceDirectory) { if (revisionFiles.Count > 1) { throw new ArgumentException(string.Format("this handler handles only a single source; got {0}", revisionFiles.Keys)); } Directory clientDirectory = sourceDirectory.Values.First(); IList <string> files = copiedFiles.Values.First(); string segmentsFile = GetSegmentsFile(files, false); bool success = false; try { // copy files from the client to index directory CopyFiles(clientDirectory, indexDirectory, files); // fsync all copied files (except segmentsFile) indexDirectory.Sync(files); // now copy and fsync segmentsFile clientDirectory.Copy(indexDirectory, segmentsFile, segmentsFile, IOContext.READ_ONCE); indexDirectory.Sync(new[] { segmentsFile }); success = true; } finally { if (!success) { files.Add(segmentsFile); // add it back so it gets deleted too CleanupFilesOnFailure(indexDirectory, files); } } // all files have been successfully copied + sync'd. update the handler's state currentRevisionFiles = revisionFiles; currentVersion = version; WriteToInfoStream(string.Format("revisionReady(): currentVersion={0} currentRevisionFiles={1}", currentVersion, currentRevisionFiles)); // update the segments.gen file WriteSegmentsGen(segmentsFile, indexDirectory); // Cleanup the index directory from old and unused index files. // NOTE: we don't use IndexWriter.deleteUnusedFiles here since it may have // side-effects, e.g. if it hits sudden IO errors while opening the index // (and can end up deleting the entire index). It is not our job to protect // against those errors, app will probably hit them elsewhere. CleanupOldIndexFiles(indexDirectory, segmentsFile); // successfully updated the index, notify the callback that the index is // ready. if (callback != null) { try { callback.Invoke(); } catch (Exception e) { throw new IOException(e.ToString(), e); } } }
public virtual void RevisionReady(string version, IDictionary <string, IList <RevisionFile> > revisionFiles, IDictionary <string, IList <string> > copiedFiles, IDictionary <string, Directory> sourceDirectory) { Directory taxonomyClientDirectory = sourceDirectory[IndexAndTaxonomyRevision.TAXONOMY_SOURCE]; Directory indexClientDirectory = sourceDirectory[IndexAndTaxonomyRevision.INDEX_SOURCE]; IList <string> taxonomyFiles = copiedFiles[IndexAndTaxonomyRevision.TAXONOMY_SOURCE]; IList <string> indexFiles = copiedFiles[IndexAndTaxonomyRevision.INDEX_SOURCE]; string taxonomySegmentsFile = IndexReplicationHandler.GetSegmentsFile(taxonomyFiles, true); string indexSegmentsFile = IndexReplicationHandler.GetSegmentsFile(indexFiles, false); bool success = false; try { // copy taxonomy files before index files IndexReplicationHandler.CopyFiles(taxonomyClientDirectory, taxonomyDirectory, taxonomyFiles); IndexReplicationHandler.CopyFiles(indexClientDirectory, indexDirectory, indexFiles); // fsync all copied files (except segmentsFile) if (taxonomyFiles.Any()) { taxonomyDirectory.Sync(taxonomyFiles); } indexDirectory.Sync(indexFiles); // now copy and fsync segmentsFile, taxonomy first because it is ok if a // reader sees a more advanced taxonomy than the index. if (taxonomySegmentsFile != null) { taxonomyClientDirectory.Copy(taxonomyDirectory, taxonomySegmentsFile, taxonomySegmentsFile, IOContext.READ_ONCE); } indexClientDirectory.Copy(indexDirectory, indexSegmentsFile, indexSegmentsFile, IOContext.READ_ONCE); if (taxonomySegmentsFile != null) { taxonomyDirectory.Sync(new[] { taxonomySegmentsFile }); } indexDirectory.Sync(new[] { indexSegmentsFile }); success = true; } finally { if (!success) { taxonomyFiles.Add(taxonomySegmentsFile); // add it back so it gets deleted too IndexReplicationHandler.CleanupFilesOnFailure(taxonomyDirectory, taxonomyFiles); indexFiles.Add(indexSegmentsFile); // add it back so it gets deleted too IndexReplicationHandler.CleanupFilesOnFailure(indexDirectory, indexFiles); } } // all files have been successfully copied + sync'd. update the handler's state currentRevisionFiles = revisionFiles; currentVersion = version; WriteToInfoStream("revisionReady(): currentVersion=" + currentVersion + " currentRevisionFiles=" + currentRevisionFiles); // update the segments.gen file IndexReplicationHandler.WriteSegmentsGen(taxonomySegmentsFile, taxonomyDirectory); IndexReplicationHandler.WriteSegmentsGen(indexSegmentsFile, indexDirectory); // Cleanup the index directory from old and unused index files. // NOTE: we don't use IndexWriter.deleteUnusedFiles here since it may have // side-effects, e.g. if it hits sudden IO errors while opening the index // (and can end up deleting the entire index). It is not our job to protect // against those errors, app will probably hit them elsewhere. IndexReplicationHandler.CleanupOldIndexFiles(indexDirectory, indexSegmentsFile); IndexReplicationHandler.CleanupOldIndexFiles(taxonomyDirectory, taxonomySegmentsFile); // successfully updated the index, notify the callback that the index is // ready. if (callback != null) { try { callback.Invoke(); } catch (Exception e) { throw new IOException(e.Message, e); } } }
private RAMDirectory(Directory dir, bool closeDir, IOContext context) : this() { foreach (string file in dir.ListAll()) { dir.Copy(this, file, file, context); } if (closeDir) { dir.Dispose(); } }
private RAMDirectory(Directory dir, bool closeDir) : this() { Directory.Copy(dir, this, closeDir); }
private RAMDirectory(Directory dir, bool closeDir, IState state) : this() { Directory.Copy(dir, this, closeDir, state); }