Example usage for org.apache.hadoop.hdfs.server.blockmanagement BlockInfo BlockInfo

List of usage examples for org.apache.hadoop.hdfs.server.blockmanagement BlockInfo BlockInfo

Introduction

In this page you can find the example usage for org.apache.hadoop.hdfs.server.blockmanagement BlockInfo BlockInfo.

Prototype

BlockInfo

Source Link

Usage

From source file:io.hops.metadata.lock.TestNDBSizer.java

License:Apache License

private void insertData() throws StorageException, StorageException, IOException {
    System.out.println("Building the data...");

    final int NUM_INODES = 500000;
    final int NUM_BLOCKS = 1200000;//2000000;
    final int NUM_REPLICAS = 3600000;//6000000;
    final int BATCH_SIZE = 5000;

    String filename = "";
    for (int i = 0; i < 100; i++) {
        filename += "-";
    }//from w ww .  jav a2 s  .co  m

    final List<INode> newFiles = new LinkedList<INode>();
    for (int i = 0; i < NUM_INODES; i++) {
        INodeDirectory dir = new INodeDirectoryWithQuota("",
                new PermissionStatus("salman", "usr", new FsPermission((short) 0777)));
        dir.setIdNoPersistance(i);
        dir.setLocalNameNoPersistance(filename + Integer.toString(i));
        dir.setParentIdNoPersistance(i);
        newFiles.add(dir);
        if (newFiles.size() >= BATCH_SIZE) {
            final int j = i;
            new LightWeightRequestHandler(HDFSOperationType.TEST) {
                @Override
                public Object performTask() throws StorageException, IOException {
                    INodeDataAccess da = (INodeDataAccess) HdfsStorageFactory
                            .getDataAccess(INodeDataAccess.class);
                    da.prepare(new LinkedList<INode>(), newFiles, new LinkedList<INode>());
                    newFiles.clear();
                    showProgressBar("INodes", j, NUM_INODES);
                    return null;
                }
            }.handle();

        }
    }

    System.out.println();

    final List<BlockInfo> newBlocks = new LinkedList<BlockInfo>();
    for (int i = 0; i < NUM_BLOCKS; i++) {
        BlockInfo block = new BlockInfo();
        block.setINodeIdNoPersistance(i);
        block.setBlockIdNoPersistance(i);
        newBlocks.add(block);
        if (newBlocks.size() >= BATCH_SIZE) {
            final int j = i;
            new LightWeightRequestHandler(HDFSOperationType.TEST) {
                @Override
                public Object performTask() throws StorageException, IOException {
                    BlockInfoDataAccess bda = (BlockInfoDataAccess) HdfsStorageFactory
                            .getDataAccess(BlockInfoDataAccess.class);
                    bda.prepare(new LinkedList<BlockInfo>(), newBlocks, new LinkedList<BlockInfo>());
                    newBlocks.clear();
                    showProgressBar("Blocks", j, NUM_BLOCKS);
                    return null;
                }
            }.handle();

        }
    }

    System.out.println();

    final List<IndexedReplica> replicas = new LinkedList<IndexedReplica>();
    for (int i = 0; i < NUM_REPLICAS; i++) {
        replicas.add(new IndexedReplica(i, i, i, i));
        if (replicas.size() >= BATCH_SIZE) {
            final int j = i;
            new LightWeightRequestHandler(HDFSOperationType.TEST) {
                @Override
                public Object performTask() throws StorageException, IOException {
                    ReplicaDataAccess rda = (ReplicaDataAccess) HdfsStorageFactory
                            .getDataAccess(ReplicaDataAccess.class);
                    rda.prepare(new LinkedList<IndexedReplica>(), replicas, new LinkedList<IndexedReplica>());
                    //StorageFactory.getConnector().commit();
                    replicas.clear();
                    showProgressBar("Replicas", j, NUM_REPLICAS);
                    return null;
                }
            }.handle();

        }
    }
}

From source file:io.hops.transaction.lock.IndividualBlockLock.java

License:Apache License

@Override
protected void acquire(TransactionLocks locks) throws IOException {
    if (blockId != NON_EXISTING_BLOCK) {
        BlockInfo result = acquireLock(DEFAULT_LOCK_TYPE, BlockInfo.Finder.ByBlockIdAndINodeId, blockId,
                inodeId);//from  w ww.ja  v a 2  s .c  o m
        if (result != null) {
            blocks.add(result);
        } else {
            //TODO fix this add a method to bring null in the others caches 
            BlockInfo dummy = new BlockInfo();
            dummy.setINodeIdNoPersistance(inodeId);
            dummy.setBlockIdNoPersistance(blockId);
            blocks.add(dummy);
        }
    }
}