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 */
018 package org.apache.hadoop.hdfs.server.namenode;
019
020 import org.apache.hadoop.classification.InterfaceAudience;
021 import org.apache.hadoop.fs.permission.PermissionStatus;
022 import org.apache.hadoop.hdfs.server.namenode.INodeFile.HeaderFormat;
023 import org.apache.hadoop.hdfs.server.namenode.XAttrFeature;
024 /**
025 * The attributes of a file.
026 */
027 @InterfaceAudience.Private
028 public interface INodeFileAttributes extends INodeAttributes {
029 /** @return the file replication. */
030 public short getFileReplication();
031
032 /** @return preferred block size in bytes */
033 public long getPreferredBlockSize();
034
035 /** @return the header as a long. */
036 public long getHeaderLong();
037
038 public boolean metadataEquals(INodeFileAttributes other);
039
040 public byte getLocalStoragePolicyID();
041
042 /** A copy of the inode file attributes */
043 public static class SnapshotCopy extends INodeAttributes.SnapshotCopy
044 implements INodeFileAttributes {
045 private final long header;
046
047 public SnapshotCopy(byte[] name, PermissionStatus permissions,
048 AclFeature aclFeature, long modificationTime, long accessTime,
049 short replication, long preferredBlockSize, byte storagePolicyID,
050 XAttrFeature xAttrsFeature) {
051 super(name, permissions, aclFeature, modificationTime, accessTime,
052 xAttrsFeature);
053 header = HeaderFormat.toLong(preferredBlockSize, replication, storagePolicyID);
054 }
055
056 public SnapshotCopy(INodeFile file) {
057 super(file);
058 this.header = file.getHeaderLong();
059 }
060
061 @Override
062 public short getFileReplication() {
063 return HeaderFormat.getReplication(header);
064 }
065
066 @Override
067 public long getPreferredBlockSize() {
068 return HeaderFormat.getPreferredBlockSize(header);
069 }
070
071 @Override
072 public byte getLocalStoragePolicyID() {
073 return HeaderFormat.getStoragePolicyID(header);
074 }
075
076 @Override
077 public long getHeaderLong() {
078 return header;
079 }
080
081 @Override
082 public boolean metadataEquals(INodeFileAttributes other) {
083 return other != null
084 && getHeaderLong()== other.getHeaderLong()
085 && getPermissionLong() == other.getPermissionLong()
086 && getAclFeature() == other.getAclFeature()
087 && getXAttrFeature() == other.getXAttrFeature();
088 }
089 }
090 }