Mercurial Hosting > luan
comparison src/goodjava/lucene/logging/LoggingIndexWriter.java @ 1556:52241b69c339
lucene logging
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Sun, 11 Oct 2020 17:28:16 -0600 |
| parents | 9cc4cee39b8b |
| children | ea7075b7afe1 |
comparison
equal
deleted
inserted
replaced
| 1555:1b397a949791 | 1556:52241b69c339 |
|---|---|
| 79 } | 79 } |
| 80 } finally { | 80 } finally { |
| 81 dis.close(); | 81 dis.close(); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 newLogs(); | 84 logger.info("building new logs"); |
| 85 for( int i=0; i<logs.length; i++ ) { | |
| 86 logs[i] = newLogFile(); | |
| 87 } | |
| 88 LogOutputStream log = logs[0].output(); | |
| 89 logLucene( System.currentTimeMillis(), log, indexWriter ); | |
| 90 log.close(); | |
| 91 writeIndex(); | |
| 92 setLog(); | |
| 93 logger.info("done building new logs"); | |
| 85 wasCreated = true; | 94 wasCreated = true; |
| 86 } | 95 } |
| 87 | 96 |
| 88 public IndexReader openReader() throws IOException { | 97 public IndexReader openReader() throws IOException { |
| 89 return indexWriter.openReader(); | 98 return indexWriter.openReader(); |
| 110 } catch(InterruptedException e) { | 119 } catch(InterruptedException e) { |
| 111 throw new RuntimeException(e); | 120 throw new RuntimeException(e); |
| 112 } | 121 } |
| 113 } | 122 } |
| 114 | 123 |
| 115 public synchronized void newLogs() throws IOException { | |
| 116 getMergeLock(); | |
| 117 try { | |
| 118 newLogs2(); | |
| 119 } finally { | |
| 120 mergeLock.unlock(); | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 private void newLogs2() throws IOException { | |
| 125 logger.info("building new logs"); | |
| 126 for( int i=0; i<logs.length; i++ ) { | |
| 127 logs[i] = newLogFile(); | |
| 128 } | |
| 129 LogOutputStream log = logs[0].output(); | |
| 130 logLucene( System.currentTimeMillis(), log, indexWriter ); | |
| 131 log.close(); | |
| 132 writeIndex(); | |
| 133 setLog(); | |
| 134 logger.info("done building new logs"); | |
| 135 } | |
| 136 | |
| 137 public synchronized void logLucene() | 124 public synchronized void logLucene() |
| 138 throws IOException | 125 throws IOException |
| 139 { | 126 { |
| 140 //log.rollback(); ? | |
| 141 logLucene( System.currentTimeMillis(), log, indexWriter ); | 127 logLucene( System.currentTimeMillis(), log, indexWriter ); |
| 142 } | 128 } |
| 143 | 129 |
| 144 private static void logLucene(long time,LogOutputStream log,LuceneIndexWriter indexWriter) | 130 private static void logLucene(long time,LogOutputStream log,LuceneIndexWriter indexWriter) |
| 145 throws IOException | 131 throws IOException |
| 463 } | 449 } |
| 464 | 450 |
| 465 private static void playLogs(LogInputStream[] logReaders,OpDoer opDoer) | 451 private static void playLogs(LogInputStream[] logReaders,OpDoer opDoer) |
| 466 throws IOException | 452 throws IOException |
| 467 { | 453 { |
| 468 if( numDocs(opDoer.writer()) != 0 ) | |
| 469 throw new RuntimeException ("not empty"); | |
| 470 for( LogInputStream reader : logReaders ) { | 454 for( LogInputStream reader : logReaders ) { |
| 471 playLog(reader,opDoer); | 455 playLog(reader,opDoer); |
| 472 } | 456 } |
| 473 opDoer.commit(); | 457 opDoer.commit(); |
| 474 } | |
| 475 | |
| 476 private static int numDocs(GoodIndexWriter indexWriter) throws IOException { | |
| 477 IndexReader reader = indexWriter.openReader(); | |
| 478 int n = reader.numDocs(); | |
| 479 reader.close(); | |
| 480 return n; | |
| 481 } | 458 } |
| 482 | 459 |
| 483 private static void playLog(LogInputStream in,OpDoer opDoer) | 460 private static void playLog(LogInputStream in,OpDoer opDoer) |
| 484 throws IOException | 461 throws IOException |
| 485 { | 462 { |
