001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hdfs.server.protocol; 019 020import org.apache.hadoop.hdfs.StorageType; 021 022import java.util.UUID; 023 024/** 025 * Class captures information of a storage in Datanode. 026 */ 027public class DatanodeStorage { 028 /** The state of the storage. */ 029 public enum State { 030 NORMAL, 031 032 /** 033 * A storage that represents a read-only path to replicas stored on a shared storage device. 034 * Replicas on {@link #READ_ONLY_SHARED} storage are not counted towards live replicas. 035 * 036 * <p> 037 * In certain implementations, a {@link #READ_ONLY_SHARED} storage may be correlated to 038 * its {@link #NORMAL} counterpart using the {@link DatanodeStorage#storageID}. This 039 * property should be used for debugging purposes only. 040 * </p> 041 */ 042 READ_ONLY_SHARED; 043 } 044 045 private final String storageID; 046 private final State state; 047 private final StorageType storageType; 048 049 /** 050 * Create a storage with {@link State#NORMAL} and {@link StorageType#DEFAULT}. 051 * 052 * @param storageID 053 */ 054 public DatanodeStorage(String storageID) { 055 this(storageID, State.NORMAL, StorageType.DEFAULT); 056 } 057 058 public DatanodeStorage(String sid, State s, StorageType sm) { 059 this.storageID = sid; 060 this.state = s; 061 this.storageType = sm; 062 } 063 064 public String getStorageID() { 065 return storageID; 066 } 067 068 public State getState() { 069 return state; 070 } 071 072 public StorageType getStorageType() { 073 return storageType; 074 } 075 076 /** 077 * Generate new storage ID. The format of this string can be changed 078 * in the future without requiring that old storage IDs be updated. 079 * 080 * @return unique storage ID 081 */ 082 public static String generateUuid() { 083 return "DS-" + UUID.randomUUID(); 084 } 085 086 @Override 087 public boolean equals(Object other){ 088 if (other == this) { 089 return true; 090 } 091 092 if ((other == null) || 093 !(other instanceof DatanodeStorage)) { 094 return false; 095 } 096 DatanodeStorage otherStorage = (DatanodeStorage) other; 097 return otherStorage.getStorageID().compareTo(getStorageID()) == 0; 098 } 099 100 @Override 101 public int hashCode() { 102 return getStorageID().hashCode(); 103 } 104}