SWEEP: Modified all command-line utilities to throw exceptions instead of display to console so our wrapper console app can show the correct usage info.
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/f0b56fd2 Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/f0b56fd2 Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/f0b56fd2 Branch: refs/heads/master Commit: f0b56fd24bb70d3b5b0a32d3fc99de7c30c09cdf Parents: 933d835 Author: Shad Storhaug <[email protected]> Authored: Thu Jul 6 18:56:44 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Jul 6 18:56:44 2017 +0700 ---------------------------------------------------------------------- .../Taxonomy/PrintTaxonomyStats.cs | 18 +- .../Index/CompoundFileExtractor.cs | 10 +- src/Lucene.Net.Misc/Index/IndexSplitter.cs | 12 +- .../Index/MultiPassIndexSplitter.cs | 14 +- src/Lucene.Net.Misc/Misc/GetTermInfo.cs | 17 +- src/Lucene.Net.Misc/Misc/HighFreqTerms.cs | 16 +- src/Lucene.Net/Index/CheckIndex.cs | 330 ++++++++++--------- src/Lucene.Net/Index/IndexUpgrader.cs | 27 +- src/Lucene.Net/Store/LockStressTest.cs | 46 ++- src/Lucene.Net/Store/LockVerifyServer.cs | 19 +- 10 files changed, 283 insertions(+), 226 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs index 6ba2d7f..b8ce155 100644 --- a/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs +++ b/src/Lucene.Net.Facet/Taxonomy/PrintTaxonomyStats.cs @@ -59,14 +59,18 @@ namespace Lucene.Net.Facet.Taxonomy } if (args.Length != (printTree ? 2 : 1)) { - // LUCENENET TODO: Usage depends on wrapping this into a console application assembly. - Console.WriteLine("\nUsage: java -classpath ... org.apache.lucene.facet.util.PrintTaxonomyStats [-printTree] /path/to/taxononmy/index\n"); - return 1; + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Console.WriteLine("\nUsage: java -classpath ... org.apache.lucene.facet.util.PrintTaxonomyStats [-printTree] /path/to/taxononmy/index\n"); + //return 1; + } + using (Store.Directory dir = FSDirectory.Open(new DirectoryInfo(path))) + { + using (var r = new DirectoryTaxonomyReader(dir)) + { + PrintStats(r, System.Console.Out, printTree); + } } - Store.Directory dir = FSDirectory.Open(new DirectoryInfo(path)); - var r = new DirectoryTaxonomyReader(dir); - PrintStats(r, System.Console.Out, printTree); - r.Dispose(); return 0; } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs b/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs index 80ced50..db9c5be 100644 --- a/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs +++ b/src/Lucene.Net.Misc/Index/CompoundFileExtractor.cs @@ -66,8 +66,10 @@ namespace Lucene.Net.Index if (filename == null) { - Console.WriteLine("Usage: org.apache.lucene.index.CompoundFileExtractor [-extract] [-dir-impl X] <cfsfile>"); - return; + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException("ERROR: CFS-FILE is required"); + //Console.WriteLine("Usage: org.apache.lucene.index.CompoundFileExtractor [-extract] [-dir-impl X] <cfsfile>"); + //return; } Store.Directory dir = null; @@ -129,7 +131,7 @@ namespace Lucene.Net.Index catch (IOException ioe) { Console.WriteLine(ioe.ToString()); - Console.Write(ioe.StackTrace); + //Console.Write(ioe.StackTrace); } finally { @@ -147,7 +149,7 @@ namespace Lucene.Net.Index catch (IOException ioe) { Console.WriteLine(ioe.ToString()); - Console.Write(ioe.StackTrace); + //Console.Write(ioe.StackTrace); } } } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net.Misc/Index/IndexSplitter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Misc/Index/IndexSplitter.cs b/src/Lucene.Net.Misc/Index/IndexSplitter.cs index 9710943..1bb3dee 100644 --- a/src/Lucene.Net.Misc/Index/IndexSplitter.cs +++ b/src/Lucene.Net.Misc/Index/IndexSplitter.cs @@ -34,7 +34,7 @@ namespace Lucene.Net.Index /// into multiple segments. For example if your index is a /// single segment, this tool won't help. Also, it does basic /// file-level copying (using simple - /// FileInfo) so it will not work with non + /// Stream) so it will not work with non /// FSDirectory Directory impls.</para> /// /// @lucene.experimental You can easily @@ -53,10 +53,12 @@ namespace Lucene.Net.Index { if (args.Length < 2) { - Console.Error.WriteLine("Usage: IndexSplitter <srcDir> -l (list the segments and their sizes)"); - Console.Error.WriteLine("IndexSplitter <srcDir> <destDir> <segments>+"); - Console.Error.WriteLine("IndexSplitter <srcDir> -d (delete the following segments)"); - return; + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Console.Error.WriteLine("Usage: IndexSplitter <srcDir> -l (list the segments and their sizes)"); + //Console.Error.WriteLine("IndexSplitter <srcDir> <destDir> <segments>+"); + //Console.Error.WriteLine("IndexSplitter <srcDir> -d (delete the following segments)"); + //return; } DirectoryInfo srcDir = new DirectoryInfo(args[0]); IndexSplitter @is = new IndexSplitter(srcDir); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs b/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs index bca1284..4f40250 100644 --- a/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs +++ b/src/Lucene.Net.Misc/Index/MultiPassIndexSplitter.cs @@ -123,12 +123,14 @@ namespace Lucene.Net.Index { if (args.Length < 5) { - Console.Error.WriteLine("Usage: MultiPassIndexSplitter -out <outputDir> -num <numParts> [-seq] <inputIndex1> [<inputIndex2 ...]"); - Console.Error.WriteLine("\tinputIndex\tpath to input index, multiple values are ok"); - Console.Error.WriteLine("\t-out ouputDir\tpath to output directory to contain partial indexes"); - Console.Error.WriteLine("\t-num numParts\tnumber of parts to produce"); - Console.Error.WriteLine("\t-seq\tsequential docid-range split (default is round-robin)"); - Environment.Exit(-1); + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Console.Error.WriteLine("Usage: MultiPassIndexSplitter -out <outputDir> -num <numParts> [-seq] <inputIndex1> [<inputIndex2 ...]"); + //Console.Error.WriteLine("\tinputIndex\tpath to input index, multiple values are ok"); + //Console.Error.WriteLine("\t-out ouputDir\tpath to output directory to contain partial indexes"); + //Console.Error.WriteLine("\t-num numParts\tnumber of parts to produce"); + //Console.Error.WriteLine("\t-seq\tsequential docid-range split (default is round-robin)"); + //Environment.Exit(-1); } List<IndexReader> indexes = new List<IndexReader>(); string outDir = null; http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net.Misc/Misc/GetTermInfo.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Misc/Misc/GetTermInfo.cs b/src/Lucene.Net.Misc/Misc/GetTermInfo.cs index f99d96a..3ab9792 100644 --- a/src/Lucene.Net.Misc/Misc/GetTermInfo.cs +++ b/src/Lucene.Net.Misc/Misc/GetTermInfo.cs @@ -42,8 +42,10 @@ namespace Lucene.Net.Misc } else { - Usage(); - Environment.Exit(1); + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Usage(); + //Environment.Exit(1); } TermInfo(dir, new Term(field, inputStr)); @@ -55,10 +57,11 @@ namespace Lucene.Net.Misc Console.WriteLine("{0}:{1} \t totalTF = {2:#,##0} \t doc freq = {3:#,##0} \n", term.Field, term.Text(), reader.TotalTermFreq(term), reader.DocFreq(term)); } - private static void Usage() - { - // LUCENENET TODO: Usage info is dependant on packaging this into a standalone console application - Console.WriteLine("\n\nusage:\n\t" + "java " + typeof(GetTermInfo).FullName + " <index dir> field term \n\n"); - } + // LUCENENET specific - our wrapper console shows the correct usage + //private static void Usage() + //{ + // // LUCENENET TODO: Usage info is dependant on packaging this into a standalone console application + // Console.WriteLine("\n\nusage:\n\t" + "java " + typeof(GetTermInfo).FullName + " <index dir> field term \n\n"); + //} } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net.Misc/Misc/HighFreqTerms.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Misc/Misc/HighFreqTerms.cs b/src/Lucene.Net.Misc/Misc/HighFreqTerms.cs index 2cb9ec0..3c74fc0 100644 --- a/src/Lucene.Net.Misc/Misc/HighFreqTerms.cs +++ b/src/Lucene.Net.Misc/Misc/HighFreqTerms.cs @@ -48,8 +48,10 @@ namespace Lucene.Net.Misc if (args.Length == 0 || args.Length > 4) { - Usage(); - Environment.Exit(1); + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Usage(); + //Environment.Exit(1); } Store.Directory dir = FSDirectory.Open(new DirectoryInfo(args[0])); @@ -86,11 +88,11 @@ namespace Lucene.Net.Misc } } - private static void Usage() - { - // LUCENENET TODO: Usage depends on packaging this into an assembly executable. - Console.WriteLine("\n\n" + "java org.apache.lucene.misc.HighFreqTerms <index dir> [-t] [number_terms] [field]\n\t -t: order by totalTermFreq\n\n"); - } + // LUCENENET specific - our wrapper console shows the correct usage + //private static void Usage() + //{ + // Console.WriteLine("\n\n" + "java org.apache.lucene.misc.HighFreqTerms <index dir> [-t] [number_terms] [field]\n\t -t: order by totalTermFreq\n\n"); + //} /// <summary> /// Returns <see cref="T:TermStats[]"/> ordered by the specified comparer http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net/Index/CheckIndex.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Index/CheckIndex.cs b/src/Lucene.Net/Index/CheckIndex.cs index 6a43b1b..565b312 100644 --- a/src/Lucene.Net/Index/CheckIndex.cs +++ b/src/Lucene.Net/Index/CheckIndex.cs @@ -1,10 +1,13 @@ +using Lucene.Net.Store; using Lucene.Net.Support; using Lucene.Net.Support.IO; +using Lucene.Net.Util; using System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.IO; +using System.Threading; namespace Lucene.Net.Index { @@ -480,8 +483,8 @@ namespace Lucene.Net.Index } set { - infoStream = value == null - ? null + infoStream = value == null + ? null : (value is SafeTextWriterWrapper ? value : new SafeTextWriterWrapper(value)); } } @@ -2399,183 +2402,194 @@ namespace Lucene.Net.Index return assertsOn; } - // LUCENENET TODO: This seems too useful not to port over...but I suppose there is a Java version that could be used on the command line. - - /* - /// Command-line interface to check and fix an index. - /// - /// <p> - /// Run it like this: - /// <pre> - /// java -ea:org.apache.lucene... Lucene.Net.Index.CheckIndex pathToIndex [-fix] [-verbose] [-segment X] [-segment Y] - /// </pre> - /// <ul> - /// <li><code>-fix</code>: actually write a new segments_N file, removing any problematic segments - /// - /// <li><code>-segment X</code>: only check the specified - /// segment(s). this can be specified multiple times, - /// to check more than one segment, eg <code>-segment _2 - /// -segment _a</code>. You can't use this with the -fix - /// option. - /// </ul> - /// - /// <p><b>WARNING</b>: <code>-fix</code> should only be used on an emergency basis as it will cause - /// documents (perhaps many) to be permanently removed from the index. Always make - /// a backup copy of your index before running this! Do not run this tool on an index - /// that is actively being written to. You have been warned! - /// - /// <p> Run without -fix, this tool will open the index, report version information - /// and report any exceptions it hits and what action it would take if -fix were - /// specified. With -fix, this tool will remove any segments that have issues and - /// write a new segments_N file. this means all documents contained in the affected - /// segments will be removed. - /// - /// <p> - /// this tool exits with exit code 1 if the index cannot be opened or has any - /// corruption, else 0. - */ - /*[STAThread] + ///// Command-line interface to check and fix an index. + ///// + ///// <p> + ///// Run it like this: + ///// <pre> + ///// java -ea:org.apache.lucene... Lucene.Net.Index.CheckIndex pathToIndex [-fix] [-verbose] [-segment X] [-segment Y] + ///// </pre> + ///// <ul> + ///// <li><code>-fix</code>: actually write a new segments_N file, removing any problematic segments + ///// + ///// <li><code>-segment X</code>: only check the specified + ///// segment(s). this can be specified multiple times, + ///// to check more than one segment, eg <code>-segment _2 + ///// -segment _a</code>. You can't use this with the -fix + ///// option. + ///// </ul> + ///// + ///// <p><b>WARNING</b>: <code>-fix</code> should only be used on an emergency basis as it will cause + ///// documents (perhaps many) to be permanently removed from the index. Always make + ///// a backup copy of your index before running this! Do not run this tool on an index + ///// that is actively being written to. You have been warned! + ///// + ///// <p> Run without -fix, this tool will open the index, report version information + ///// and report any exceptions it hits and what action it would take if -fix were + ///// specified. With -fix, this tool will remove any segments that have issues and + ///// write a new segments_N file. this means all documents contained in the affected + ///// segments will be removed. + ///// + ///// <p> + ///// this tool exits with exit code 1 if the index cannot be opened or has any + ///// corruption, else 0. + [STAThread] public static void Main(string[] args) { - bool doFix = false; - bool doCrossCheckTermVectors = false; - bool verbose = false; - IList<string> onlySegments = new List<string>(); - string indexPath = null; - string dirImpl = null; - int i = 0; - while (i < args.Length) - { - string arg = args[i]; - if ("-fix".Equals(arg, StringComparison.Ordinal)) + bool doFix = false; + bool doCrossCheckTermVectors = false; + bool verbose = false; + IList<string> onlySegments = new List<string>(); + string indexPath = null; + string dirImpl = null; + int i = 0; + while (i < args.Length) + { + string arg = args[i]; + if ("-fix".Equals(arg, StringComparison.Ordinal)) + { + doFix = true; + } + else if ("-crossCheckTermVectors".Equals(arg, StringComparison.Ordinal)) + { + doCrossCheckTermVectors = true; + } + else if (arg.Equals("-verbose", StringComparison.Ordinal)) + { + verbose = true; + } + else if (arg.Equals("-segment", StringComparison.Ordinal)) + { + if (i == args.Length - 1) + { + // LUCENENET specific - we only output from our CLI wrapper + throw new ArgumentException("ERROR: missing name for -segment option"); + //Console.WriteLine("ERROR: missing name for -segment option"); + //Environment.Exit(1); + } + i++; + onlySegments.Add(args[i]); + } + else if ("-dir-impl".Equals(arg, StringComparison.Ordinal)) + { + if (i == args.Length - 1) + { + // LUCENENET specific - we only output from our CLI wrapper + throw new ArgumentException("ERROR: missing value for -dir-impl option"); + //Console.WriteLine("ERROR: missing value for -dir-impl option"); + //Environment.Exit(1); + } + i++; + dirImpl = args[i]; + } + else + { + if (indexPath != null) + { + // LUCENENET specific - we only output from our CLI wrapper + throw new ArgumentException("ERROR: unexpected extra argument '" + args[i] + "'"); + //Console.WriteLine("ERROR: unexpected extra argument '" + args[i] + "'"); + //Environment.Exit(1); + } + indexPath = args[i]; + } + i++; + } + + if (indexPath == null) { - doFix = true; + // LUCENENET specific - we only output from our CLI wrapper + throw new ArgumentException("\nERROR: index path not specified"); + //Console.WriteLine("\nERROR: index path not specified"); + //Console.WriteLine("\nUsage: java Lucene.Net.Index.CheckIndex pathToIndex [-fix] [-crossCheckTermVectors] [-segment X] [-segment Y] [-dir-impl X]\n" + "\n" + " -fix: actually write a new segments_N file, removing any problematic segments\n" + " -crossCheckTermVectors: verifies that term vectors match postings; this IS VERY SLOW!\n" + " -codec X: when fixing, codec to write the new segments_N file with\n" + " -verbose: print additional details\n" + " -segment X: only check the specified segments. this can be specified multiple\n" + " times, to check more than one segment, eg '-segment _2 -segment _a'.\n" + " You can't use this with the -fix option\n" + " -dir-impl X: use a specific " + typeof(FSDirectory).Name + " implementation. " + "If no package is specified the " + typeof(FSDirectory).Namespace + " package will be used.\n" + "\n" + "**WARNING**: -fix should only be used on an emergency basis as it will cause\n" + "documents (perha ps many) to be permanently removed from the index. Always make\n" + "a backup copy of your index before running this! Do not run this tool on an index\n" + "that is actively being written to. You have been warned!\n" + "\n" + "Run without -fix, this tool will open the index, report version information\n" + "and report any exceptions it hits and what action it would take if -fix were\n" + "specified. With -fix, this tool will remove any segments that have issues and\n" + "write a new segments_N file. this means all documents contained in the affected\n" + "segments will be removed.\n" + "\n" + "this tool exits with exit code 1 if the index cannot be opened or has any\n" + "corruption, else 0.\n"); + //Environment.Exit(1); } - else if ("-crossCheckTermVectors".Equals(arg, StringComparison.Ordinal)) + + // LUCENENET specific - doesn't apply + //if (!AssertsOn()) + //{ + // Console.WriteLine("\nNOTE: testing will be more thorough if you run java with '-ea:org.apache.lucene...', so assertions are enabled"); + //} + + if (onlySegments.Count == 0) { - doCrossCheckTermVectors = true; + onlySegments = null; } - else if (arg.Equals("-verbose", StringComparison.Ordinal)) + else if (doFix) { - verbose = true; + // LUCENENET specific - we only output from our CLI wrapper + throw new ArgumentException("ERROR: cannot specify both -fix and -segment"); + //Console.WriteLine("ERROR: cannot specify both -fix and -segment"); + //Environment.Exit(1); } - else if (arg.Equals("-segment", StringComparison.Ordinal)) + + Console.WriteLine("\nOpening index @ " + indexPath + "\n"); + Directory dir = null; + try { - if (i == args.Length - 1) - { - Console.WriteLine("ERROR: missing name for -segment option"); - Environment.Exit(1); - } - i++; - onlySegments.Add(args[i]); + if (dirImpl == null) + { + dir = FSDirectory.Open(new DirectoryInfo(indexPath)); + } + else + { + dir = CommandLineUtil.NewFSDirectory(dirImpl, new DirectoryInfo(indexPath)); + } } - else if ("-dir-impl".Equals(arg, StringComparison.Ordinal)) + catch (Exception t) { - if (i == args.Length - 1) - { - Console.WriteLine("ERROR: missing value for -dir-impl option"); - Environment.Exit(1); - } - i++; - dirImpl = args[i]; + // LUCENENET specific - we only output from our CLI wrapper + throw new ArgumentException("ERROR: could not open directory \"" + indexPath + "\"; exiting\n" + t.ToString()); + //Console.WriteLine("ERROR: could not open directory \"" + indexPath + "\"; exiting"); + //Console.Out.WriteLine(t.StackTrace); + //Environment.Exit(1); } - else + + CheckIndex checker = new CheckIndex(dir); + checker.CrossCheckTermVectors = doCrossCheckTermVectors; + checker.InfoStream = Console.Out; + checker.InfoStreamIsVerbose = verbose; + + Status result = checker.DoCheckIndex(onlySegments); + if (result.MissingSegments) { - if (indexPath != null) - { - Console.WriteLine("ERROR: unexpected extra argument '" + args[i] + "'"); Environment.Exit(1); - } - indexPath = args[i]; - } - i++; - } - - if (indexPath == null) - { - Console.WriteLine("\nERROR: index path not specified"); - Console.WriteLine("\nUsage: java Lucene.Net.Index.CheckIndex pathToIndex [-fix] [-crossCheckTermVectors] [-segment X] [-segment Y] [-dir-impl X]\n" + "\n" + " -fix: actually write a new segments_N file, removing any problematic segments\n" + " -crossCheckTermVectors: verifies that term vectors match postings; this IS VERY SLOW!\n" + " -codec X: when fixing, codec to write the new segments_N file with\n" + " -verbose: print additional details\n" + " -segment X: only check the specified segments. this can be specified multiple\n" + " times, to check more than one segment, eg '-segment _2 -segment _a'.\n" + " You can't use this with the -fix option\n" + " -dir-impl X: use a specific " + typeof(FSDirectory).Name + " implementation. " + "If no package is specified the " + typeof(FSDirectory).Namespace + " package will be used.\n" + "\n" + "**WARNING**: -fix should only be used on an emergency basis as it will cause\n" + "documents (perhaps man y) to be permanently removed from the index. Always make\n" + "a backup copy of your index before running this! Do not run this tool on an index\n" + "that is actively being written to. You have been warned!\n" + "\n" + "Run without -fix, this tool will open the index, report version information\n" + "and report any exceptions it hits and what action it would take if -fix were\n" + "specified. With -fix, this tool will remove any segments that have issues and\n" + "write a new segments_N file. this means all documents contained in the affected\n" + "segments will be removed.\n" + "\n" + "this tool exits with exit code 1 if the index cannot be opened or has any\n" + "corruption, else 0.\n"); - Environment.Exit(1); - } - - if (!AssertsOn()) - { - Console.WriteLine("\nNOTE: testing will be more thorough if you run java with '-ea:org.apache.lucene...', so assertions are enabled"); - } - - if (onlySegments.Count == 0) - { - onlySegments = null; - } - else if (doFix) - { - Console.WriteLine("ERROR: cannot specify both -fix and -segment"); - Environment.Exit(1); - } - - Console.WriteLine("\nOpening index @ " + indexPath + "\n"); - Directory dir = null; - try - { - if (dirImpl == null) - { - dir = FSDirectory.Open(new DirectoryInfo(indexPath)); } - else + + if (!result.Clean) { - dir = CommandLineUtil.NewFSDirectory(dirImpl, new DirectoryInfo(indexPath)); + if (!doFix) + { + Console.WriteLine("WARNING: would write new segments file, and " + result.TotLoseDocCount + " documents would be lost, if index fix were specified\n"); + //Console.WriteLine("WARNING: would write new segments file, and " + result.TotLoseDocCount + " documents would be lost, if -fix were specified\n"); + } + else + { + Console.WriteLine("WARNING: " + result.TotLoseDocCount + " documents will be lost\n"); + Console.WriteLine("NOTE: will write new segments file in 5 seconds; this will remove " + result.TotLoseDocCount + " docs from the index. this IS YOUR LAST CHANCE TO CTRL+C!"); + for (int s = 0; s < 5; s++) + { + Thread.Sleep(1000); + Console.WriteLine(" " + (5 - s) + "..."); + } + Console.WriteLine("Writing..."); + checker.FixIndex(result); + Console.WriteLine("OK"); + Console.WriteLine("Wrote new segments file \"" + result.NewSegments.GetSegmentsFileName() + "\""); + } } - } - catch (Exception t) - { - Console.WriteLine("ERROR: could not open directory \"" + indexPath + "\"; exiting"); - Console.Out.WriteLine(t.StackTrace); - Environment.Exit(1); - } - - CheckIndex checker = new CheckIndex(dir); - checker.CrossCheckTermVectors = doCrossCheckTermVectors; - checker.SetInfoStream(new StreamWriter(Console.OpenStandardOutput()), verbose); + Console.WriteLine(); - Status result = checker.DoCheckIndex(onlySegments); - if (result.MissingSegments) - { - Environment.Exit(1); - } - - if (!result.Clean) - { - if (!doFix) + int exitCode; + if (result.Clean == true) { - Console.WriteLine("WARNING: would write new segments file, and " + result.TotLoseDocCount + " documents would be lost, if -fix were specified\n"); + exitCode = 0; } else { - Console.WriteLine("WARNING: " + result.TotLoseDocCount + " documents will be lost\n"); - Console.WriteLine("NOTE: will write new segments file in 5 seconds; this will remove " + result.TotLoseDocCount + " docs from the index. this IS YOUR LAST CHANCE TO CTRL+C!"); - for (int s = 0;s < 5;s++) - { - Thread.Sleep(1000); - Console.WriteLine(" " + (5 - s) + "..."); - } - Console.WriteLine("Writing..."); - checker.FixIndex(result); - Console.WriteLine("OK"); - Console.WriteLine("Wrote new segments file \"" + result.NewSegments.SegmentsFileName + "\""); - } - } - Console.WriteLine(""); - - int exitCode; - if (result.Clean == true) - { - exitCode = 0; - } - else - { - exitCode = 1; - } - Environment.Exit(exitCode); - }*/ + exitCode = 1; + } + Environment.Exit(exitCode); + } } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net/Index/IndexUpgrader.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Index/IndexUpgrader.cs b/src/Lucene.Net/Index/IndexUpgrader.cs index c99323a..9898fea 100644 --- a/src/Lucene.Net/Index/IndexUpgrader.cs +++ b/src/Lucene.Net/Index/IndexUpgrader.cs @@ -55,16 +55,18 @@ namespace Lucene.Net.Index { private static void PrintUsage() { - Console.Error.WriteLine("Upgrades an index so all segments created with a previous Lucene version are rewritten."); - Console.Error.WriteLine("Usage:"); - Console.Error.WriteLine(" java " + typeof(IndexUpgrader).Name + " [-delete-prior-commits] [-verbose] [-dir-impl X] indexDir"); - Console.Error.WriteLine("this tool keeps only the last commit in an index; for this"); - Console.Error.WriteLine("reason, if the incoming index has more than one commit, the tool"); - Console.Error.WriteLine("refuses to run by default. Specify -delete-prior-commits to override"); - Console.Error.WriteLine("this, allowing the tool to delete all but the last commit."); - Console.Error.WriteLine("Specify a " + typeof(FSDirectory).Name + " implementation through the -dir-impl option to force its use. If no package is specified the " + typeof(FSDirectory).Namespace + " package will be used."); - Console.Error.WriteLine("WARNING: this tool may reorder document IDs!"); - Environment.FailFast("1"); + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Console.Error.WriteLine("Upgrades an index so all segments created with a previous Lucene version are rewritten."); + //Console.Error.WriteLine("Usage:"); + //Console.Error.WriteLine(" java " + typeof(IndexUpgrader).Name + " [-delete-prior-commits] [-verbose] [-dir-impl X] indexDir"); + //Console.Error.WriteLine("this tool keeps only the last commit in an index; for this"); + //Console.Error.WriteLine("reason, if the incoming index has more than one commit, the tool"); + //Console.Error.WriteLine("refuses to run by default. Specify -delete-prior-commits to override"); + //Console.Error.WriteLine("this, allowing the tool to delete all but the last commit."); + //Console.Error.WriteLine("Specify a " + typeof(FSDirectory).Name + " implementation through the -dir-impl option to force its use. If no package is specified the " + typeof(FSDirectory).Namespace + " package will be used."); + //Console.Error.WriteLine("WARNING: this tool may reorder document IDs!"); + //Environment.FailFast("1"); } /// <summary> @@ -98,8 +100,9 @@ namespace Lucene.Net.Index { if (i == args.Length - 1) { - Console.WriteLine("ERROR: missing value for -dir-impl option"); - Environment.FailFast("1"); + throw new ArgumentException("ERROR: missing value for -dir option"); + //Console.WriteLine("ERROR: missing value for -dir-impl option"); + //Environment.FailFast("1"); } i++; dirImpl = args[i]; http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net/Store/LockStressTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/LockStressTest.cs b/src/Lucene.Net/Store/LockStressTest.cs index ea5c35c..341bb69 100644 --- a/src/Lucene.Net/Store/LockStressTest.cs +++ b/src/Lucene.Net/Store/LockStressTest.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Linq; using System.Net; using System.Net.Sockets; using System.Threading; @@ -37,9 +38,24 @@ namespace Lucene.Net.Store { if (args.Length != 7) { - // LUCENENET TODO: Usage depends on making this into a console application executable. - Console.WriteLine("Usage: java Lucene.Net.Store.LockStressTest myID verifierHost verifierPort lockFactoryClassName lockDirName sleepTimeMS count\n" + "\n" + " myID = int from 0 .. 255 (should be unique for test process)\n" + " verifierHost = hostname that LockVerifyServer is listening on\n" + " verifierPort = port that LockVerifyServer is listening on\n" + " lockFactoryClassName = primary LockFactory class that we will use\n" + " lockDirName = path to the lock directory (only set for Simple/NativeFSLockFactory\n" + " sleepTimeMS = milliseconds to pause betweeen each lock obtain/release\n" + " count = number of locking tries\n" + "\n" + "You should run multiple instances of this process, each with its own\n" + "unique ID, and each pointing to the same lock directory, to verify\n" + "that locking is working correctly.\n" + "\n" + "Make sure you are first running LockVerifyServer."); - Environment.FailFast("1"); + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Console.WriteLine("Usage: java Lucene.Net.Store.LockStressTest myID verifierHost verifierPort lockFactoryClassName lockDirName sleepTimeMS count\n" + + // "\n" + + // " myID = int from 0 .. 255 (should be unique for test process)\n" + + // " verifierHost = hostname that LockVerifyServer is listening on\n" + + // " verifierPort = port that LockVerifyServer is listening on\n" + + // " lockFactoryClassName = primary LockFactory class that we will use\n" + + // " lockDirName = path to the lock directory (only set for Simple/NativeFSLockFactory\n" + + // " sleepTimeMS = milliseconds to pause betweeen each lock obtain/release\n" + + // " count = number of locking tries\n" + + // "\n" + + // "You should run multiple instances of this process, each with its own\n" + + // "unique ID, and each pointing to the same lock directory, to verify\n" + + // "that locking is working correctly.\n" + + // "\n" + + // "Make sure you are first running LockVerifyServer."); + //Environment.FailFast("1"); } int arg = 0; @@ -47,24 +63,30 @@ namespace Lucene.Net.Store if (myID < 0 || myID > 255) { - Console.WriteLine("myID must be a unique int 0..255"); - Environment.Exit(1); + throw new ArgumentException("ID must be a unique int 0..255"); + //Console.WriteLine("myID must be a unique int 0..255"); + //Environment.Exit(1); } - IPHostEntry verifierHost = Dns.GetHostEntryAsync(args[arg++]).Result; + string verifierHost = args[arg++]; int verifierPort = Convert.ToInt32(args[arg++]); - IPAddress verifierIp = verifierHost.AddressList[0]; - IPEndPoint addr = new IPEndPoint(verifierIp, verifierPort); - string lockFactoryClassName = args[arg++]; string lockDirName = args[arg++]; int sleepTimeMS = Convert.ToInt32(args[arg++]); int count = Convert.ToInt32(args[arg++]); + IPAddress[] addresses = Dns.GetHostAddressesAsync(verifierHost).Result; + IPAddress addr = addresses.FirstOrDefault(); + Type c; try { c = Type.GetType(lockFactoryClassName); + if (c == null) + { + // LUCENENET: try again, this time with the Store namespace + c = Type.GetType("Lucene.Net.Store." + lockFactoryClassName); + } } catch (Exception) { @@ -99,11 +121,11 @@ namespace Lucene.Net.Store Console.WriteLine("Connecting to server " + addr + " and registering as client " + myID + "..."); using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { + socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); + socket.Connect(verifierHost, verifierPort); + using (Stream @out = new NetworkStream(socket), @in = new NetworkStream(socket)) { - socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); - socket.Connect(verifierIp, 500); - BinaryReader intReader = new BinaryReader(@in); BinaryWriter intWriter = new BinaryWriter(@out); http://git-wip-us.apache.org/repos/asf/lucenenet/blob/f0b56fd2/src/Lucene.Net/Store/LockVerifyServer.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Store/LockVerifyServer.cs b/src/Lucene.Net/Store/LockVerifyServer.cs index 6a22f8f..93a1a52 100644 --- a/src/Lucene.Net/Store/LockVerifyServer.cs +++ b/src/Lucene.Net/Store/LockVerifyServer.cs @@ -1,5 +1,6 @@ using Lucene.Net.Support.Threading; using System; +using System.Globalization; using System.IO; using System.Net; using System.Net.Sockets; @@ -41,23 +42,25 @@ namespace Lucene.Net.Store { if (args.Length != 2) { - // LUCENENET TODO: Usage depends on making this into a console application executable. - Console.WriteLine("Usage: java Lucene.Net.Store.LockVerifyServer bindToIp clients\n"); - Environment.FailFast("1"); + // LUCENENET specific - our wrapper console shows the correct usage + throw new ArgumentException(); + //Console.WriteLine("Usage: java Lucene.Net.Store.LockVerifyServer bindToIp clients\n"); + //Environment.FailFast("1"); } int arg = 0; - IPHostEntry ipHostInfo = Dns.GetHostEntryAsync(args[arg++]).Result; - IPAddress ipAddress = ipHostInfo.AddressList[0]; - IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 0); - int maxClients = Convert.ToInt32(args[arg++]); + string hostname = args[arg++]; + int maxClients = Convert.ToInt32(args[arg++], CultureInfo.InvariantCulture); + + IPAddress ipAddress = IPAddress.Parse(hostname); using (Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1); s.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 30000);// SoTimeout = 30000; // initially 30 secs to give clients enough time to startup - s.Bind(localEndPoint); + s.Bind(new IPEndPoint(ipAddress, 0)); + s.Listen(maxClients); Console.WriteLine("Listening on " + ((IPEndPoint)s.LocalEndPoint).Port.ToString() + "..."); // we set the port as a sysprop, so the ANT task can read it. For that to work, this server must run in-process:
