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.protocol; 019 020import org.apache.hadoop.classification.InterfaceAudience; 021import org.apache.hadoop.classification.InterfaceStability; 022import org.apache.hadoop.io.erasurecode.ECSchema; 023 024/** 025 * A policy about how to write/read/code an erasure coding file. 026 */ 027@InterfaceAudience.Public 028@InterfaceStability.Evolving 029public final class ErasureCodingPolicy { 030 031 private final String name; 032 private final ECSchema schema; 033 private final int cellSize; 034 035 public ErasureCodingPolicy(String name, ECSchema schema, int cellSize){ 036 this.name = name; 037 this.schema = schema; 038 this.cellSize = cellSize; 039 } 040 041 public String getName() { 042 return name; 043 } 044 045 public ECSchema getSchema() { 046 return schema; 047 } 048 049 public int getCellSize() { 050 return cellSize; 051 } 052 053 public int getNumDataUnits() { 054 return schema.getNumDataUnits(); 055 } 056 057 public int getNumParityUnits() { 058 return schema.getNumParityUnits(); 059 } 060 061 @Override 062 public boolean equals(Object o) { 063 if (this == o) { 064 return true; 065 } 066 if (o == null || getClass() != o.getClass()) { 067 return false; 068 } 069 ErasureCodingPolicy that = (ErasureCodingPolicy) o; 070 071 return that.getName().equals(name) && 072 that.getCellSize() == cellSize && 073 that.getSchema().equals(schema); 074 } 075 076 @Override 077 public int hashCode() { 078 int result = name.hashCode(); 079 result = 31 * result + schema.hashCode(); 080 result = 31 * result + cellSize; 081 return result; 082 } 083 084 @Override 085 public String toString() { 086 return "ErasureCodingPolicy=[" + "Name=" + name + ", " 087 + "Schema=[" + schema.toString() + "], " 088 + "CellSize=" + cellSize + " " + "]"; 089 } 090}