Mercurial Hosting > luan
comparison src/goodjava/lucene/backup/BackupIndexWriter.java @ 1690:973d3039c421
backup server checks client domain
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 12 Jun 2022 20:13:24 -0600 |
parents | 445048f9eca7 |
children | 1578324d2aac |
comparison
equal
deleted
inserted
replaced
1689:af22d6c120e4 | 1690:973d3039c421 |
---|---|
30 | 30 |
31 | 31 |
32 public final class BackupIndexWriter extends LoggingIndexWriter { | 32 public final class BackupIndexWriter extends LoggingIndexWriter { |
33 private static final Logger logger = LoggerFactory.getLogger(BackupIndexWriter.class); | 33 private static final Logger logger = LoggerFactory.getLogger(BackupIndexWriter.class); |
34 public static String[] backupDomains; | 34 public static String[] backupDomains; |
35 private final String domain; | |
35 private final String name; | 36 private final String name; |
36 private final File dir; | 37 private final File dir; |
37 private boolean isSyncPending = false; | 38 private boolean isSyncPending = false; |
38 private final ExecutorService exec = Executors.newSingleThreadExecutor(); | 39 private final ExecutorService exec = Executors.newSingleThreadExecutor(); |
39 | 40 |
40 public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,long logTime,String name) | 41 public BackupIndexWriter(LuceneIndexWriter indexWriter,File logDir,long logTime,String domain,String name) |
41 throws IOException | 42 throws IOException |
42 { | 43 { |
43 super(indexWriter,logDir,logTime); | 44 super(indexWriter,logDir,logTime); |
44 if( backupDomains == null ) | 45 if( backupDomains == null ) |
45 throw new RuntimeException("must set backupDomains"); | 46 throw new RuntimeException("must set backupDomains"); |
47 this.domain = domain; | |
46 this.name = name; | 48 this.name = name; |
47 File f = new File(System.getProperty("java.io.tmpdir")); | 49 File f = new File(System.getProperty("java.io.tmpdir")); |
48 dir = new File(f,"goodjava.lucene/"+name); | 50 dir = new File(f,"goodjava.lucene/"+domain+"~"+name); |
49 IoUtils.mkdirs(dir); | 51 IoUtils.mkdirs(dir); |
50 } | 52 } |
51 | 53 |
52 @Override public synchronized void close() throws IOException { | 54 @Override public synchronized void close() throws IOException { |
53 super.close(); | 55 super.close(); |
138 logMap.put(log.file.getName(),log); | 140 logMap.put(log.file.getName(),log); |
139 } | 141 } |
140 for( String backupDomain : backupDomains ) { | 142 for( String backupDomain : backupDomains ) { |
141 RpcClient rpc = BackupServer.rpcClient(backupDomain); | 143 RpcClient rpc = BackupServer.rpcClient(backupDomain); |
142 try { | 144 try { |
143 RpcCall call = new RpcCall("login",name); | 145 RpcCall call = new RpcCall("login",domain,name); |
144 rpc.write(call); | 146 rpc.write(call); |
145 rpc.read(); | 147 rpc.read(); |
146 call = new RpcCall("check",logInfo); | 148 call = new RpcCall("check",logInfo); |
147 while(true) { | 149 while(true) { |
148 rpc.write(call); | 150 rpc.write(call); |
184 for( File f : dir.listFiles() ) { | 186 for( File f : dir.listFiles() ) { |
185 IoUtils.delete(f); | 187 IoUtils.delete(f); |
186 } | 188 } |
187 } | 189 } |
188 | 190 |
189 public static BackupIndexWriter newWithRestore(LuceneIndexWriter indexWriter,File logDir,long logTime,String name) | 191 public static BackupIndexWriter newWithRestore(LuceneIndexWriter indexWriter,File logDir,long logTime,String domain,String name) |
190 throws IOException | 192 throws IOException |
191 { | 193 { |
192 if( !logDir.exists() ) { | 194 if( !logDir.exists() ) { |
193 RpcClient rpc = BackupServer.rpcClient(backupDomains[0]); | 195 RpcClient rpc = BackupServer.rpcClient(backupDomains[0]); |
194 try { | 196 try { |
195 RpcCall call; | 197 RpcCall call; |
196 RpcResult result; | 198 RpcResult result; |
197 call = new RpcCall("exists",name); | 199 call = new RpcCall("exists",domain,name); |
198 rpc.write(call); | 200 rpc.write(call); |
199 result = rpc.read(); | 201 result = rpc.read(); |
200 boolean exists = (Boolean)result.returnValues[0]; | 202 boolean exists = (Boolean)result.returnValues[0]; |
201 if( exists ) { | 203 if( exists ) { |
202 logger.error("restoring "+logDir+" from backup"); | 204 logger.error("restoring "+logDir+" from backup"); |
203 File zip = File.createTempFile("luan_",".zip"); | 205 File zip = File.createTempFile("luan_",".zip"); |
204 IoUtils.delete(zip); | 206 IoUtils.delete(zip); |
205 call = new RpcCall("login",name); | 207 call = new RpcCall("login",domain,name); |
206 rpc.write(call); | 208 rpc.write(call); |
207 rpc.read(); | 209 rpc.read(); |
208 call = new RpcCall("zip"); | 210 call = new RpcCall("zip"); |
209 rpc.write(call); | 211 rpc.write(call); |
210 result = rpc.read(); | 212 result = rpc.read(); |
220 } catch(RpcException e) { | 222 } catch(RpcException e) { |
221 throw new RuntimeException(e); | 223 throw new RuntimeException(e); |
222 } | 224 } |
223 rpc.close(); | 225 rpc.close(); |
224 } | 226 } |
225 return new BackupIndexWriter(indexWriter,logDir,logTime,name); | 227 return new BackupIndexWriter(indexWriter,logDir,logTime,domain,name); |
226 } | 228 } |
227 | 229 |
228 } | 230 } |