changeset 1390:179c4882c6b6

backup work
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 04 Sep 2019 00:06:42 -0600
parents eb8b35dccd99
children 94f48cc76de8
files src/luan/modules/lucene/LuceneIndex.java
diffstat 1 files changed, 13 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan/modules/lucene/LuceneIndex.java	Tue Sep 03 22:54:31 2019 -0600
+++ b/src/luan/modules/lucene/LuceneIndex.java	Wed Sep 04 00:06:42 2019 -0600
@@ -176,23 +176,32 @@
 			analyzer = sfp.analyzer;
 		}
 		this.analyzer = analyzer;
-		reopen();
+		boolean wasCreated = reopen();
 		postgresBackup = completer!=null ? PostgresBackup.newInstance() : null;
-		if( postgresBackup != null && postgresBackup.wasCreated )
-			rebuild_postgres_backup(completer);
+		if( postgresBackup != null ) {
+			if( !wasCreated && postgresBackup.wasCreated ) {
+				logger.error("rebuilding postgres backup");
+				rebuild_postgres_backup(completer);
+			} else if( wasCreated && !postgresBackup.wasCreated ) {
+				logger.error("restoring from postgres");
+				restore_from_postgres();
+			}
+		}
 	}
 
-	public void reopen() throws IOException {
+	public boolean reopen() throws IOException {
 		IndexWriterConfig conf = new IndexWriterConfig(version,analyzer);
 		snapshotDeletionPolicy = new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy());
 		conf.setIndexDeletionPolicy(snapshotDeletionPolicy);
 		FSDirectory dir = FSDirectory.open(indexDir);
 		fileDir = dir.getDirectory();
+		boolean wasCreated = !fileDir.exists();
 		writer = new IndexWriter(dir,conf);
 		writer.commit();  // commit index creation
 		reader = DirectoryReader.open(dir);
 		searcher = new IndexSearcher(reader);
 		initId();
+		return wasCreated;
 	}
 
 	private void wrote() {