/** * Writes a backup to the specified stream. * * @param os the stream to write to */ public void backup(OutputStream os) throws IOException { int count = 0; GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(os); for (Master master : mRegistry.getServers()) { Iterator<JournalEntry> it = master.getJournalEntryIterator(); while (it.hasNext()) { it.next().toBuilder().clearSequenceNumber().build().writeDelimitedTo(zipStream); count++; } } // finish() instead of close() since close would close os, which is owned by the caller. zipStream.finish(); LOG.info("Created backup with {} entries", count); }
/** * Restores master state from the specified backup. * * @param is an input stream to read from the backup */ public void initFromBackup(InputStream is) throws IOException { int count = 0; try (GzipCompressorInputStream gzIn = new GzipCompressorInputStream(is); JournalEntryStreamReader reader = new JournalEntryStreamReader(gzIn)) { List<Master> masters = mRegistry.getServers(); JournalEntry entry; Map<String, Master> mastersByName = Maps.uniqueIndex(masters, Master::getName); while ((entry = reader.readEntry()) != null) { String masterName = JournalEntryAssociation.getMasterForEntry(entry); Master master = mastersByName.get(masterName); master.processJournalEntry(entry); try (JournalContext jc = master.createJournalContext()) { jc.append(entry); count++; } } } LOG.info("Restored {} entries from backup", count); } }
/** * Starts the gRPC server. The AlluxioMaster registers the Services of registered * {@link Master}s and meta services. */ protected void startServingRPCServer() { // TODO(ggezer) Executor threads not reused until thread capacity is hit. // ExecutorService executorService = Executors.newFixedThreadPool(mMaxWorkerThreads); try { SocketAddress bindAddress = getRpcAddressFromBindSocket(); LOG.info("Starting gRPC server on address {}", bindAddress); GrpcServerBuilder serverBuilder = GrpcServerBuilder.forAddress(bindAddress, ServerConfiguration.global()); for (Master master : mRegistry.getServers()) { registerServices(serverBuilder, master.getServices()); } mGrpcServer = serverBuilder.build().start(); mSafeModeManager.notifyRpcServerStarted(); LOG.info("Started gRPC server on address {}", bindAddress); // Wait until the server is shut down. mGrpcServer.awaitTermination(); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Writes a backup to the specified stream. * * @param os the stream to write to */ public void backup(OutputStream os) throws IOException { int count = 0; GzipCompressorOutputStream zipStream = new GzipCompressorOutputStream(os); for (Master master : mRegistry.getServers()) { Iterator<JournalEntry> it = master.getJournalEntryIterator(); while (it.hasNext()) { it.next().toBuilder().clearSequenceNumber().build().writeDelimitedTo(zipStream); count++; } } // finish() instead of close() since close would close os, which is owned by the caller. zipStream.finish(); LOG.info("Created backup with {} entries", count); }
/** * Restores master state from the specified backup. * * @param is an input stream to read from the backup */ public void initFromBackup(InputStream is) throws IOException { int count = 0; try (GzipCompressorInputStream gzIn = new GzipCompressorInputStream(is); JournalEntryStreamReader reader = new JournalEntryStreamReader(gzIn)) { List<Master> masters = mRegistry.getServers(); JournalEntry entry; Map<String, Master> mastersByName = Maps.uniqueIndex(masters, Master::getName); while ((entry = reader.readEntry()) != null) { String masterName = JournalEntryAssociation.getMasterForEntry(entry); Master master = mastersByName.get(masterName); master.processJournalEntry(entry); try (JournalContext jc = master.createJournalContext()) { jc.append(entry); count++; } } } LOG.info("Restored {} entries from backup", count); } }
for (Master master : mRegistry.getServers()) { registerServices(processor, master.getServices());