Add block b belonging to the specified file inode to the map
16640
BlockInfo addINode(Block b, INodeFile iNode, short replication) {
    BlockInfo info = checkBlockInfo(b, replication);
    info.inode = iNode;
    return info;
  }
658073
void read(BlockId blk, IoBuffer buffer) {
		try {
			IoChannel fileChannel = getFileChannel(blk.fileName());

			// clear the buffer
			buffer.clear();

			// read a block from file
			fileChannel.read(buffer, blk.number() * BLOCK_SIZE);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("cannot read block " + blk);
		}
	}
1187499
public void persistFile(long fileId, List<Long> blockIds) throws AlluxioException, IOException {
    Map<Long, Long> blockIdToLockId;
    synchronized (mLock) {
      blockIdToLockId = mPersistingInProgressFiles.get(fileId);
      if (blockIdToLockId == null || !blockIdToLockId.keySet().equals(new HashSet<>(blockIds))) {
        throw new IOException("Not all the blocks of file " + fileId + " are locked");
      }
    }

    FileInfo fileInfo = mBlockWorker.getFileInfo(fileId);
    try (CloseableResource<UnderFileSystem> ufsResource =
        mUfsManager.get(fileInfo.getMountId()).acquireUfsResource()) {
      UnderFileSystem ufs = ufsResource.get();
      String dstPath = prepareUfsFilePath(fileInfo, ufs);
      OutputStream outputStream = ufs.createNonexistingFile(dstPath,
          CreateOptions.defaults(ServerConfiguration.global())
          .setOwner(fileInfo.getOwner()).setGroup(fileInfo.getGroup())
          .setMode(new Mode((short) fileInfo.getMode())));
      final WritableByteChannel outputChannel = Channels.newChannel(outputStream);
      List<Throwable> errors = new ArrayList<>();
      try {
        for (long blockId : blockIds) {
          long lockId = blockIdToLockId.get(blockId);

          if (ServerConfiguration.getBoolean(PropertyKey.WORKER_FILE_PERSIST_RATE_LIMIT_ENABLED)) {
            BlockMeta blockMeta =
                mBlockWorker.getBlockMeta(Sessions.CHECKPOINT_SESSION_ID, blockId, lockId);
            mPersistenceRateLimiter.acquire((int) blockMeta.getBlockSize());
          }

          // obtain block reader
          BlockReader reader =
              mBlockWorker.readBlockRemote(Sessions.CHECKPOINT_SESSION_ID, blockId, lockId);

          // write content out
          ReadableByteChannel inputChannel = reader.getChannel();
          mChannelCopier.copy(inputChannel, outputChannel);
          reader.close();
        }
      } catch (BlockDoesNotExistException | InvalidWorkerStateException e) {
        errors.add(e);
      } finally {
        // make sure all the locks are released
        for (long lockId : blockIdToLockId.values()) {
          try {
            mBlockWorker.unlockBlock(lockId);
          } catch (BlockDoesNotExistException e) {
            errors.add(e);
          }
        }

        // Process any errors
        if (!errors.isEmpty()) {
          StringBuilder errorStr = new StringBuilder();
          errorStr.append("the blocks of file").append(fileId).append(" are failed to persist\n");
          for (Throwable e : errors) {
            errorStr.append(e).append('\n');
          }
          throw new IOException(errorStr.toString());
        }
      }

      outputStream.flush();
      outputChannel.close();
      outputStream.close();
      String ufsFingerprint = ufs.getFingerprint(dstPath);
      synchronized (mLock) {
        mPersistingInProgressFiles.remove(fileId);
        mPersistedUfsFingerprints.put(fileId, ufsFingerprint);
      }
    }
  }
540766
boolean removeBlock(String path, INodeFileUnderConstruction fileNode,
                      Block block) throws IOException {
    waitForReady();

    writeLock();
    try {
      // modify file-> block and blocksMap
      fileNode.removeBlock(block);
      getFSNamesystem().blocksMap.removeBlock(block);
      // Remove the block from corruptReplicasMap
      getFSNamesystem().corruptReplicas.removeFromCorruptReplicasMap(block);

      // write modified block locations to log
      fsImage.getEditLog().logOpenFile(path, fileNode);
      if (NameNode.stateChangeLog.isDebugEnabled()) {
        NameNode.stateChangeLog.debug("DIR* FSDirectory.removeBlock: "
                                      +path+" with "+block
                                      +" block is removed from the file system");
      }
    } finally {
      writeUnlock();
    }
    return true;
  }
833187
private Map<URI, Set<URI>> addMapFilePrefix(final Map<URI, Set<URI>> map) {
        final Map<URI, Set<URI>> res = new HashMap<>();
        for (final Map.Entry<URI, Set<URI>> e: map.entrySet()) {
            final URI key = e.getKey();
            final Set<URI> newSet = new HashSet<>(e.getValue().size());
            for (final URI file: e.getValue()) {
                newSet.add(tempFileNameScheme.generateTempFileName(file));
            }
            res.put(key.equals(ROOT_URI) ? key : tempFileNameScheme.generateTempFileName(key), newSet);
        }
        return res;
    }
847996
def add_basic_block(self, basic_block):
        """"""
        assert(isinstance(basic_block, BasicBlock))
        self.basic_block_list.append(basic_block)
1014800
void assignToBlock(BlockId blk) {
		internalLock.writeLock().lock();
		try {
			flush();
			this.blk = blk;
			contents.read(blk);
			pins = 0;
			lastLsn = LogSeqNum.readFromPage(contents, LAST_LSN_OFFSET);
		} finally {
			internalLock.writeLock().unlock();
		}
	}
382459
private static void multBlockAdd( double []blockA, double []blockB, double []blockC,
                                     final int m, final int n, final int o,
                                     final int blockLength ) {
//        for( int i = 0; i < m; i++ ) {
//            for( int j = 0; j < o; j++ ) {
//                double val = 0;
//                for( int k = 0; k < n; k++ ) {
//                    val += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];
//                }
//
//                blockC[ i*blockLength + j] += val;
//            }
//        }

//        int rowA = 0;
//        for( int i = 0; i < m; i++ , rowA += blockLength) {
//            for( int j = 0; j < o; j++ ) {
//                double val = 0;
//                int indexB = j;
//                int indexA = rowA;
//                int end = indexA + n;
//                for( ; indexA != end; indexA++ , indexB += blockLength ) {
//                    val += blockA[ indexA ]*blockB[ indexB ];
//                }
//
//                blockC[ rowA + j] += val;
//            }
//        }

//        for( int k = 0; k < n; k++ ) {
//            for( int i = 0; i < m; i++ ) {
//                for( int j = 0; j < o; j++ ) {
//                    blockC[ i*blockLength + j] += blockA[ i*blockLength + k]*blockB[ k*blockLength + j];
//                }
//            }
//        }

        for( int k = 0; k < n; k++ ) {
            int rowB = k*blockLength;
            int endB = rowB+o;
            for( int i = 0; i < m; i++ ) {
                int indexC = i*blockLength;
                double valA = blockA[ indexC + k];
                int indexB = rowB;
                
                while( indexB != endB ) {
                    blockC[ indexC++ ] += valA*blockB[ indexB++];
                }
            }
        }
    }
858271
void write(BlockId blk, IoBuffer buffer) {
		try {
			IoChannel fileChannel = getFileChannel(blk.fileName());

			// rewind the buffer
			buffer.rewind();

			// write the block to the file
			fileChannel.write(buffer, blk.number() * BLOCK_SIZE);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("cannot write block" + blk);
		}
	}
889661
public synchronized void allocate(RegularFile file, int count) throws IOException {
    int newAllocatedBlockCount = allocatedBlockCount + count;
    if (newAllocatedBlockCount > maxBlockCount) {
      throw new IOException("out of disk space");
    }

    int newBlocksNeeded = Math.max(count - blockCache.blockCount(), 0);

    for (int i = 0; i < newBlocksNeeded; i++) {
      file.addBlock(new byte[blockSize]);
    }

    if (newBlocksNeeded != count) {
      blockCache.transferBlocksTo(file, count - newBlocksNeeded);
    }

    allocatedBlockCount = newAllocatedBlockCount;
  }
71412
private void addCreatedSplit(List<InputSplit> splitList, 
                               List<String> locations, 
                               ArrayList<OneBlockInfo> validBlocks) {
    // create an input split
    Path[] fl = new Path[validBlocks.size()];
    long[] offset = new long[validBlocks.size()];
    long[] length = new long[validBlocks.size()];
    for (int i = 0; i < validBlocks.size(); i++) {
      fl[i] = validBlocks.get(i).onepath; 
      offset[i] = validBlocks.get(i).offset;
      length[i] = validBlocks.get(i).length;
    }

     // add this split to the list that is returned
    CombineFileSplit thissplit = new CombineFileSplit(fl, offset, 
                                   length, locations.toArray(new String[0]));
    splitList.add(thissplit); 
  }
860613
private void copyBlockLocalFinalize(int dstNamespaceId,
      Block dstBlock, File dstBlockFile)
    throws IOException {
    boolean inlineChecksum = Block.isInlineChecksumBlockFilename(dstBlockFile
        .getName());
    long blkSize = 0;
    long fileSize = dstBlockFile.length();
    lock.writeLock().lock();
    try {
      DatanodeBlockInfo info = volumeMap.get(dstNamespaceId, dstBlock);
      if (info == null) {
        throw new IOException("Could not find information for " + dstBlock);
      }
      if (inlineChecksum) {
        blkSize = BlockInlineChecksumReader.getBlockSizeFromFileLength(fileSize,
            info.getChecksumType(), info.getBytesPerChecksum());
      } else {
        blkSize = fileSize;
      }

      FSVolume dstVol = info.getBlockDataFile().getVolume();
      // Finalize block on disk.
      File dest = dstVol.addBlock(dstNamespaceId, dstBlock, dstBlockFile,
          info.isInlineChecksum(), info.getChecksumType(),
          info.getBytesPerChecksum());
      volumeMap.add(dstNamespaceId, dstBlock,
          new DatanodeBlockInfo(dstVol, dest, blkSize, true, inlineChecksum,
              info.getChecksumType(), info.getBytesPerChecksum(), false, 0));
      volumeMap.removeOngoingCreates(dstNamespaceId, dstBlock);
    } finally {
      lock.writeLock().unlock();
    }
  }
213484
private <T extends INode> T addNode(String src, T child,
        long childDiskspace, boolean inheritPermission)
  throws QuotaExceededException {
    byte[][] components = INode.getPathComponents(src);
    byte[] path = components[components.length - 1];
    child.setLocalName(path);
    cacheName(child);
    INode[] inodes = new INode[components.length];
    writeLock();
    try {
      rootDir.getExistingPathINodes(components, inodes);
      return addChild(inodes, inodes.length-1, child, childDiskspace,
                      inheritPermission);
    } finally {
      writeUnlock();
    }
  }
1194603
private static int getBlockIdInFile(DistributedFileSystem srcFs, 
      Path srcPath, long blockId) throws IOException {
    FileStatus srcStat = srcFs.getFileStatus(srcPath);
    LocatedBlocks lbs =
        srcFs.getClient().getLocatedBlocks(srcPath.toUri().getPath(), 0, 
            srcStat.getLen());
    
    int i = 0;
    LOG.info("Look for block " + blockId + " in file " + srcPath);
    for (LocatedBlock lb: lbs.getLocatedBlocks()) {
      if (lb.getBlock().getBlockId() == blockId) {
        return i;
      }
      i++;
    }
    
    return -1;
  }
433451
def with_file_utils(&block)
      Module.new do
        include Mustermann::FileUtils
        define_method(:f, &block)
        private(:f)
        extend self
      end
    end
247852
public void add(StorageDirView dir, long blockId, long blockSizeBytes) {
    Pair<List<Long>, Long> candidate;
    if (mDirCandidates.containsKey(dir)) {
      candidate = mDirCandidates.get(dir);
    } else {
      candidate = new Pair<List<Long>, Long>(new ArrayList<Long>(), 0L);
      mDirCandidates.put(dir, candidate);
    }

    candidate.getFirst().add(blockId);
    long blockBytes = candidate.getSecond() + blockSizeBytes;
    candidate.setSecond(blockBytes);

    long sum = blockBytes + dir.getAvailableBytes();
    if (mMaxBytes < sum) {
      mMaxBytes = sum;
      mDirWithMaxBytes = dir;
    }
  }
827995
protected void addToMap(Map m, String key, String value) {
        m.put(key,value);
    }