Mercurial Hosting > luan
diff src/luan/modules/lucene/LuceneIndex.java @ 1544:35601f15ecc3
add lucene log tag and restore_from_log
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 20 Sep 2020 20:36:55 -0600 |
parents | 1db694d98003 |
children | 736ec76bbf42 |
line wrap: on
line diff
--- a/src/luan/modules/lucene/LuceneIndex.java Sun Sep 20 16:45:31 2020 -0600 +++ b/src/luan/modules/lucene/LuceneIndex.java Sun Sep 20 20:36:55 2020 -0600 @@ -417,6 +417,10 @@ } } + public void tag(String tag) throws IOException { + writer.tag(tag); + } + public String to_string() { @@ -737,10 +741,11 @@ writeLock.lock(); boolean ok = false; try { - writer.deleteAll(); + IndexWriter iw = writer.getLuceneIndexWriter(); + iw.deleteAll(); postgresBackup.restoreLucene(this); ok = true; - writer.commit(); + iw.commit(); wrote(); ensure_open(); // refresh searcher initId(); @@ -762,6 +767,46 @@ writer.addDocument(toLucene(doc)); } + public void restore_from_log() + throws IOException, LuanException, SQLException, ParseException + { + LoggingIndexWriter loggingWriter = (LoggingIndexWriter)writer; + if( wasCreated && !loggingWriter.wasCreated ) { + logger.error("restoring from log"); + force_restore_from_log(); + } + } + + public void force_restore_from_log() + throws IOException + { + logger.warn("start force_restore_from_log"); + if( writeLock.isHeldByCurrentThread() ) + throw new RuntimeException(); + writeLock.lock(); + boolean ok = false; + try { + LoggingIndexWriter loggingWriter = (LoggingIndexWriter)writer; + IndexWriter iw = writer.getLuceneIndexWriter(); + iw.deleteAll(); + loggingWriter.playLogs(null); + ok = true; + iw.commit(); + wrote(); + ensure_open(); // refresh searcher + initId(); + wasCreated = false; + } finally { + if( !ok ) { + writer.rollback(); + reopen(); + } + wrote(); + writeLock.unlock(); + } + logger.warn("end force_restore_from_log"); + } + public void check(Luan luan) throws IOException, SQLException, LuanException, ParseException { boolean hasPostgres = postgresBackup != null; String msg = "start check";