/** * Replace the journal at index <code>index</code> with one that throws an * exception on flush. * * @param index the index of the journal to take offline. * @return the original <code>EditLogOutputStream</code> of the journal. */ private void invalidateEditsDirAtIndex(int index, boolean failOnFlush, boolean failOnWrite) throws IOException { JournalAndStream jas = getJournalAndStream(index); EditLogFileOutputStream spyElos = spyOnStream(jas); if (failOnWrite) { doThrow(new IOException("fail on write()")).when(spyElos).write( (FSEditLogOp) any()); } if (failOnFlush) { doThrow(new IOException("fail on flush()")).when(spyElos).flush(); } else { doThrow(new IOException("fail on setReadyToFlush()")).when(spyElos) .setReadyToFlush(); } }
/** * Replace the journal at index <code>index</code> with one that throws an * exception on flush. * * @param index the index of the journal to take offline. * @return the original <code>EditLogOutputStream</code> of the journal. */ private EditLogOutputStream invalidateEditsDirAtIndex(int index, boolean failOnFlush, boolean failOnWrite) throws IOException { FSImage fsimage = cluster.getNameNode().getFSImage(); FSEditLog editLog = fsimage.getEditLog(); JournalAndStream jas = editLog.getJournals().get(index); EditLogFileOutputStream elos = (EditLogFileOutputStream) jas.getCurrentStream(); EditLogFileOutputStream spyElos = spy(elos); if (failOnWrite) { doThrow(new IOException("fail on write()")).when(spyElos).write( (FSEditLogOp) any()); } if (failOnFlush) { doThrow(new IOException("fail on flush()")).when(spyElos).flush(); } else { doThrow(new IOException("fail on setReadyToFlush()")).when(spyElos) .setReadyToFlush(); } doNothing().when(spyElos).abort(); jas.setCurrentStreamForTests(spyElos); return elos; }
/** * Replace the journal at index <code>index</code> with one that throws an * exception on flush. */ private EditLogOutputStream invalidateEditsDirAtIndex(int index) throws IOException { FSImage fsimage = cluster.getNameNode(0).avatars.get(0).avatar.getFSImage(); FSEditLog editLog = fsimage.getEditLog(); JournalAndStream jas = editLog.getJournals().get(index); EditLogFileOutputStream elos = (EditLogFileOutputStream) jas .getCurrentStream(); EditLogFileOutputStream spyElos = spy(elos); doThrow(new IOException("fail on write()")).when(spyElos).write( (FSEditLogOp) any()); doThrow(new IOException("fail on write()")).when(spyElos).writeRaw( (byte[]) any(), anyInt(), anyInt()); doThrow(new IOException("fail on write()")).when(spyElos).writeRawOp( (byte[]) any(), anyInt(), anyInt(), anyLong()); doNothing().when(spyElos).abort(); jas.setCurrentStreamForTests(spyElos); return elos; }
@Override // NameNodeMXBean public String getNameJournalStatus() { List<Map<String, String>> jasList = new ArrayList<Map<String, String>>(); FSEditLog log = getFSImage().getEditLog(); if (log != null) { boolean openForWrite = log.isOpenForWrite(); for (JournalAndStream jas : log.getJournals()) { final Map<String, String> jasMap = new HashMap<String, String>(); String manager = jas.getManager().toString(); jasMap.put("required", String.valueOf(jas.isRequired())); jasMap.put("disabled", String.valueOf(jas.isDisabled())); jasMap.put("manager", manager); if (jas.isDisabled()) { jasMap.put("stream", "Failed"); } else if (openForWrite) { EditLogOutputStream elos = jas.getCurrentStream(); if (elos != null) { jasMap.put("stream", elos.generateReport()); } else { jasMap.put("stream", "not currently writing"); } } else { jasMap.put("stream", "open for read"); } jasList.add(jasMap); } } return JSON.toString(jasList); }
public long getSharedLogCTime() throws IOException { for (JournalAndStream jas : journalSet.getAllJournalStreams()) { if (jas.isShared()) { return jas.getManager().getJournalCTime(); } } throw new IOException("No shared log found."); }
public synchronized void doPreUpgradeOfSharedLog() throws IOException { for (JournalAndStream jas : journalSet.getAllJournalStreams()) { if (jas.isShared()) { jas.getManager().doPreUpgrade(); } } }
public synchronized void doUpgradeOfSharedLog() throws IOException { for (JournalAndStream jas : journalSet.getAllJournalStreams()) { if (jas.isShared()) { jas.getManager().doUpgrade(storage); } } }
public synchronized void doFinalizeOfSharedLog() throws IOException { for (JournalAndStream jas : journalSet.getAllJournalStreams()) { if (jas.isShared()) { jas.getManager().doFinalize(); } } }
public synchronized boolean canRollBackSharedLog(StorageInfo prevStorage, int targetLayoutVersion) throws IOException { for (JournalAndStream jas : journalSet.getAllJournalStreams()) { if (jas.isShared()) { return jas.getManager().canRollBack(storage, prevStorage, targetLayoutVersion); } } throw new IOException("No shared log found."); }
public synchronized void doRollback() throws IOException { for (JournalAndStream jas : journalSet.getAllJournalStreams()) { if (jas.isShared()) { jas.getManager().doRollback(); } } }
private EditLogFileOutputStream spyOnStream(JournalAndStream jas) { EditLogFileOutputStream elos = (EditLogFileOutputStream) jas.getCurrentStream(); EditLogFileOutputStream spyElos = spy(elos); jas.setCurrentStreamForTests(spyElos); return spyElos; }
/** * Pull out one of the JournalAndStream objects from the edit log. */ private JournalAndStream getJournalAndStream(int index) { FSImage fsimage = cluster.getNamesystem().getFSImage(); FSEditLog editLog = fsimage.getEditLog(); return editLog.getJournals().get(index); }
/** * invalidate storage by removing the second and third storage directories */ public void invalidateStorage(FSImage fi, Set<File> filesToInvalidate) throws IOException { ArrayList<StorageDirectory> al = new ArrayList<StorageDirectory>(2); Iterator<StorageDirectory> it = fi.getStorage().dirIterator(); while(it.hasNext()) { StorageDirectory sd = it.next(); if(filesToInvalidate.contains(sd.getRoot())) { LOG.info("causing IO error on " + sd.getRoot()); al.add(sd); } } // simulate an error fi.getStorage().reportErrorsOnDirectories(al); for (JournalAndStream j : fi.getEditLog().getJournals()) { if (j.getManager() instanceof FileJournalManager) { FileJournalManager fm = (FileJournalManager)j.getManager(); if (fm.getStorageDirectory().getRoot().equals(path2) || fm.getStorageDirectory().getRoot().equals(path3)) { EditLogOutputStream mockStream = spy(j.getCurrentStream()); j.setCurrentStreamForTests(mockStream); doThrow(new IOException("Injected fault: write")). when(mockStream).write(Mockito.<FSEditLogOp>anyObject()); } } } }