@Override public void init() { txThreadMap = new ArrayMap<Thread, TransactionImpl>((byte) 5, true, true); logSwitcherFileName = txLogDir + separator + "active_tx_log"; txLog1FileName = "tm_tx_log.1"; txLog2FileName = "tm_tx_log.2"; try { if (fileSystem.fileExists(logSwitcherFileName)) { FileChannel fc = fileSystem.open(logSwitcherFileName, "rw"); byte fileName[] = new byte[256]; ByteBuffer buf = ByteBuffer.wrap(fileName); fc.read(buf); fc.close(); String currentTxLog = txLogDir + separator + UTF8.decode(fileName).trim(); if (!fileSystem.fileExists(currentTxLog)) { throw logAndReturn( "TM startup failure", new TransactionFailureException( "Unable to start TM, " + "active tx log file[" + currentTxLog + "] not found.")); } txLog = new TxLog(currentTxLog, fileSystem, msgLog); msgLog.logMessage("TM opening log: " + currentTxLog, true); } else { if (fileSystem.fileExists(txLogDir + separator + txLog1FileName) || fileSystem.fileExists(txLogDir + separator + txLog2FileName)) { throw logAndReturn( "TM startup failure", new TransactionFailureException( "Unable to start TM, " + "no active tx log file found but found either " + txLog1FileName + " or " + txLog2FileName + " file, please set one of them as active or " + "remove them.")); } ByteBuffer buf = ByteBuffer.wrap(txLog1FileName.getBytes("UTF-8")); FileChannel fc = fileSystem.open(logSwitcherFileName, "rw"); fc.write(buf); txLog = new TxLog(txLogDir + separator + txLog1FileName, fileSystem, msgLog); msgLog.logMessage("TM new log: " + txLog1FileName, true); fc.force(true); fc.close(); } tmOk = true; } catch (IOException e) { log.log(Level.SEVERE, "Unable to start TM", e); throw logAndReturn( "TM startup failure", new TransactionFailureException("Unable to start TM", e)); } }
public boolean storeFilesUpgradeable(File neoStoreFile) { File storeDirectory = neoStoreFile.getParentFile(); for (String fileName : fileNamesToExpectedVersions.keySet()) { String expectedVersion = fileNamesToExpectedVersions.get(fileName); FileChannel fileChannel = null; byte[] expectedVersionBytes = UTF8.encode(expectedVersion); try { File storeFile = new File(storeDirectory, fileName); if (!fs.fileExists(storeFile)) { return false; } fileChannel = fs.open(storeFile, "r"); if (fileChannel.size() < expectedVersionBytes.length) { return false; } fileChannel.position(fileChannel.size() - expectedVersionBytes.length); byte[] foundVersionBytes = new byte[expectedVersionBytes.length]; fileChannel.read(ByteBuffer.wrap(foundVersionBytes)); if (!expectedVersion.equals(UTF8.decode(foundVersionBytes))) { return false; } } catch (IOException e) { throw new RuntimeException(e); } finally { if (fileChannel != null) { try { fileChannel.close(); } catch (IOException e) { // Ignore exception on close } } } } return true; }
private int logCount() { XaLogicalLog log = neoDataSource().getXaContainer().getLogicalLog(); int count = 0; for (long i = log.getHighestLogVersion() - 1; i >= 0; i--) { if (fs.fileExists(log.getFileName(i))) { count++; } else { break; } } return count; }
private File fixPath(File dir, StoreFactory sf) { try { fileSystem.mkdirs(dir); } catch (IOException e) { throw new UnderlyingStorageException( "Unable to create directory path[" + storeDir + "] for Neo4j kernel store."); } File store = new File(dir, NeoStore.DEFAULT_NAME); if (!fileSystem.fileExists(store)) { sf.createNeoStore(store).close(); } return store; }