Mercurial Hosting > luan
comparison src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1551:9cc4cee39b8b
add LuanOpDoer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 04 Oct 2020 16:29:54 -0600 |
parents | 41c32da4cbd1 |
children | 52241b69c339 |
comparison
equal
deleted
inserted
replaced
1550:0dc3be25ad20 | 1551:9cc4cee39b8b |
---|---|
221 File dirFile = new File(logDir,"merge"); | 221 File dirFile = new File(logDir,"merge"); |
222 if( dirFile.exists() ) | 222 if( dirFile.exists() ) |
223 throw new RuntimeException(); | 223 throw new RuntimeException(); |
224 Directory dir = FSDirectory.open(dirFile); | 224 Directory dir = FSDirectory.open(dirFile); |
225 LuceneIndexWriter mergeWriter = new LuceneIndexWriter( dir, indexWriter.goodConfig ); | 225 LuceneIndexWriter mergeWriter = new LuceneIndexWriter( dir, indexWriter.goodConfig ); |
226 OpDoer opDoer = new OpDoer(mergeWriter); | 226 OpDoer opDoer = new BasicOpDoer(mergeWriter); |
227 playLog( first.input(), opDoer ); | 227 playLog( first.input(), opDoer ); |
228 playLog( second.input(), opDoer ); | 228 playLog( second.input(), opDoer ); |
229 mergeWriter.commit(); | 229 mergeWriter.commit(); |
230 LogFile merge = newLogFile(); | 230 LogFile merge = newLogFile(); |
231 LogOutputStream log = merge.output(); | 231 LogOutputStream log = merge.output(); |
298 indexWriter.check(); | 298 indexWriter.check(); |
299 File dirFile = new File(logDir,"check"); | 299 File dirFile = new File(logDir,"check"); |
300 IoUtils.deleteRecursively(dirFile); | 300 IoUtils.deleteRecursively(dirFile); |
301 Directory dir = FSDirectory.open(dirFile); | 301 Directory dir = FSDirectory.open(dirFile); |
302 LuceneIndexWriter checkWriter = new LuceneIndexWriter( dir, indexWriter.goodConfig ); | 302 LuceneIndexWriter checkWriter = new LuceneIndexWriter( dir, indexWriter.goodConfig ); |
303 playLogs(logReaders,new OpDoer(checkWriter)); | 303 playLogs(logReaders,new BasicOpDoer(checkWriter)); |
304 //logger.info("check lucene"); | 304 //logger.info("check lucene"); |
305 IndexReader checkReader = checkWriter.openReader(); | 305 IndexReader checkReader = checkWriter.openReader(); |
306 int nCheck = checkReader.numDocs(); | 306 int nCheck = checkReader.numDocs(); |
307 int nOrig = indexReader.numDocs(); | 307 int nOrig = indexReader.numDocs(); |
308 if( nCheck != nOrig ) { | 308 if( nCheck != nOrig ) { |
446 private void writeOp(int op) throws IOException { | 446 private void writeOp(int op) throws IOException { |
447 log.writeLong(System.currentTimeMillis()); | 447 log.writeLong(System.currentTimeMillis()); |
448 log.writeByte(op); | 448 log.writeByte(op); |
449 } | 449 } |
450 | 450 |
451 // return whether stopped at tag | |
452 public synchronized void playLogs(OpDoer opDoer) throws IOException { | 451 public synchronized void playLogs(OpDoer opDoer) throws IOException { |
453 if( opDoer == null ) | 452 if( opDoer == null ) |
454 opDoer = new OpDoer(indexWriter); | 453 opDoer = new BasicOpDoer(indexWriter); |
455 playLogs( logReaders(logs), opDoer ); | 454 playLogs( logReaders(logs), opDoer ); |
456 } | 455 } |
457 | 456 |
458 private static LogInputStream[] logReaders(LogFile[] logs) throws IOException { | 457 private static LogInputStream[] logReaders(LogFile[] logs) throws IOException { |
459 LogInputStream[] logReaders = new LogInputStream[logs.length]; | 458 LogInputStream[] logReaders = new LogInputStream[logs.length]; |
464 } | 463 } |
465 | 464 |
466 private static void playLogs(LogInputStream[] logReaders,OpDoer opDoer) | 465 private static void playLogs(LogInputStream[] logReaders,OpDoer opDoer) |
467 throws IOException | 466 throws IOException |
468 { | 467 { |
469 if( numDocs(opDoer.writer) != 0 ) | 468 if( numDocs(opDoer.writer()) != 0 ) |
470 throw new RuntimeException ("not empty"); | 469 throw new RuntimeException ("not empty"); |
471 for( LogInputStream reader : logReaders ) { | 470 for( LogInputStream reader : logReaders ) { |
472 playLog(reader,opDoer); | 471 playLog(reader,opDoer); |
473 } | 472 } |
474 opDoer.commit(); | 473 opDoer.commit(); |