Java Code Examples for org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoContiguous#EMPTY_ARRAY

The following examples show how to use org.apache.hadoop.hdfs.server.blockmanagement.BlockInfoContiguous#EMPTY_ARRAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestEditLog.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  PermissionStatus p = namesystem.createFsOwnerPermissions(
                                      new FsPermission((short)0777));
  FSEditLog editLog = namesystem.getEditLog();

  for (int i = 0; i < numTransactions; i++) {
    INodeFile inode = new INodeFile(namesystem.dir.allocateNewInodeId(), null,
        p, 0L, 0L, BlockInfoContiguous.EMPTY_ARRAY, replication, blockSize);
    inode.toUnderConstruction("", "");

    editLog.logOpenFile("/filename" + (startIndex + i), inode, false, false);
    editLog.logCloseFile("/filename" + (startIndex + i), inode);
    editLog.logSync();
  }
}
 
Example 2
Source File: TestEditLog.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
  PermissionStatus p = namesystem.createFsOwnerPermissions(
                                      new FsPermission((short)0777));
  FSEditLog editLog = namesystem.getEditLog();

  for (int i = 0; i < numTransactions; i++) {
    INodeFile inode = new INodeFile(namesystem.dir.allocateNewInodeId(), null,
        p, 0L, 0L, BlockInfoContiguous.EMPTY_ARRAY, replication, blockSize);
    inode.toUnderConstruction("", "");

    editLog.logOpenFile("/filename" + (startIndex + i), inode, false, false);
    editLog.logCloseFile("/filename" + (startIndex + i), inode);
    editLog.logSync();
  }
}
 
Example 3
Source File: FSDirectory.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private static INodeFile newINodeFile(long id, PermissionStatus permissions,
    long mtime, long atime, short replication, long preferredBlockSize,
    byte storagePolicyId) {
  return new INodeFile(id, null, permissions, mtime, atime,
      BlockInfoContiguous.EMPTY_ARRAY, replication, preferredBlockSize,
      storagePolicyId);
}
 
Example 4
Source File: INodeFile.java    From hadoop with Apache License 2.0 5 votes vote down vote up
void truncateBlocksTo(int n) {
  final BlockInfoContiguous[] newBlocks;
  if (n == 0) {
    newBlocks = BlockInfoContiguous.EMPTY_ARRAY;
  } else {
    newBlocks = new BlockInfoContiguous[n];
    System.arraycopy(getBlocks(), 0, newBlocks, 0, n);
  }
  // set new blocks
  setBlocks(newBlocks);
}
 
Example 5
Source File: FSDirectory.java    From big-c with Apache License 2.0 5 votes vote down vote up
private static INodeFile newINodeFile(long id, PermissionStatus permissions,
    long mtime, long atime, short replication, long preferredBlockSize,
    byte storagePolicyId) {
  return new INodeFile(id, null, permissions, mtime, atime,
      BlockInfoContiguous.EMPTY_ARRAY, replication, preferredBlockSize,
      storagePolicyId);
}
 
Example 6
Source File: INodeFile.java    From big-c with Apache License 2.0 5 votes vote down vote up
void truncateBlocksTo(int n) {
  final BlockInfoContiguous[] newBlocks;
  if (n == 0) {
    newBlocks = BlockInfoContiguous.EMPTY_ARRAY;
  } else {
    newBlocks = new BlockInfoContiguous[n];
    System.arraycopy(getBlocks(), 0, newBlocks, 0, n);
  }
  // set new blocks
  setBlocks(newBlocks);
}
 
Example 7
Source File: CreateEditsLog.java    From hadoop with Apache License 2.0 4 votes vote down vote up
static void addFiles(FSEditLog editLog, int numFiles, short replication, 
                       int blocksPerFile, long startingBlockId, long blockSize,
                       FileNameGenerator nameGenerator) {
  
  PermissionStatus p = new PermissionStatus("joeDoe", "people",
                                    new FsPermission((short)0777));
  INodeId inodeId = new INodeId();
  INodeDirectory dirInode = new INodeDirectory(inodeId.nextValue(), null, p,
    0L);
  editLog.logMkDir(BASE_PATH, dirInode);
  BlockInfoContiguous[] blocks = new BlockInfoContiguous[blocksPerFile];
  for (int iB = 0; iB < blocksPerFile; ++iB) {
    blocks[iB] = 
     new BlockInfoContiguous(new Block(0, blockSize, BLOCK_GENERATION_STAMP),
                             replication);
  }
  
  long currentBlockId = startingBlockId;
  long bidAtSync = startingBlockId;

  for (int iF = 0; iF < numFiles; iF++) {
    for (int iB = 0; iB < blocksPerFile; ++iB) {
       blocks[iB].setBlockId(currentBlockId++);
    }

    final INodeFile inode = new INodeFile(inodeId.nextValue(), null,
        p, 0L, 0L, blocks, replication, blockSize, (byte)0);
    inode.toUnderConstruction("", "");

   // Append path to filename with information about blockIDs 
    String path = "_" + iF + "_B" + blocks[0].getBlockId() + 
                  "_to_B" + blocks[blocksPerFile-1].getBlockId() + "_";
    String filePath = nameGenerator.getNextFileName("");
    filePath = filePath + path;
    // Log the new sub directory in edits
    if ((iF % nameGenerator.getFilesPerDirectory())  == 0) {
      String currentDir = nameGenerator.getCurrentDir();
      dirInode = new INodeDirectory(inodeId.nextValue(), null, p, 0L);
      editLog.logMkDir(currentDir, dirInode);
    }
    INodeFile fileUc = new INodeFile(inodeId.nextValue(), null,
        p, 0L, 0L, BlockInfoContiguous.EMPTY_ARRAY, replication, blockSize);
    fileUc.toUnderConstruction("", "");
    editLog.logOpenFile(filePath, fileUc, false, false);
    editLog.logCloseFile(filePath, inode);

    if (currentBlockId - bidAtSync >= 2000) { // sync every 2K blocks
      editLog.logSync();
      bidAtSync = currentBlockId;
    }
  }
  System.out.println("Created edits log in directory " + edits_dir);
  System.out.println(" containing " +
     numFiles + " File-Creates, each file with " + blocksPerFile + " blocks");
  System.out.println(" blocks range: " + 
      startingBlockId + " to " + (currentBlockId-1));
}
 
Example 8
Source File: CreateEditsLog.java    From big-c with Apache License 2.0 4 votes vote down vote up
static void addFiles(FSEditLog editLog, int numFiles, short replication, 
                       int blocksPerFile, long startingBlockId, long blockSize,
                       FileNameGenerator nameGenerator) {
  
  PermissionStatus p = new PermissionStatus("joeDoe", "people",
                                    new FsPermission((short)0777));
  INodeId inodeId = new INodeId();
  INodeDirectory dirInode = new INodeDirectory(inodeId.nextValue(), null, p,
    0L);
  editLog.logMkDir(BASE_PATH, dirInode);
  BlockInfoContiguous[] blocks = new BlockInfoContiguous[blocksPerFile];
  for (int iB = 0; iB < blocksPerFile; ++iB) {
    blocks[iB] = 
     new BlockInfoContiguous(new Block(0, blockSize, BLOCK_GENERATION_STAMP),
                             replication);
  }
  
  long currentBlockId = startingBlockId;
  long bidAtSync = startingBlockId;

  for (int iF = 0; iF < numFiles; iF++) {
    for (int iB = 0; iB < blocksPerFile; ++iB) {
       blocks[iB].setBlockId(currentBlockId++);
    }

    final INodeFile inode = new INodeFile(inodeId.nextValue(), null,
        p, 0L, 0L, blocks, replication, blockSize, (byte)0);
    inode.toUnderConstruction("", "");

   // Append path to filename with information about blockIDs 
    String path = "_" + iF + "_B" + blocks[0].getBlockId() + 
                  "_to_B" + blocks[blocksPerFile-1].getBlockId() + "_";
    String filePath = nameGenerator.getNextFileName("");
    filePath = filePath + path;
    // Log the new sub directory in edits
    if ((iF % nameGenerator.getFilesPerDirectory())  == 0) {
      String currentDir = nameGenerator.getCurrentDir();
      dirInode = new INodeDirectory(inodeId.nextValue(), null, p, 0L);
      editLog.logMkDir(currentDir, dirInode);
    }
    INodeFile fileUc = new INodeFile(inodeId.nextValue(), null,
        p, 0L, 0L, BlockInfoContiguous.EMPTY_ARRAY, replication, blockSize);
    fileUc.toUnderConstruction("", "");
    editLog.logOpenFile(filePath, fileUc, false, false);
    editLog.logCloseFile(filePath, inode);

    if (currentBlockId - bidAtSync >= 2000) { // sync every 2K blocks
      editLog.logSync();
      bidAtSync = currentBlockId;
    }
  }
  System.out.println("Created edits log in directory " + edits_dir);
  System.out.println(" containing " +
     numFiles + " File-Creates, each file with " + blocksPerFile + " blocks");
  System.out.println(" blocks range: " + 
      startingBlockId + " to " + (currentBlockId-1));
}