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 public DatanodeStorage(String storageID) { 053 this(storageID, State.NORMAL, StorageType.DEFAULT); 054 } 055 056 public DatanodeStorage(String sid, State s, StorageType sm) { 057 this.storageID = sid; 058 this.state = s; 059 this.storageType = sm; 060 } 061 062 public String getStorageID() { 063 return storageID; 064 } 065 066 public State getState() { 067 return state; 068 } 069 070 public StorageType getStorageType() { 071 return storageType; 072 } 073 074 /** 075 * Generate new storage ID. The format of this string can be changed 076 * in the future without requiring that old storage IDs be updated. 077 * 078 * @return unique storage ID 079 */ 080 public static String generateUuid() { 081 return "DS-" + UUID.randomUUID(); 082 } 083 084 @Override 085 public String toString() { 086 return "DatanodeStorage["+ storageID + "," + storageType + "," + state +"]"; 087 } 088 089 @Override 090 public boolean equals(Object other){ 091 if (other == this) { 092 return true; 093 } 094 095 if ((other == null) || 096 !(other instanceof DatanodeStorage)) { 097 return false; 098 } 099 DatanodeStorage otherStorage = (DatanodeStorage) other; 100 return otherStorage.getStorageID().compareTo(getStorageID()) == 0; 101 } 102 103 @Override 104 public int hashCode() { 105 return getStorageID().hashCode(); 106 } 107}