code: public long nextGenerationStampForBlock(Block block, boolean fromNN) throws IOException {
      writeLock();
      try {
        if (isInSafeMode()) {
          throw new SafeModeException("Cannot get nextGenStamp for " + block, safeMode);
        }
        Block blockWithWildcardGenstamp = new Block(block.getBlockId());
        BlockInfo storedBlock = blocksMap.getStoredBlock(blockWithWildcardGenstamp);
        if (storedBlock == null) {
          String msg = block + " is already commited, storedBlock == null.";
          LOG.info(msg);
          throw new BlockAlreadyCommittedException(msg);
        }
        INodeFile fileINode = storedBlock.getINode();
        if (!fileINode.isUnderConstruction()) {
          String msg = block + " is already commited, !fileINode.isUnderConstruction().";
          LOG.info(msg);
          throw new BlockAlreadyCommittedException(msg);
        }
        // Disallow client-initiated recovery once
        // NameNode initiated lease recovery starts
        String path = null;
        try {
          path = fileINode.getFullPathName();
        } catch (IOException ioe) {
          throw (BlockAlreadyCommittedException)
            new BlockAlreadyCommittedException(
                block + " is already deleted").initCause(ioe);
        }
        if (!fromNN && HdfsConstants.NN_RECOVERY_LEASEHOLDER.equals(
            leaseManager.getLeaseByPath(path).getHolder())) {
          String msg = block +
            "is being recovered by NameNode, ignoring the request from a client";
          LOG.info(msg);
          throw new IOException(msg);
        }
        if (!((INodeFileUnderConstruction) fileINode).setLastRecoveryTime(now())) {
          String msg = block + " is being recovered, ignoring this request.";
          LOG.info(msg);
          throw new IOException(msg);
        }
        return nextGenerationStamp();
      } finally {
        writeUnlock();
      }
    }
docs: Verifies that the block is associated with a file that has a lease.
  Increments, logs and then returns the stamp
  
  @param block block
  @param fromNN if it is for lease recovery initiated by NameNode
  @return a new generation stamp