/** * Wait for all files in waitList to have length equal to newLength. */ private void waitForRecovery() throws IOException { for(PathData item : waitList) { out.println("Waiting for " + item + " ..."); out.flush(); for(;;) { item.refreshStatus(); if(item.stat.getLen() == newLength) break; try {Thread.sleep(1000);} catch(InterruptedException ignored) {} } out.println("Truncated " + item + " to length: " + newLength); out.flush(); } } }
boolean done = false; while (!done) { item.refreshStatus(); BlockLocation[] locations = item.fs.getFileBlockLocations(item.stat, 0, item.stat.getLen());
private long dumpFromOffset(PathData item, long offset) throws IOException { long fileSize = item.refreshStatus().getLen(); if (offset > fileSize) return fileSize; // treat a negative offset as relative to end of the file, floor of 0 if (offset < 0) { offset = Math.max(fileSize + offset, 0); } FSDataInputStream in = item.fs.open(item.path); try { in.seek(offset); // use conf so the system configured io block size is used IOUtils.copyBytes(in, System.out, getConf(), false); offset = in.getPos(); } finally { in.close(); } return offset; } }
throw e; dst.refreshStatus(); // need to update stat to know it exists now
/** * Wait for all files in waitList to have length equal to newLength. */ private void waitForRecovery() throws IOException { for(PathData item : waitList) { out.println("Waiting for " + item + " ..."); out.flush(); for(;;) { item.refreshStatus(); if(item.stat.getLen() == newLength) break; try {Thread.sleep(1000);} catch(InterruptedException ignored) {} } out.println("Truncated " + item + " to length: " + newLength); out.flush(); } } }
/** * Wait for all files in waitList to have length equal to newLength. */ private void waitForRecovery() throws IOException { for(PathData item : waitList) { out.println("Waiting for " + item + " ..."); out.flush(); for(;;) { item.refreshStatus(); if(item.stat.getLen() == newLength) break; try {Thread.sleep(1000);} catch(InterruptedException ignored) {} } out.println("Truncated " + item + " to length: " + newLength); out.flush(); } } }
/** * Wait for all files in waitList to have length equal to newLength. */ private void waitForRecovery() throws IOException { for(PathData item : waitList) { out.println("Waiting for " + item + " ..."); out.flush(); for(;;) { item.refreshStatus(); if(item.stat.getLen() == newLength) break; try {Thread.sleep(1000);} catch(InterruptedException ignored) {} } out.println("Truncated " + item + " to length: " + newLength); out.flush(); } } }
/** * Wait for all files in waitList to have length equal to newLength. */ private void waitForRecovery() throws IOException { for(PathData item : waitList) { out.println("Waiting for " + item + " ..."); out.flush(); for(;;) { item.refreshStatus(); if(item.stat.getLen() == newLength) break; try {Thread.sleep(1000);} catch(InterruptedException ignored) {} } out.println("Truncated " + item + " to length: " + newLength); out.flush(); } } }
private long dumpFromOffset(PathData item, long offset) throws IOException { long fileSize = item.refreshStatus().getLen(); if (offset > fileSize) return fileSize; // treat a negative offset as relative to end of the file, floor of 0 if (offset < 0) { offset = Math.max(fileSize + offset, 0); } FSDataInputStream in = item.fs.open(item.path); try { in.seek(offset); // use conf so the system configured io block size is used IOUtils.copyBytes(in, System.out, getConf(), false); offset = in.getPos(); } finally { in.close(); } return offset; } }
boolean done = false; while (!done) { item.refreshStatus(); BlockLocation[] locations = item.fs.getFileBlockLocations(item.stat, 0, item.stat.getLen());
private long dumpFromOffset(PathData item, long offset) throws IOException { long fileSize = item.refreshStatus().getLen(); if (offset > fileSize) return fileSize; // treat a negative offset as relative to end of the file, floor of 0 if (offset < 0) { offset = Math.max(fileSize + offset, 0); } FSDataInputStream in = item.fs.open(item.path); try { in.seek(offset); // use conf so the system configured io block size is used IOUtils.copyBytes(in, System.out, getConf(), false); offset = in.getPos(); } finally { in.close(); } return offset; } }
private long dumpFromOffset(PathData item, long offset) throws IOException { long fileSize = item.refreshStatus().getLen(); if (offset > fileSize) return fileSize; // treat a negative offset as relative to end of the file, floor of 0 if (offset < 0) { offset = Math.max(fileSize + offset, 0); } FSDataInputStream in = item.fs.open(item.path); try { in.seek(offset); // use conf so the system configured io block size is used IOUtils.copyBytes(in, System.out, getConf(), false); offset = in.getPos(); } finally { in.close(); } return offset; } }
private long dumpFromOffset(PathData item, long offset) throws IOException { long fileSize = item.refreshStatus().getLen(); if (offset > fileSize) return fileSize; // treat a negative offset as relative to end of the file, floor of 0 if (offset < 0) { offset = Math.max(fileSize + offset, 0); } FSDataInputStream in = item.fs.open(item.path); try { in.seek(offset); // use conf so the system configured io block size is used IOUtils.copyBytes(in, System.out, getConf(), false); offset = in.getPos(); } finally { in.close(); } return offset; } }
boolean done = false; while (!done) { item.refreshStatus(); BlockLocation[] locations = item.fs.getFileBlockLocations(item.stat, 0, item.stat.getLen());
@Test public void testCopyStreamTargetExists() throws Exception { FSDataOutputStream out = mock(FSDataOutputStream.class); whenFsCreate().thenReturn(out); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); target.refreshStatus(); // so it's updated as existing cmd.setOverwrite(true); when(mockFs.getFileStatus(eq(tmpPath))).thenReturn(fileStat); when(mockFs.delete(eq(path), eq(false))).thenReturn(true); when(mockFs.rename(eq(tmpPath), eq(path))).thenReturn(true); FSInputStream in = mock(FSInputStream.class); when(in.read(any(byte[].class), anyInt(), anyInt())).thenReturn(-1); tryCopyStream(in, true); verify(mockFs).delete(eq(path), anyBoolean()); verify(mockFs).rename(eq(tmpPath), eq(path)); verify(mockFs, never()).delete(eq(tmpPath), anyBoolean()); verify(mockFs, never()).close(); }
@Test public void testCopyStreamTargetExists() throws Exception { FSDataOutputStream out = mock(FSDataOutputStream.class); whenFsCreate().thenReturn(out); when(mockFs.getFileStatus(eq(path))).thenReturn(fileStat); target.refreshStatus(); // so it's updated as existing cmd.setOverwrite(true); when(mockFs.getFileStatus(eq(tmpPath))).thenReturn(fileStat); when(mockFs.delete(eq(path), eq(false))).thenReturn(true); when(mockFs.rename(eq(tmpPath), eq(path))).thenReturn(true); FSInputStream in = mock(FSInputStream.class); when(in.read(any(byte[].class), anyInt(), anyInt())).thenReturn(-1); tryCopyStream(in, true); verify(mockFs).delete(eq(path), anyBoolean()); verify(mockFs).rename(eq(tmpPath), eq(path)); verify(mockFs, never()).delete(eq(tmpPath), anyBoolean()); verify(mockFs, never()).close(); }
throw e; dst.refreshStatus(); // need to update stat to know it exists now
throw e; dst.refreshStatus(); // need to update stat to know it exists now
throw e; dst.refreshStatus(); // need to update stat to know it exists now
throw e; dst.refreshStatus(); // need to update stat to know it exists now