Mercurial Hosting > luan
comparison src/goodjava/lucene/backup/BackupIndexWriter.java @ 1512:31b543826ca9
lucene.backup login
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 23 May 2020 19:01:57 -0600 |
parents | 0ba144491a42 |
children | 634f6765830e |
comparison
equal
deleted
inserted
replaced
1511:fb5be0e8ca54 | 1512:31b543826ca9 |
---|---|
26 | 26 |
27 public class BackupIndexWriter extends LoggingIndexWriter { | 27 public class BackupIndexWriter extends LoggingIndexWriter { |
28 private static final Logger logger = LoggerFactory.getLogger(BackupIndexWriter.class); | 28 private static final Logger logger = LoggerFactory.getLogger(BackupIndexWriter.class); |
29 public static String[] backupDomains; | 29 public static String[] backupDomains; |
30 private final String name; | 30 private final String name; |
31 private final String password; | |
31 private final File dir; | 32 private final File dir; |
32 private boolean isSyncPending = false; | 33 private boolean isSyncPending = false; |
33 private final ExecutorService exec = Executors.newSingleThreadExecutor(); | 34 private final ExecutorService exec = Executors.newSingleThreadExecutor(); |
34 | 35 |
35 public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,String name) throws IOException { | 36 public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,String name,String password) throws IOException { |
36 super(indexWriter,logDir); | 37 super(indexWriter,logDir); |
37 if( backupDomains == null ) | 38 if( backupDomains == null ) |
38 throw new RuntimeException("must set backupDomains"); | 39 throw new RuntimeException("must set backupDomains"); |
39 this.name = name; | 40 this.name = name; |
41 this.password = password; | |
40 File f = new File(System.getProperty("java.io.tmpdir")); | 42 File f = new File(System.getProperty("java.io.tmpdir")); |
41 dir = new File(f,"goodjava.lucene/"+name); | 43 dir = new File(f,"goodjava.lucene/"+name); |
42 IoUtils.mkdirs(dir); | 44 IoUtils.mkdirs(dir); |
43 } | 45 } |
44 | 46 |
119 logInfo.add(fileInfo); | 121 logInfo.add(fileInfo); |
120 logMap.put(log.file.getName(),log); | 122 logMap.put(log.file.getName(),log); |
121 } | 123 } |
122 for( String backupDomain : backupDomains ) { | 124 for( String backupDomain : backupDomains ) { |
123 RpcClient rpc = BackupServer.rpcClient(backupDomain); | 125 RpcClient rpc = BackupServer.rpcClient(backupDomain); |
124 RpcCall call = new RpcCall("check",name,logInfo); | |
125 try { | 126 try { |
127 RpcCall call = new RpcCall("login",name,password); | |
128 rpc.write(call); | |
129 rpc.read(); | |
130 call = new RpcCall("check",logInfo); | |
126 while(true) { | 131 while(true) { |
127 rpc.write(call); | 132 rpc.write(call); |
128 RpcResult result = rpc.read(); | 133 RpcResult result = rpc.read(); |
129 logger.info(Arrays.asList(result.returnValues).toString()); | 134 //logger.info(Arrays.asList(result.returnValues).toString()); |
130 String status = (String)result.returnValues[0]; | 135 String status = (String)result.returnValues[0]; |
131 if( status.equals("ok") ) { | 136 if( status.equals("ok") ) { |
132 break; | 137 break; |
133 } else if( status.equals("missing") || status.equals("bad_checksum") ) { | 138 } else if( status.equals("missing") || status.equals("bad_checksum") ) { |
134 String fileName = (String)result.returnValues[1]; | 139 String fileName = (String)result.returnValues[1]; |
135 if( status.equals("bad_checksum") ) | 140 if( status.equals("bad_checksum") ) |
136 logger.error("bad_checksum "+fileName); | 141 logger.error("bad_checksum "+fileName); |
137 LogFile log = logMap.get(fileName); | 142 LogFile log = logMap.get(fileName); |
138 long len = log.end() - 8; | 143 long len = log.end() - 8; |
139 InputStream in = log.input(); | 144 InputStream in = log.input(); |
140 call = new RpcCall(in,len,"add",name,logInfo,fileName); | 145 call = new RpcCall(in,len,"add",logInfo,fileName); |
141 } else if( status.equals("incomplete") ) { | 146 } else if( status.equals("incomplete") ) { |
142 String fileName = (String)result.returnValues[1]; | 147 String fileName = (String)result.returnValues[1]; |
143 long logEnd = (Long)result.returnValues[2]; | 148 long logEnd = (Long)result.returnValues[2]; |
144 LogFile log = logMap.get(fileName); | 149 LogFile log = logMap.get(fileName); |
145 long len = log.end() - logEnd; | 150 long len = log.end() - logEnd; |
146 InputStream in = log.input(); | 151 InputStream in = log.input(); |
147 in.skip(logEnd-8); | 152 in.skip(logEnd-8); |
148 call = new RpcCall(in,len,"append",name,logInfo,fileName); | 153 call = new RpcCall(in,len,"append",logInfo,fileName); |
149 } else | 154 } else |
150 throw new RuntimeException("status "+status); | 155 throw new RuntimeException("status "+status); |
151 } | 156 } |
152 } catch(RpcException e) { | 157 } catch(RpcException e) { |
153 logger.warn("",e); | 158 logger.warn("",e); |