HBASE-12414 Move HFileLink.exists() to base class
This commit is contained in:
parent
c84b13514e
commit
b827b6d02e
|
@ -337,22 +337,33 @@ public class FileLink {
|
|||
public String toString() {
|
||||
StringBuilder str = new StringBuilder(getClass().getName());
|
||||
str.append(" locations=[");
|
||||
int i = 0;
|
||||
for (Path location: locations) {
|
||||
if (i++ > 0) str.append(", ");
|
||||
str.append(location.toString());
|
||||
for (int i = 0; i < locations.length; ++i) {
|
||||
if (i > 0) str.append(", ");
|
||||
str.append(locations[i].toString());
|
||||
}
|
||||
str.append("]");
|
||||
return str.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the file pointed by the link exists
|
||||
*/
|
||||
public boolean exists(final FileSystem fs) throws IOException {
|
||||
for (int i = 0; i < locations.length; ++i) {
|
||||
if (fs.exists(locations[i])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the path of the first available link.
|
||||
*/
|
||||
public Path getAvailablePath(FileSystem fs) throws IOException {
|
||||
for (Path path: locations) {
|
||||
if (fs.exists(path)) {
|
||||
return path;
|
||||
for (int i = 0; i < locations.length; ++i) {
|
||||
if (fs.exists(locations[i])) {
|
||||
return locations[i];
|
||||
}
|
||||
}
|
||||
throw new FileNotFoundException("Unable to open link: " + this);
|
||||
|
@ -366,9 +377,9 @@ public class FileLink {
|
|||
* @throws IOException on unexpected error.
|
||||
*/
|
||||
public FileStatus getFileStatus(FileSystem fs) throws IOException {
|
||||
for (Path path: locations) {
|
||||
for (int i = 0; i < locations.length; ++i) {
|
||||
try {
|
||||
return fs.getFileStatus(path);
|
||||
return fs.getFileStatus(locations[i]);
|
||||
} catch (FileNotFoundException e) {
|
||||
// Try another file location
|
||||
}
|
||||
|
|
|
@ -245,15 +245,6 @@ public class HFileLink extends FileLink {
|
|||
return(TableName.valueOf(m.group(1), m.group(2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the HFileLink exists
|
||||
*/
|
||||
public boolean exists(final FileSystem fs) throws IOException {
|
||||
return fs.exists(this.originPath) ||
|
||||
fs.exists(this.tempPath) ||
|
||||
fs.exists(this.archivePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new HFileLink name
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue