org.apache.hadoop.hbase.io
Class FileLink

java.lang.Object
  extended by org.apache.hadoop.hbase.io.FileLink
Direct Known Subclasses:
HFileLink, HLogLink

@InterfaceAudience.Private
public class FileLink
extends Object

The FileLink is a sort of hardlink, that allows access to a file given a set of locations.

The Problem:

If we want to create a reference to a file, we need to remember that it can be in its original location or in the archive folder. The FileLink class tries to abstract this concept and given a set of locations it is able to switch between them making this operation transparent for the user. HFileLink is a more concrete implementation of the FileLink.

Back-references: To help the CleanerChore to keep track of the links to a particular file, during the FileLink creation, a new file is placed inside a back-reference directory. There's one back-reference directory for each file that has links, and in the directory there's one file per link.

HFileLink Example


Field Summary
static String BACK_REFERENCES_DIRECTORY_PREFIX
          Define the Back-reference directory name prefix: .links-/
 
Constructor Summary
protected FileLink()
           
  FileLink(Collection<org.apache.hadoop.fs.Path> locations)
           
  FileLink(org.apache.hadoop.fs.Path originPath, org.apache.hadoop.fs.Path... alternativePaths)
           
 
Method Summary
 boolean exists(org.apache.hadoop.fs.FileSystem fs)
           
 org.apache.hadoop.fs.Path getAvailablePath(org.apache.hadoop.fs.FileSystem fs)
           
static String getBackReferenceFileName(org.apache.hadoop.fs.Path dirPath)
          Get the referenced file name from the reference link directory path.
static org.apache.hadoop.fs.Path getBackReferencesDir(org.apache.hadoop.fs.Path storeDir, String fileName)
          Get the directory to store the link back references
 org.apache.hadoop.fs.FileStatus getFileStatus(org.apache.hadoop.fs.FileSystem fs)
          Get the FileStatus of the referenced file.
 org.apache.hadoop.fs.Path[] getLocations()
           
static boolean isBackReferencesDir(org.apache.hadoop.fs.Path dirPath)
          Checks if the specified directory path is a back reference links folder.
 org.apache.hadoop.fs.FSDataInputStream open(org.apache.hadoop.fs.FileSystem fs)
          Open the FileLink for read.
 org.apache.hadoop.fs.FSDataInputStream open(org.apache.hadoop.fs.FileSystem fs, int bufferSize)
          Open the FileLink for read.
protected  void setLocations(org.apache.hadoop.fs.Path originPath, org.apache.hadoop.fs.Path... alternativePaths)
          NOTE: This method must be used only in the constructor! It creates a List with the specified locations for the link.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

BACK_REFERENCES_DIRECTORY_PREFIX

public static final String BACK_REFERENCES_DIRECTORY_PREFIX
Define the Back-reference directory name prefix: .links-/

See Also:
Constant Field Values
Constructor Detail

FileLink

protected FileLink()

FileLink

public FileLink(org.apache.hadoop.fs.Path originPath,
                org.apache.hadoop.fs.Path... alternativePaths)
Parameters:
originPath - Original location of the file to link
alternativePaths - Alternative locations to look for the linked file

FileLink

public FileLink(Collection<org.apache.hadoop.fs.Path> locations)
Parameters:
locations - locations to look for the linked file
Method Detail

getLocations

public org.apache.hadoop.fs.Path[] getLocations()
Returns:
the locations to look for the linked file.

toString

public String toString()
Overrides:
toString in class Object

exists

public boolean exists(org.apache.hadoop.fs.FileSystem fs)
               throws IOException
Returns:
true if the file pointed by the link exists
Throws:
IOException

getAvailablePath

public org.apache.hadoop.fs.Path getAvailablePath(org.apache.hadoop.fs.FileSystem fs)
                                           throws IOException
Returns:
the path of the first available link.
Throws:
IOException

getFileStatus

public org.apache.hadoop.fs.FileStatus getFileStatus(org.apache.hadoop.fs.FileSystem fs)
                                              throws IOException
Get the FileStatus of the referenced file.

Parameters:
fs - FileSystem on which to get the file status
Returns:
InputStream for the hfile link.
Throws:
IOException - on unexpected error.

open

public org.apache.hadoop.fs.FSDataInputStream open(org.apache.hadoop.fs.FileSystem fs)
                                            throws IOException
Open the FileLink for read.

It uses a wrapper of FSDataInputStream that is agnostic to the location of the file, even if the file switches between locations.

Parameters:
fs - FileSystem on which to open the FileLink
Returns:
InputStream for reading the file link.
Throws:
IOException - on unexpected error.

open

public org.apache.hadoop.fs.FSDataInputStream open(org.apache.hadoop.fs.FileSystem fs,
                                                   int bufferSize)
                                            throws IOException
Open the FileLink for read.

It uses a wrapper of FSDataInputStream that is agnostic to the location of the file, even if the file switches between locations.

Parameters:
fs - FileSystem on which to open the FileLink
bufferSize - the size of the buffer to be used.
Returns:
InputStream for reading the file link.
Throws:
IOException - on unexpected error.

setLocations

protected void setLocations(org.apache.hadoop.fs.Path originPath,
                            org.apache.hadoop.fs.Path... alternativePaths)
NOTE: This method must be used only in the constructor! It creates a List with the specified locations for the link.


getBackReferencesDir

public static org.apache.hadoop.fs.Path getBackReferencesDir(org.apache.hadoop.fs.Path storeDir,
                                                             String fileName)
Get the directory to store the link back references

To simplify the reference count process, during the FileLink creation a back-reference is added to the back-reference directory of the specified file.

Parameters:
storeDir - Root directory for the link reference folder
fileName - File Name with links
Returns:
Path for the link back references.

getBackReferenceFileName

public static String getBackReferenceFileName(org.apache.hadoop.fs.Path dirPath)
Get the referenced file name from the reference link directory path.

Parameters:
dirPath - Link references directory path
Returns:
Name of the file referenced

isBackReferencesDir

public static boolean isBackReferencesDir(org.apache.hadoop.fs.Path dirPath)
Checks if the specified directory path is a back reference links folder.

Parameters:
dirPath - Directory path to verify
Returns:
True if the specified directory is a link references folder


Copyright © 2015 The Apache Software Foundation. All rights reserved.