Skip to content

In HadoopAttributeStore, get absolute path for attributePath - #2123

Merged
lossyrob merged 2 commits into
locationtech:masterfrom
lossyrob:fix/hadoop-layer-exists
Apr 4, 2017
Merged

lossyrob merged 2 commits into
locationtech:masterfrom
lossyrob:fix/hadoop-layer-exists

Conversation

@lossyrob

@lossyrob lossyrob commented Apr 4, 2017

Copy link
Copy Markdown
Member

Fixes #2113

What was happening is, because the attributePath was being stored as a local path, the attributePath method returned the relative path as well; when being compared to listed paths in layerExists, it would always fail the match. This didn't surface itself beforehand because we would always use absolute paths with HadoopLayer types; this prevents a problem if a user decides to user a relative path when the default filesystem is local.

This was a bit tough to capture in a unit test, but I did test this manually against geotrellis-landsat-tutorial.

val ap = new Path(rootPath, "_attributes")
val fs = ap.getFileSystem(hadoopConfiguration)
// Get the absolute path to attributes
(fs, fs.getFileStatus(ap).getPath)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getFileStatus throws FileNotFoundException when the path does not exist

@pomadchin pomadchin Apr 4, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A straightforward solution would be to use try catch, and to create dirs on exception.
Another solution would be to getFileStatus of a root path and to create only _attributes folder, but that would require manual catalog creation, and still would throw runtime exceptions.

val (fs, attributePath) = {
  val ap = new Path(rootPath, "_attributes")
  val fs = ap.getFileSystem(hadoopConfiguration)
  // Get the absolute path to attributes
  try {
    fs.getFileStatus(ap)
  } catch {
    case _: FileNotFoundException => fs.mkdirs(ap)
  }

  (fs, fs.getFileStatus(ap).getPath)
}

@pomadchin pomadchin Apr 4, 2017 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, try catch way would be ok, here is exists method implementation:

public boolean exists(Path f) throws IOException {
  try {
    return getFileStatus(f) != null;
  } catch (FileNotFoundException e) {
    return false;
  }
}

The result smth like:

val (fs, attributePath) = {
  val ap = new Path(rootPath, "_attributes")
  val fs = ap.getFileSystem(hadoopConfiguration)

  // Create directory if it doesn't exist
  if(!fs.exists(ap)) fs.mkdirs(ap)

  // Get the absolute path to attributes
  (fs, fs.getFileStatus(ap).getPath)
}

Signed-off-by: Grigory Pomadchin <[email protected]>
@pomadchin
pomadchin force-pushed the fix/hadoop-layer-exists branch from c4ee998 to 5beed5c Compare April 4, 2017 06:10
@pomadchin pomadchin added this to the 1.1 milestone Apr 4, 2017
@lossyrob
lossyrob merged commit 3e3c3b7 into locationtech:master Apr 4, 2017
@lossyrob lossyrob changed the title Get absolute path for attributePath In HadoopAttributeStore, get absolute path for attributePath Apr 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants