/** * Return the storage directory corresponding to the passed URI * @param uri URI of a storage directory * @return The matching storage directory or null if none found */ StorageDirectory getStorageDirectory(URI uri) { try { uri = Util.fileAsURI(new File(uri)); Iterator<StorageDirectory> it = dirIterator(); for (; it.hasNext(); ) { StorageDirectory sd = it.next(); if (Util.fileAsURI(sd.getRoot()).equals(uri)) { return sd; } } } catch (IOException ioe) { LOG.warn("Error converting file to URI", ioe); } return null; }
/** * Return the list of locations being used for a specific purpose. * i.e. Image or edit log storage. * * @param dirType Purpose of locations requested. * @throws IOException */ Collection<URI> getDirectories(NameNodeDirType dirType) throws IOException { ArrayList<URI> list = new ArrayList<URI>(); Iterator<StorageDirectory> it = (dirType == null) ? dirIterator() : dirIterator(dirType); for ( ;it.hasNext(); ) { StorageDirectory sd = it.next(); try { list.add(Util.fileAsURI(sd.getRoot())); } catch (IOException e) { throw new IOException("Exception while processing " + "StorageDirectory " + sd.getRoot(), e); } } return list; }
/** * Attempt to parse a storage uri with storage class and URI. The storage * class component of the uri is case-insensitive. * * @param rawLocation Location string of the format [type]uri, where [type] is * optional. * @return A StorageLocation object if successfully parsed, null otherwise. * Does not throw any exceptions. */ public static StorageLocation parse(String rawLocation) throws IOException, SecurityException { Matcher matcher = regex.matcher(rawLocation); StorageType storageType = StorageType.DEFAULT; String location = rawLocation; if (matcher.matches()) { String classString = matcher.group(1); location = matcher.group(2); if (!classString.isEmpty()) { storageType = StorageType.valueOf(classString.toUpperCase()); } } return new StorageLocation(storageType, Util.stringAsURI(location)); }
public void testThrottler() throws IOException { Configuration conf = new Configuration(); FileSystem.setDefaultUri(conf, "hdfs://localhost:0"); long bandwidthPerSec = 1024*1024L; final long TOTAL_BYTES =6*bandwidthPerSec; long bytesToSend = TOTAL_BYTES; long start = Util.now(); DataTransferThrottler throttler = new DataTransferThrottler(bandwidthPerSec); long totalBytes = 0L; long bytesSent = 1024*512L; // 0.5MB throttler.throttle(bytesSent); bytesToSend -= bytesSent; bytesSent = 1024*768L; // 0.75MB throttler.throttle(bytesSent); bytesToSend -= bytesSent; try { Thread.sleep(1000); } catch (InterruptedException ignored) {} throttler.throttle(bytesToSend); long end = Util.now(); assertTrue(totalBytes*1000/(end-start)<=bandwidthPerSec); }
@Test public void testOneOperation() throws Exception { File editsDir = createEditsDir(); DummyServerCore core = new DummyServerCore(); EditLogFileOutputStream out = initEdits(editsDir); ServerLogReaderPreTransactional logReader = new ServerLogReaderPreTransactional(core, Util.stringAsURI(editsDir.getAbsolutePath())); core.logReader = logReader; Thread coreThread, logReaderThread; coreThread = new Thread(core); logReaderThread = new Thread(logReader); logReaderThread.start(); coreThread.start(); writeOperation(out, 1000, true); Thread.sleep(500); core.shutdown(); logReaderThread.join(); coreThread.join(); Assert.assertEquals(1, core.notifications.size()); Assert.assertEquals(1000, core.notifications.poll().txId); }
@Test public void testMissingVersion() throws IOException { // -37 is pre-transactional layout int lv = 12345; StorageInfo si = new StorageInfo(lv, 10, 0); StorageDirectory sd = new NNStorage(si).new StorageDirectory(editsDir); format(sd); URI editsURI = Util.stringAsURI(sd.getRoot().getAbsolutePath()); // remove verision file sd.getVersionFile().delete(); try { NotifierUtils.getVersion(editsURI); fail("Should fail"); } catch (Exception e) { LOG.info("expected exception: " + e.getMessage()); } }
@Override public void createSnapshot(String snapshotId, boolean updateLeases) throws IOException { // Create new SnapshotStore SnapshotStorage ssStore = new SnapshotStorage(conf, Util.stringAsURI(tempDir)); // Download image & edit files from namenode downloadSnapshotFiles(ssStore); // Merge image and edit files doMerge(ssStore); // Update file lengths for leased files (optional) if (updateLeases) { updateLeasedFiles(ssStore); } // Save snapshot saveSnapshot(ssStore, snapshotId); ssStore.close(); }
@Before public void setUp() throws Exception { Collection<String> dirList = new ArrayList<String>(); dirList.add(imageLclName); dirList.add(imageShdName0); dirList.add(imageShdName1); dirList.add(editsLclName); dirList.add(editsShdName0); dirList.add(editsShdName1); for(String name : dirList) { File dir = new File(name); FileUtil.fullyDelete(dir); dir.mkdirs(); } imageLcl = Util.stringAsURI(imageLclName); imageShd0 = Util.stringAsURI(imageShdName0); imageShd1 = Util.stringAsURI(imageShdName1); editsLcl = Util.stringAsURI(editsLclName); editsShd0 = Util.stringAsURI(editsShdName0); editsShd1 = Util.stringAsURI(editsShdName1); conf = new Configuration(); }
private long dispatchBlockMoves() throws InterruptedException { long bytesLastMoved = bytesMoved.get(); Future<?>[] futures = new Future<?>[plan.sources.size()]; int i=0; for (Source source : plan.sources) { futures[i++] = dispatcherExecutor.submit( source.new BlockMoveDispatcher(Util.now())); } // wait for all dispatcher threads to finish for (Future<?> future : futures) { try { future.get(); } catch (ExecutionException e) { LOG.warn("Dispatcher thread failed", e.getCause()); } } // wait for all block moving to be done waitForMoveCompletion(); return bytesMoved.get()-bytesLastMoved; }
public void testThrottler() throws IOException { Configuration conf = new Configuration(); FileSystem.setDefaultUri(conf, "hdfs://localhost:0"); long bandwidthPerSec = 1024*1024L; final long TOTAL_BYTES =6*bandwidthPerSec; long bytesToSend = TOTAL_BYTES; long start = Util.now(); BlockTransferThrottler throttler = new BlockTransferThrottler(bandwidthPerSec); long totalBytes = 0L; long bytesSent = 1024*512L; // 0.5MB throttler.throttle(bytesSent); bytesToSend -= bytesSent; bytesSent = 1024*768L; // 0.75MB throttler.throttle(bytesSent); bytesToSend -= bytesSent; try { Thread.sleep(1000); } catch (InterruptedException ignored) {} throttler.throttle(bytesToSend); long end = Util.now(); assertTrue(totalBytes*1000/(end-start)<=bandwidthPerSec); }
/** * Attempt to parse a storage uri with storage class and URI. The storage * class component of the uri is case-insensitive. * * @param rawLocation Location string of the format [type]uri, where [type] is * optional. * @return A StorageLocation object if successfully parsed, null otherwise. * Does not throw any exceptions. */ static StorageLocation parse(String rawLocation) throws IOException { Matcher matcher = regex.matcher(rawLocation); StorageType storageType = StorageType.DEFAULT; String location = rawLocation; if (matcher.matches()) { String classString = matcher.group(1); location = matcher.group(2); if (!classString.isEmpty()) { storageType = StorageType.valueOf(classString.toUpperCase()); } } return new StorageLocation(storageType, Util.stringAsURI(location)); }
Collection<URI> getDirectories(NameNodeDirType dirType) throws IOException { ArrayList<URI> list = new ArrayList<URI>(); Iterator<StorageDirectory> it = (dirType == null) ? dirIterator() : dirIterator(dirType); for ( ;it.hasNext(); ) { StorageDirectory sd = it.next(); try { list.add(Util.fileAsURI(sd.getRoot())); } catch (IOException e) { throw new IOException("Exception while processing " + "StorageDirectory " + sd.getRoot(), e); } } return list; }
public void testThrottler() throws IOException { Configuration conf = new HdfsConfiguration(); FileSystem.setDefaultUri(conf, "hdfs://localhost:0"); long bandwidthPerSec = 1024*1024L; final long TOTAL_BYTES =6*bandwidthPerSec; long bytesToSend = TOTAL_BYTES; long start = Util.now(); DataTransferThrottler throttler = new DataTransferThrottler(bandwidthPerSec); long totalBytes = 0L; long bytesSent = 1024*512L; // 0.5MB throttler.throttle(bytesSent); bytesToSend -= bytesSent; bytesSent = 1024*768L; // 0.75MB throttler.throttle(bytesSent); bytesToSend -= bytesSent; try { Thread.sleep(1000); } catch (InterruptedException ignored) {} throttler.throttle(bytesToSend); long end = Util.now(); assertTrue(totalBytes*1000/(end-start)<=bandwidthPerSec); }