Esempio n. 1
0
 /**
  * Create a blook pool slice
  *
  * @param bpid Block pool Id
  * @param volume {@link FsVolumeImpl} to which this BlockPool belongs to
  * @param bpDir directory corresponding to the BlockPool
  * @param conf configuration
  * @throws IOException
  */
 BlockPoolSlice(String bpid, FsVolumeImpl volume, File bpDir, Configuration conf)
     throws IOException {
   this.bpid = bpid;
   this.volume = volume;
   this.currentDir = new File(bpDir, DataStorage.STORAGE_DIR_CURRENT);
   this.finalizedDir = new File(currentDir, DataStorage.STORAGE_DIR_FINALIZED);
   this.lazypersistDir = new File(currentDir, DataStorage.STORAGE_DIR_LAZY_PERSIST);
   if (!this.finalizedDir.exists()) {
     if (!this.finalizedDir.mkdirs()) {
       throw new IOException("Failed to mkdirs " + this.finalizedDir);
     }
   }
   this.tmpDir = new File(bpDir, DataStorage.STORAGE_DIR_TMP);
   if (tmpDir.exists()) {
     FileUtil.fullyDelete(tmpDir);
   }
   this.rbwDir = new File(currentDir, DataStorage.STORAGE_DIR_RBW);
   final boolean supportAppends =
       conf.getBoolean(
           DFSConfigKeys.DFS_SUPPORT_APPEND_KEY, DFSConfigKeys.DFS_SUPPORT_APPEND_DEFAULT);
   if (rbwDir.exists() && !supportAppends) {
     FileUtil.fullyDelete(rbwDir);
   }
   if (!rbwDir.mkdirs()) { // create rbw directory if not exist
     if (!rbwDir.isDirectory()) {
       throw new IOException("Mkdirs failed to create " + rbwDir.toString());
     }
   }
   if (!tmpDir.mkdirs()) {
     if (!tmpDir.isDirectory()) {
       throw new IOException("Mkdirs failed to create " + tmpDir.toString());
     }
   }
   // 循环的获取BP目录的大小
   this.dfsUsage = new DU(bpDir, conf, loadDfsUsed());
   this.dfsUsage.start();
   // 注册一个JVM关闭的钩子
   ShutdownHookManager.get()
       .addShutdownHook(
           new Runnable() {
             @Override
             public void run() {
               if (!dfsUsedSaved) {
                 saveDfsUsed();
               }
             }
           },
           SHUTDOWN_HOOK_PRIORITY);
 }
Esempio n. 2
0
  void addToReplicasMap(
      ReplicaMap volumeMap,
      File dir,
      final RamDiskReplicaTracker lazyWriteReplicaMap,
      boolean isFinalized)
      throws IOException {
    File files[] = FileUtil.listFiles(dir);

    for (File file : files) {
      if (file.isDirectory()) {
        addToReplicasMap(volumeMap, file, lazyWriteReplicaMap, isFinalized);
      }
      if (isFinalized && FsDatasetUtil.isUnlinkTmpFile(file)) {
        throw new RuntimeException("未实现");
      }
      if (!Block.isBlockFilename(file)) continue;
      long genStamp = FsDatasetUtil.getGenerationStampFromFile(files, file);
      long blockId = Block.filename2id(file.getName());
      ReplicaInfo newReplica = null;
      if (isFinalized) {
        newReplica =
            new FinalizedReplica(blockId, file.length(), genStamp, volume, file.getParentFile());
      } else {
        boolean loadRwr = true;
        File restartMeta =
            new File(file.getParent() + File.pathSeparator + "." + file.getName() + ".restart");
        try {
          if (!restartMeta.delete()) {
            FsDatasetImpl.LOG.warn("Failed to delete restart meta file: " + restartMeta.getPath());
          }
        } finally {
        }
        if (loadRwr) {
          LOG.error("未实现");
          continue;
        }
      }
      ReplicaInfo oldReplica = volumeMap.get(bpid, newReplica.getBlockId());
      if (oldReplica == null) {
        volumeMap.add(bpid, newReplica);
      } else {
        throw new RuntimeException("未实现");
      }
      if (newReplica.getVolume().isTransientStorage()) {
        throw new RuntimeException("未实现");
      } else {
        lazyWriteReplicaMap.discardReplica(bpid, blockId, false);
      }
    }
  }