public int dump(String filenameOrDirectory, PrintStream out, TimeZone timeZone) throws IOException { int logsFound = 0; for (String fileName : filenamesOf(filenameOrDirectory, getLogPrefix())) { logsFound++; out.println("=== " + fileName + " ==="); StoreChannel fileChannel = fileSystem.open(new File(fileName), "r"); ByteBuffer buffer = ByteBuffer.allocateDirect(9 + Xid.MAXGTRIDSIZE + Xid.MAXBQUALSIZE * 10); long logVersion, prevLastCommittedTx; try { long[] header = VersionAwareLogEntryReader.readLogHeader(buffer, fileChannel, false); logVersion = header[0]; prevLastCommittedTx = header[1]; } catch (IOException ex) { out.println("Unable to read timestamp information, no records in logical log."); out.println(ex.getMessage()); fileChannel.close(); throw ex; } out.println( "Logical log version: " + logVersion + " with prev committed tx[" + prevLastCommittedTx + "]"); LogDeserializer deserializer = new LogDeserializer(buffer, instantiateCommandReaderFactory()); PrintingConsumer consumer = new PrintingConsumer(out, timeZone); try (Cursor<LogEntry, IOException> cursor = deserializer.cursor(fileChannel)) { while (cursor.next(consumer)) ; } } return logsFound; }
/** @return a {@link RequestContext} specifying at which point the store copy started. */ public RequestContext flushStoresAndStreamStoreFiles(StoreWriter writer, boolean includeLogs) { try { long lastAppliedTransaction = transactionIdStore.getLastClosedTransactionId(); monitor.startFlushingEverything(); logRotationControl.forceEverything(); monitor.finishFlushingEverything(); ByteBuffer temporaryBuffer = ByteBuffer.allocateDirect(1024 * 1024); // Copy the store files monitor.startStreamingStoreFiles(); try (ResourceIterator<File> files = dataSource.listStoreFiles(includeLogs)) { while (files.hasNext()) { File file = files.next(); try (StoreChannel fileChannel = fileSystem.open(file, "r")) { monitor.startStreamingStoreFile(file); writer.write( relativePath(storeDirectory, file), fileChannel, temporaryBuffer, file.length() > 0); monitor.finishStreamingStoreFile(file); } } } finally { monitor.finishStreamingStoreFiles(); } return anonymous(lastAppliedTransaction); } catch (IOException e) { throw new ServerFailureException(e); } }
public boolean recoveryNeededAt(File dataDir, long currentLogVersion) throws IOException { // We need config to determine where the logical log files are File neoStorePath = new File(dataDir, NeoStore.DEFAULT_NAME); if (!fs.fileExists(neoStorePath)) { // No database in the specified directory. return false; } PhysicalLogFiles logFiles = new PhysicalLogFiles(dataDir, fs); File log = logFiles.getLogFileForVersion(currentLogVersion); if (!fs.fileExists(log)) { // This most likely means that the db has been cleanly shut down, i.e. force then inc log // version, // then NOT creating a new log file (will be done the next startup) return false; } try (StoreChannel logChannel = fs.open(log, "r")) { return LogRecoveryCheck.recoveryRequired(logChannel); } }