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; 019 020import org.apache.hadoop.classification.InterfaceAudience; 021import org.apache.hadoop.classification.InterfaceStability; 022import org.apache.hadoop.conf.Configuration; 023 024/** 025 * The public API for creating a new ReplicaAccessor. 026 */ 027@InterfaceAudience.Public 028@InterfaceStability.Stable 029public abstract class ReplicaAccessorBuilder { 030 /** 031 * Set the file name which is being opened. Provided for debugging purposes. 032 */ 033 public abstract ReplicaAccessorBuilder setFileName(String fileName); 034 035 /** Set the block ID and block pool ID which are being opened. */ 036 public abstract ReplicaAccessorBuilder 037 setBlock(long blockId, String blockPoolId); 038 039 /** Set the genstamp of the block which is being opened. */ 040 public abstract ReplicaAccessorBuilder setGenerationStamp(long genstamp); 041 042 /** 043 * Set whether checksums must be verified. Checksums should be skipped if 044 * the user has disabled checksum verification in the configuration. Users 045 * may wish to do this if their software does checksum verification at a 046 * higher level than HDFS. 047 */ 048 public abstract ReplicaAccessorBuilder 049 setVerifyChecksum(boolean verifyChecksum); 050 051 /** Set the name of the HDFS client. Provided for debugging purposes. */ 052 public abstract ReplicaAccessorBuilder setClientName(String clientName); 053 054 /** 055 * Set whether short-circuit is enabled. Short-circuit may be disabled if 056 * the user has set dfs.client.read.shortcircuit to false, or if the block 057 * being read is under construction. The fact that this bit is enabled does 058 * not mean that the user has permission to do short-circuit reads or to 059 * access the replica-- that must be checked separately by the 060 * ReplicaAccessorBuilder implementation. 061 */ 062 public abstract ReplicaAccessorBuilder 063 setAllowShortCircuitReads(boolean allowShortCircuit); 064 065 /** 066 * Set the length of the replica which is visible to this client. If bytes 067 * are added later, they will not be visible to the ReplicaAccessor we are 068 * building. In order to see more of the replica, the client must re-open 069 * this HDFS file. The visible length provides an upper bound, but not a 070 * lower one. If the replica is deleted or truncated, fewer bytes may be 071 * visible than specified here. 072 */ 073 public abstract ReplicaAccessorBuilder setVisibleLength(long visibleLength); 074 075 /** 076 * Set the configuration to use. ReplicaAccessorBuilder subclasses should 077 * define their own configuration prefix. For example, the foobar plugin 078 * could look for configuration keys like foo.bar.parameter1, 079 * foo.bar.parameter2. 080 */ 081 public abstract ReplicaAccessorBuilder setConfiguration(Configuration conf); 082 083 /** 084 * Set the block access token to use. 085 */ 086 public abstract ReplicaAccessorBuilder setBlockAccessToken(byte[] token); 087 088 /** 089 * Build a new ReplicaAccessor. 090 * 091 * The implementation must perform any necessary access checks before 092 * constructing the ReplicaAccessor. If there is a hardware-level or 093 * network-level setup operation that could fail, it should be done here. If 094 * the implementation returns a ReplicaAccessor, we will assume that it works 095 * and not attempt to construct a normal BlockReader. 096 * 097 * If the ReplicaAccessor could not be built, implementations may wish to log 098 * a message at TRACE level indicating why. 099 * 100 * @return null if the ReplicaAccessor could not be built; the 101 * ReplicaAccessor otherwise. 102 */ 103 public abstract ReplicaAccessor build(); 104}