Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1543:1db694d98003 | 1544:35601f15ecc3 |
---|---|
415 } finally { | 415 } finally { |
416 snapshotDeletionPolicy.release(ic); | 416 snapshotDeletionPolicy.release(ic); |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 public void tag(String tag) throws IOException { | |
421 writer.tag(tag); | |
422 } | |
423 | |
420 | 424 |
421 | 425 |
422 public String to_string() { | 426 public String to_string() { |
423 return writer.getLuceneIndexWriter().getDirectory().toString(); | 427 return writer.getLuceneIndexWriter().getDirectory().toString(); |
424 } | 428 } |
735 if( writeLock.isHeldByCurrentThread() ) | 739 if( writeLock.isHeldByCurrentThread() ) |
736 throw new RuntimeException(); | 740 throw new RuntimeException(); |
737 writeLock.lock(); | 741 writeLock.lock(); |
738 boolean ok = false; | 742 boolean ok = false; |
739 try { | 743 try { |
740 writer.deleteAll(); | 744 IndexWriter iw = writer.getLuceneIndexWriter(); |
745 iw.deleteAll(); | |
741 postgresBackup.restoreLucene(this); | 746 postgresBackup.restoreLucene(this); |
742 ok = true; | 747 ok = true; |
743 writer.commit(); | 748 iw.commit(); |
744 wrote(); | 749 wrote(); |
745 ensure_open(); // refresh searcher | 750 ensure_open(); // refresh searcher |
746 initId(); | 751 initId(); |
747 wasCreated = false; | 752 wasCreated = false; |
748 } finally { | 753 } finally { |
758 | 763 |
759 void restore(LuanTable doc) | 764 void restore(LuanTable doc) |
760 throws LuanException, IOException | 765 throws LuanException, IOException |
761 { | 766 { |
762 writer.addDocument(toLucene(doc)); | 767 writer.addDocument(toLucene(doc)); |
768 } | |
769 | |
770 public void restore_from_log() | |
771 throws IOException, LuanException, SQLException, ParseException | |
772 { | |
773 LoggingIndexWriter loggingWriter = (LoggingIndexWriter)writer; | |
774 if( wasCreated && !loggingWriter.wasCreated ) { | |
775 logger.error("restoring from log"); | |
776 force_restore_from_log(); | |
777 } | |
778 } | |
779 | |
780 public void force_restore_from_log() | |
781 throws IOException | |
782 { | |
783 logger.warn("start force_restore_from_log"); | |
784 if( writeLock.isHeldByCurrentThread() ) | |
785 throw new RuntimeException(); | |
786 writeLock.lock(); | |
787 boolean ok = false; | |
788 try { | |
789 LoggingIndexWriter loggingWriter = (LoggingIndexWriter)writer; | |
790 IndexWriter iw = writer.getLuceneIndexWriter(); | |
791 iw.deleteAll(); | |
792 loggingWriter.playLogs(null); | |
793 ok = true; | |
794 iw.commit(); | |
795 wrote(); | |
796 ensure_open(); // refresh searcher | |
797 initId(); | |
798 wasCreated = false; | |
799 } finally { | |
800 if( !ok ) { | |
801 writer.rollback(); | |
802 reopen(); | |
803 } | |
804 wrote(); | |
805 writeLock.unlock(); | |
806 } | |
807 logger.warn("end force_restore_from_log"); | |
763 } | 808 } |
764 | 809 |
765 public void check(Luan luan) throws IOException, SQLException, LuanException, ParseException { | 810 public void check(Luan luan) throws IOException, SQLException, LuanException, ParseException { |
766 boolean hasPostgres = postgresBackup != null; | 811 boolean hasPostgres = postgresBackup != null; |
767 String msg = "start check"; | 812 String msg = "start check"; |