diff src/goodjava/lucene/backup/BackupIndexWriter.java @ 1508:86c5e7000ecf

lucene.backup checksum
author Franklin Schmidt <fschmidt@gmail.com>
date Sat, 16 May 2020 17:56:02 -0600
parents d80395468b4e
children 0ba144491a42
line wrap: on
line diff
--- a/src/goodjava/lucene/backup/BackupIndexWriter.java	Sat May 16 12:33:41 2020 +0300
+++ b/src/goodjava/lucene/backup/BackupIndexWriter.java	Sat May 16 17:56:02 2020 -0600
@@ -12,6 +12,7 @@
 import java.util.concurrent.Executors;
 import java.util.concurrent.ExecutorService;
 import javax.net.ssl.SSLSocket;
+import org.apache.lucene.search.SortField;
 import goodjava.io.IoUtils;
 import goodjava.rpc.RpcClient;
 import goodjava.rpc.RpcCall;
@@ -56,6 +57,11 @@
 		}
 	}
 
+	protected void doCheck(SortField sortField) throws IOException {
+		super.doCheck(sortField);
+		runSyncWithChecksum();
+	}
+
 	public void runSync() {
 		try {
 			exec.submit(sync).get();
@@ -64,17 +70,35 @@
 		}
 	}
 
+	public void runSyncWithChecksum() {
+		try {
+			exec.submit(syncWithChecksum).get();
+		} catch(Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
 	private final Runnable sync = new Runnable() {
 		public void run() {
 			try {
-				sync();
+				sync(false);
 			} catch(IOException e) {
 				throw new RuntimeException(e);
 			}
 		}
 	};
 
-	private void sync() throws IOException {
+	private final Runnable syncWithChecksum = new Runnable() {
+		public void run() {
+			try {
+				sync(true);
+			} catch(IOException e) {
+				throw new RuntimeException(e);
+			}
+		}
+	};
+
+	private void sync(boolean withChecksum) throws IOException {
 		List<LogFile> logs = new ArrayList<LogFile>();
 		synchronized(this) {
 			isSyncPending = false;
@@ -91,6 +115,8 @@
 			Map fileInfo = new HashMap();
 			fileInfo.put("name",log.file.getName());
 			fileInfo.put("end",log.end());
+			if( withChecksum )
+				fileInfo.put("checksum",log.checksum());
 			logInfo.add(fileInfo);
 			logMap.put(log.file.getName(),log);
 		}
@@ -105,8 +131,10 @@
 					String status = (String)result.returnValues[0];
 					if( status.equals("ok") ) {
 						break;
-					} else if( status.equals("missing") ) {
+					} else if( status.equals("missing") || status.equals("bad_checksum") ) {
 						String fileName = (String)result.returnValues[1];
+						if( status.equals("bad_checksum") )
+							logger.error("bad_checksum "+fileName);
 						LogFile log = logMap.get(fileName);
 						long len = log.end() - 8;
 						InputStream in = log.input();