Example usage for org.apache.hadoop.hdfs.server.blockmanagement DatanodeStorageInfo getDatanodeDescriptor

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

Introduction

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

Prototype

public DatanodeDescriptor getDatanodeDescriptor() 

Source Link

Usage

From source file:io.hops.metadata.StorageMap.java

License:Apache License

/**
 * Adds or replaces storageinfo for the given sid
 *//* ww w  .j a va 2 s. co m*/
public void updateStorage(final DatanodeStorageInfo storageInfo) {
    try {
        // Allow lookup of storageId (String) <--> sid (int)
        storageIdMap.update(storageInfo);

        // Also write to the storages table (mapping DN-Sid-storagetype)
        final int sid = storageInfo.getSid();
        final String datanodeUuid = storageInfo.getDatanodeDescriptor().getDatanodeUuid();
        final int storageType = storageInfo.getStorageType().ordinal();

        // Get the list of storages we know to be on this DN
        ArrayList<Integer> sids = this.datanodeUuidToSids.get(datanodeUuid);

        if (sids == null) { // First time we see this DN
            sids = new ArrayList<Integer>();
            this.datanodeUuidToSids.put(datanodeUuid, sids);
        }

        if (!sids.contains(sid)) { // We haven't seen this sid on this DN yet
            // Add in hashmap
            sids.add(sid);

            // Persist to database
            new HopsTransactionalRequestHandler(HDFSOperationType.UPDATE_SID_MAP) {
                @Override
                public void acquireLock(TransactionLocks locks) throws IOException {
                    LockFactory lf = LockFactory.getInstance();
                    locks.add(lf.getVariableLock(Variable.Finder.StorageMap, LockType.READ_COMMITTED));
                }

                @Override
                public Object performTask() throws StorageException, IOException {
                    StorageDataAccess<Storage> da = (StorageDataAccess) HdfsStorageFactory
                            .getDataAccess(StorageDataAccess.class);
                    Storage h = da.findByPk(sid);
                    if (h == null) {
                        h = new Storage(sid, datanodeUuid, storageType);
                        da.add(h);
                    }
                    return null;
                }
            }.handle();
        }
    } catch (IOException e) {
        // TODO throw some stuff?
        e.printStackTrace();
    }

    // Allow lookup of sid (int) -> DatanodeStorageInfo
    storageInfoMap.put(storageInfo.getSid(), storageInfo);
}