Package org.apache.hadoop.hdfs.server.datanode.FSDataset

Examples of org.apache.hadoop.hdfs.server.datanode.FSDataset.ActiveFile


   */
  private ArrayList<Thread> getActiveThreads(int namespaceId, Block block) {
    lock.writeLock().lock();
    try {
      //check ongoing create threads
      final ActiveFile activefile = volumeMap.getOngoingCreates(namespaceId, block);
      if (activefile != null && !activefile.threads.isEmpty()) {
        //remove dead threads
        for(Iterator<Thread> i = activefile.threads.iterator(); i.hasNext(); ) {
          final Thread t = i.next();
          if (!t.isAlive()) {
View Full Code Here


      long oldFileLength = blockFile.length();
      if (newblock.getNumBytes() < oldFileLength) {
        truncateBlock(blockFile, tmpMetaFile, oldFileLength,
            newblock.getNumBytes());
      ActiveFile file = volumeMap.getOngoingCreates(namespaceId, oldblock);
      if (file != null) {
        file.setBytesAcked(newblock.getNumBytes());
        file.setBytesOnDisk(newblock.getNumBytes());
      } else {
        // This should never happen unless called from unit tests.
        this.getDatanodeBlockInfo(namespaceId, oldblock).syncInMemorySize();
      }
      }
 
      //rename the tmp file to the new meta file (with new generation stamp)
      File newMetaFile = getMetaFile(blockFile, newblock);
      if (!tmpMetaFile.renameTo(newMetaFile)) {
        throw new IOException("Cannot rename tmp meta file to " + newMetaFile);
      }
 
      if(volumeMap.getOngoingCreates(namespaceId, oldblock) != null){
        ActiveFile af = volumeMap.removeOngoingCreates(namespaceId, oldblock);
        volumeMap.addOngoingCreates(namespaceId, newblock, af);
      }
      volumeMap.update(namespaceId, oldblock, newblock);
 
      // paranoia! verify that the contents of the stored block
View Full Code Here

    lock.writeLock().lock();
    try {
      //
      // Is it already in the create process?
      //
      ActiveFile activeFile = volumeMap.getOngoingCreates(namespaceId, b);
      if (activeFile != null) {
        f = activeFile.file;
        threads = activeFile.threads;
        expectedFileSize = activeFile.getBytesOnDisk();

        if (!isRecovery) {
          throw new BlockAlreadyExistsException("Block " + b +
                                  " has already been started (though not completed), and thus cannot be created.");
        } else {
          for (Thread thread:threads) {
            thread.interrupt();
          }
        }
        volumeMap.removeOngoingCreates(namespaceId, b);
      }
      FSVolume v = null;
      if (!isRecovery) {
        v = volumes.getNextVolume(blockSize);
        // create temporary file to hold block in the designated volume
        f = createTmpFile(namespaceId, v, b, replicationRequest);
      } else if (f != null) {
        DataNode.LOG.info("Reopen already-open Block for append " + b);
        // create or reuse temporary file to hold block in the designated volume
        v = volumeMap.get(namespaceId, b).getVolume();
        volumeMap.add(namespaceId, b, new DatanodeBlockInfo(v, f,
            DatanodeBlockInfo.UNFINALIZED));
      } else {
        // reopening block for appending to it.
        DataNode.LOG.info("Reopen Block for append " + b);
        v = volumeMap.get(namespaceId, b).getVolume();
        f = createTmpFile(namespaceId, v, b, replicationRequest);
        File blkfile = getBlockFile(namespaceId, b);
        File oldmeta = getMetaFile(namespaceId, b);
        File newmeta = getMetaFile(f, b);

        // rename meta file to tmp directory
        DataNode.LOG.debug("Renaming " + oldmeta + " to " + newmeta);
        if (!oldmeta.renameTo(newmeta)) {
          throw new IOException("Block " + b + " reopen failed. " +
                                " Unable to move meta file  " + oldmeta +
                                " to tmp dir " + newmeta);
        }

        // rename block file to tmp directory
        DataNode.LOG.debug("Renaming " + blkfile + " to " + f);
        if (!blkfile.renameTo(f)) {
          if (!f.delete()) {
            throw new IOException("Block " + b + " reopen failed. " +
                                  " Unable to remove file " + f);
          }
          if (!blkfile.renameTo(f)) {
            throw new IOException("Block " + b + " reopen failed. " +
                                  " Unable to move block file " + blkfile +
                                  " to tmp dir " + f);
          }
        }
      }
      if (f == null) {
        DataNode.LOG.warn("Block " + b + " reopen failed " +
                          " Unable to locate tmp file.");
        throw new IOException("Block " + b + " reopen failed " +
                              " Unable to locate tmp file.");
      }
      // If this is a replication request, then this is not a permanent
      // block yet, it could get removed if the datanode restarts. If this
      // is a write or append request, then it is a valid block.
      if (replicationRequest) {
        volumeMap.add(namespaceId, b, new DatanodeBlockInfo(v));
      } else {
        volumeMap.add(namespaceId, b, new DatanodeBlockInfo(v, f, -1));
      }
      volumeMap.addOngoingCreates(namespaceId, b, new ActiveFile(f, threads,
          expectedFileSize));
     
    } finally {
      lock.writeLock().unlock();
    }
View Full Code Here

    }
  }

  private void fakeBeingCreated(Block b) {
    ongoingCreates.put(b,
        new ActiveFile(blockFile(b), new ArrayList<Thread>()));
  }
View Full Code Here

     * Create an ActiveFile from a file on disk during DataNode startup.
     * This factory method is just to make it clear when the purpose
     * of this constructor is.
     */
    public static ActiveFile createStartupRecoveryFile(File f) {
      return new ActiveFile(f, true);
    }
View Full Code Here

  public File findBlockFile(int namespaceId, long blockId) {
    lock.readLock().lock();
    try {
      final Block eb = new Block(blockId);
      File blockfile = null;
      ActiveFile activefile = volumeMap.getOngoingCreates(namespaceId, eb);
      if (activefile != null) {
        blockfile = activefile.file;
      }
      if (blockfile == null) {
        blockfile = getFile(namespaceId, eb);
View Full Code Here

    return info.getFinalizedSize();
  }

  @Override
  public long getOnDiskLength(int namespaceId, Block b) throws IOException {
    ActiveFile activeFile = volumeMap.getOngoingCreates(namespaceId, b);

    if (activeFile != null) {
      return activeFile.getBytesOnDisk();
    } else {
      return getFinalizedBlockLength(namespaceId, b);
    }
  }
View Full Code Here

    }
  }

  @Override
  public long getVisibleLength(int namespaceId, Block b) throws IOException {
    ActiveFile activeFile = volumeMap.getOngoingCreates(namespaceId, b);

    if (activeFile != null) {
      return activeFile.getBytesAcked();
    } else {
      return getFinalizedBlockLength(namespaceId, b);
    }
  }
View Full Code Here

   */
  private ArrayList<Thread> getActiveThreads(int namespaceId, Block block) {
    lock.writeLock().lock();
    try {
      //check ongoing create threads
      final ActiveFile activefile = volumeMap.getOngoingCreates(namespaceId, block);
      if (activefile != null && !activefile.threads.isEmpty()) {
        //remove dead threads
        for(Iterator<Thread> i = activefile.threads.iterator(); i.hasNext(); ) {
          final Thread t = i.next();
          if (!t.isAlive()) {
View Full Code Here

      long oldFileLength = blockFile.length();
      if (newblock.getNumBytes() < oldFileLength) {
        truncateBlock(blockFile, tmpMetaFile, oldFileLength,
            newblock.getNumBytes());
      ActiveFile file = volumeMap.getOngoingCreates(namespaceId, oldblock);
      if (file != null) {
        file.setBytesAcked(newblock.getNumBytes());
        file.setBytesOnDisk(newblock.getNumBytes());
      } else {
        // This should never happen unless called from unit tests.
        this.getDatanodeBlockInfo(namespaceId, oldblock).syncInMemorySize();
      }
      }
 
      //rename the tmp file to the new meta file (with new generation stamp)
      File newMetaFile = getMetaFile(blockFile, newblock);
      if (!tmpMetaFile.renameTo(newMetaFile)) {
        throw new IOException("Cannot rename tmp meta file to " + newMetaFile);
      }
 
      if(volumeMap.getOngoingCreates(namespaceId, oldblock) != null){
        ActiveFile af = volumeMap.removeOngoingCreates(namespaceId, oldblock);
        volumeMap.addOngoingCreates(namespaceId, newblock, af);
      }
      volumeMap.update(namespaceId, oldblock, newblock);
 
      // paranoia! verify that the contents of the stored block
View Full Code Here

TOP

Related Classes of org.apache.hadoop.hdfs.server.datanode.FSDataset.ActiveFile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.