Exemplo n.º 1
0
  /**
   * Generate testing environment and return a collection of blocks on which to run the tests.
   *
   * @param bpid Block pool ID to generate blocks for
   * @param dataSet Namespace in which to insert blocks
   * @return Contrived blocks for further testing.
   * @throws IOException
   */
  private ExtendedBlock[] setup(String bpid, FsDatasetImpl dataSet) throws IOException {
    // setup replicas map

    ExtendedBlock[] blocks =
        new ExtendedBlock[] {
          new ExtendedBlock(bpid, 1, 1, 2001), new ExtendedBlock(bpid, 2, 1, 2002),
          new ExtendedBlock(bpid, 3, 1, 2003), new ExtendedBlock(bpid, 4, 1, 2004),
          new ExtendedBlock(bpid, 5, 1, 2005), new ExtendedBlock(bpid, 6, 1, 2006)
        };

    ReplicaMap replicasMap = dataSet.volumeMap;
    FsVolumeImpl vol =
        (FsVolumeImpl) dataSet.volumes.getNextVolume(StorageType.DEFAULT, 0).getVolume();
    ReplicaInfo replicaInfo =
        new FinalizedReplica(
            blocks[FINALIZED].getLocalBlock(), vol, vol.getCurrentDir().getParentFile());
    replicasMap.add(bpid, replicaInfo);
    replicaInfo.getBlockFile().createNewFile();
    replicaInfo.getMetaFile().createNewFile();

    replicasMap.add(
        bpid,
        new ReplicaInPipeline(
            blocks[TEMPORARY].getBlockId(),
            blocks[TEMPORARY].getGenerationStamp(),
            vol,
            vol.createTmpFile(bpid, blocks[TEMPORARY].getLocalBlock()).getParentFile(),
            0));

    replicaInfo =
        new ReplicaBeingWritten(
            blocks[RBW].getLocalBlock(),
            vol,
            vol.createRbwFile(bpid, blocks[RBW].getLocalBlock()).getParentFile(),
            null);
    replicasMap.add(bpid, replicaInfo);
    replicaInfo.getBlockFile().createNewFile();
    replicaInfo.getMetaFile().createNewFile();

    replicasMap.add(
        bpid,
        new ReplicaWaitingToBeRecovered(
            blocks[RWR].getLocalBlock(),
            vol,
            vol.createRbwFile(bpid, blocks[RWR].getLocalBlock()).getParentFile()));
    replicasMap.add(
        bpid,
        new ReplicaUnderRecovery(
            new FinalizedReplica(
                blocks[RUR].getLocalBlock(), vol, vol.getCurrentDir().getParentFile()),
            2007));

    return blocks;
  }
  /** Asynchronously lazy persist the block from the RamDisk to Disk. */
  void submitLazyPersistTask(
      String bpId,
      long blockId,
      long genStamp,
      long creationTime,
      File metaFile,
      File blockFile,
      FsVolumeReference target)
      throws IOException {
    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "LazyWriter schedule async task to persist RamDisk block pool id: "
              + bpId
              + " block id: "
              + blockId);
    }

    FsVolumeImpl volume = (FsVolumeImpl) target.getVolume();
    File lazyPersistDir = volume.getLazyPersistDir(bpId);
    if (!lazyPersistDir.exists() && !lazyPersistDir.mkdirs()) {
      FsDatasetImpl.LOG.warn("LazyWriter failed to create " + lazyPersistDir);
      throw new IOException(
          "LazyWriter fail to find or create lazy persist dir: " + lazyPersistDir.toString());
    }

    ReplicaLazyPersistTask lazyPersistTask =
        new ReplicaLazyPersistTask(
            bpId, blockId, genStamp, creationTime, blockFile, metaFile, target, lazyPersistDir);
    execute(volume.getCurrentDir(), lazyPersistTask);
  }