Mercurial Hosting > luan
diff src/goodjava/lucene/backup/BackupIndexWriter.java @ 1672:8dd8c556c449
backup work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 26 May 2022 21:10:02 -0600 |
parents | 736ec76bbf42 |
children | 1b9f9fdb3b41 |
line wrap: on
line diff
--- a/src/goodjava/lucene/backup/BackupIndexWriter.java Thu May 12 10:56:45 2022 -0600 +++ b/src/goodjava/lucene/backup/BackupIndexWriter.java Thu May 26 21:10:02 2022 -0600 @@ -4,6 +4,7 @@ import java.io.InputStream; import java.io.IOException; import java.net.Socket; +import java.net.ConnectException; import java.util.List; import java.util.ArrayList; import java.util.Map; @@ -11,6 +12,7 @@ import java.util.Arrays; import java.util.concurrent.Executors; import java.util.concurrent.ExecutorService; +import java.util.concurrent.ExecutionException; import org.apache.lucene.search.SortField; import goodjava.io.IoUtils; import goodjava.rpc.RpcClient; @@ -18,13 +20,13 @@ import goodjava.rpc.RpcResult; import goodjava.rpc.RpcException; import goodjava.lucene.api.LuceneIndexWriter; -import goodjava.logging.Logger; -import goodjava.logging.LoggerFactory; import goodjava.lucene.logging.LoggingIndexWriter; import goodjava.lucene.logging.LogFile; +import goodjava.logging.Logger; +import goodjava.logging.LoggerFactory; -public class BackupIndexWriter extends LoggingIndexWriter { +public final class BackupIndexWriter extends LoggingIndexWriter { private static final Logger logger = LoggerFactory.getLogger(BackupIndexWriter.class); public static String[] backupDomains; private final String name; @@ -46,12 +48,12 @@ IoUtils.mkdirs(dir); } - public synchronized void close() throws IOException { + @Override public synchronized void close() throws IOException { super.close(); exec.shutdown(); } - public synchronized void commit() throws IOException { + @Override public synchronized void commit() throws IOException { super.commit(); //sync(); if( !isSyncPending ) { @@ -60,7 +62,7 @@ } } - protected boolean doCheck(SortField sortField) throws IOException { + @Override protected boolean doCheck(SortField sortField) throws IOException { boolean ok = super.doCheck(sortField); if( ok ) runSyncWithChecksum(); @@ -68,17 +70,22 @@ } public void runSync() { - try { - exec.submit(sync).get(); - } catch(Exception e) { - throw new RuntimeException(e); - } + exec(sync); } public void runSyncWithChecksum() { + exec(syncWithChecksum); + } + + private void exec(Runnable r) { try { - exec.submit(syncWithChecksum).get(); - } catch(Exception e) { + exec.submit(r).get(); + } catch(InterruptedException e) { + throw new RuntimeException(e); + } catch(ExecutionException e) { + Throwable cause = e.getCause(); + if( cause instanceof RuntimeException ) + throw (RuntimeException)cause; throw new RuntimeException(e); } } @@ -87,6 +94,8 @@ public void run() { try { sync(false); + } catch(ConnectException e) { + logger.error("sync failed: "+e.getMessage()); } catch(IOException e) { throw new RuntimeException(e); } @@ -97,6 +106,8 @@ public void run() { try { sync(true); + } catch(ConnectException e) { + logger.error("syncWithChecksum failed: "+e.getMessage()); } catch(IOException e) { throw new RuntimeException(e); } @@ -159,7 +170,7 @@ throw new RuntimeException("status "+status); } } catch(RpcException e) { - logger.warn("",e); + logger.error("",e); } rpc.close(); }