/** * Write the current dfsUsed to the cache file. */ void saveDfsUsed() { File outFile = new File(currentDir, DU_CACHE_FILE); if (!fileIoProvider.deleteWithExistsCheck(volume, outFile)) { FsDatasetImpl.LOG.warn("Failed to delete old dfsUsed file in " + outFile.getParent()); } try { long used = getDfsUsed(); try (Writer out = new OutputStreamWriter( new FileOutputStream(outFile), "UTF-8")) { // mtime is written last, so that truncated writes won't be valid. out.write(Long.toString(used) + " " + Long.toString(timer.now())); // This is only called as part of the volume shutdown. // We explicitly avoid calling flush with fileIoProvider which triggers // volume check upon io exception to avoid cyclic volume checks. out.flush(); } } catch (IOException ioe) { // If write failed, the volume might be bad. Since the cache file is // not critical, log the error and continue. FsDatasetImpl.LOG.warn("Failed to write dfsUsed to " + outFile, ioe); } }
private void saveReplicas(BlockListAsLongs blocksListToPersist) { if (blocksListToPersist == null || blocksListToPersist.getNumberOfBlocks()== 0) { return; } final File tmpFile = new File(currentDir, REPLICA_CACHE_FILE + ".tmp"); final File replicaCacheFile = new File(currentDir, REPLICA_CACHE_FILE); if (!fileIoProvider.deleteWithExistsCheck(volume, tmpFile) || !fileIoProvider.deleteWithExistsCheck(volume, replicaCacheFile)) { return; } FileOutputStream out = null; try { out = fileIoProvider.getFileOutputStream(volume, tmpFile); blocksListToPersist.writeTo(out); out.close(); // Renaming the tmp file to replicas fileIoProvider.moveFile(volume, tmpFile, replicaCacheFile); } catch (Exception e) { // If write failed, the volume might be bad. Since the cache file is // not critical, log the error, delete both the files (tmp and cache) // and continue. LOG.warn("Failed to write replicas to cache ", e); fileIoProvider.deleteWithExistsCheck(volume, replicaCacheFile); } finally { IOUtils.closeStream(out); fileIoProvider.deleteWithExistsCheck(volume, tmpFile); } }
@Override public OutputStream createRestartMetaStream() throws IOException { File blockFile = getBlockFile(); File restartMeta = new File(blockFile.getParent() + File.pathSeparator + "." + blockFile.getName() + ".restart"); if (!getFileIoProvider().deleteWithExistsCheck(getVolume(), restartMeta)) { DataNode.LOG.warn("Failed to delete restart meta file: " + restartMeta.getPath()); } return getFileIoProvider().getFileOutputStream(getVolume(), restartMeta); }