Mercurial Hosting > luan
diff src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1484:1fa6e8ec2d53
lucene.logging cleanup
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 25 Apr 2020 11:14:25 -0600 |
parents | 7d145095cc0b |
children | 2469aa31f31b |
line wrap: on
line diff
--- a/src/goodjava/lucene/logging/LoggingIndexWriter.java Sat Apr 25 10:31:49 2020 -0600 +++ b/src/goodjava/lucene/logging/LoggingIndexWriter.java Sat Apr 25 11:14:25 2020 -0600 @@ -64,7 +64,7 @@ final int n = dis.readInt(); for( int i=0; i<n; i++ ) { File file = new File( logDir, dis.readUTF() ); - logs.add( new LogFile(file,"rwd") ); + logs.add( LogFile.newLogFile(file) ); } deleteUnusedFiles(); return; @@ -119,7 +119,7 @@ do { file = new File(logDir,"_"+rnd.nextInt(100)+".log"); } while( file.exists() ); - return new LogFile(file,"rwd"); + return LogFile.newLogFile(file); } private void deleteUnusedFiles() throws IOException { @@ -162,8 +162,8 @@ throw new RuntimeException(); Directory dir = FSDirectory.open(dirFile); LuceneIndexWriter mergeWriter = new LuceneIndexWriter( indexWriter.luceneVersion, dir, indexWriter.goodConfig ); - playLog(first,mergeWriter); - playLog(second,mergeWriter); + playLog( first.input(), mergeWriter ); + playLog( second.input(), mergeWriter ); mergeWriter.commit(); LogFile merge = newLogFile(); logLucene( lastTime, merge, mergeWriter ); @@ -208,7 +208,7 @@ public void check(SortField sortField) throws IOException { IndexReader indexReader; - List<LogFile> logs; + List<LogInputStream> logReaders; synchronized(this) { if( isMerging ) { logger.warn("is merging, check aborted"); @@ -216,10 +216,7 @@ } isMerging = true; indexReader = indexWriter.openReader(); - logs = new ArrayList<LogFile>(this.logs); - int i = logs.size() - 1; - LogFile last = logs.get(i); - logs.set(i,last.snapshot()); + logReaders = logReaders(logs); } try { logger.info("check start"); @@ -228,7 +225,7 @@ IoUtils.deleteRecursively(dirFile); Directory dir = FSDirectory.open(dirFile); LuceneIndexWriter checkWriter = new LuceneIndexWriter( indexWriter.luceneVersion, dir, indexWriter.goodConfig ); - playLogs(logs,checkWriter); + playLogs(logReaders,checkWriter); logger.info("check lucene"); IndexReader checkReader = checkWriter.openReader(); if( sortField == null ) { @@ -380,14 +377,22 @@ } public synchronized void playLogs() throws IOException { - playLogs(logs,indexWriter); + playLogs( logReaders(logs), indexWriter ); } - private static void playLogs(List<LogFile> logs,LuceneIndexWriter indexWriter) throws IOException { + private static List<LogInputStream> logReaders(List<LogFile> logs) throws IOException { + List<LogInputStream> logReaders = new ArrayList<LogInputStream>(); + for( LogFile log : logs ) { + logReaders.add( log.input() ); + } + return logReaders; + } + + private static void playLogs(List<LogInputStream> logReaders,LuceneIndexWriter indexWriter) throws IOException { if( numDocs(indexWriter) != 0 ) throw new RuntimeException ("not empty"); - for( LogFile log : logs ) { - playLog(log,indexWriter); + for( LogInputStream reader : logReaders ) { + playLog(reader,indexWriter); } indexWriter.commit(); } @@ -399,11 +404,11 @@ return n; } - private static void playLog(LogFile log,LuceneIndexWriter indexWriter) throws IOException { - LogInputStream in = log.input(); + private static void playLog(LogInputStream in,LuceneIndexWriter indexWriter) throws IOException { while( in.available() > 0 ) { playOp(in,indexWriter); } + in.close(); } private static void playOp(LogInputStream in,LuceneIndexWriter indexWriter) throws IOException {