3

I use the Hadoop's FileSystem class for deleting some HDFS files. The problem now is, that the client gets a Connection Timeout after a too long duration, I need to shrink the time to wait until the timeout, so that the user gets faster responses, if he/she is outside the network! Here my codes snippet:

try {
    System.setProperty("HADOOP_USER_NAME", "test");
    Configuration conf = new Configuration();
    File csvFile = new File(pathCsvFile);
    FileSystem hdfs = FileSystem.get(new URI(csvFile.getPath(), conf);
    if(hdfs.exists(new Path(filterValuesPath))) {
        hdfs.delete(new Path(filterValuesPath), true);
        setInfo("File deleted!");
    } else {
        setInfo("No file to delete!");
    }
} catch (Exception ex) {         // the timeout is too high!!!
    ex.printStackTrace();
    setInfo("No connection or no files to delete!");
}

Where and how can I set the timeout for my application? I don't want to change this in any Hadoop config files, just locally for my Java app. Thank you!

D. Müller
  • 3,336
  • 4
  • 36
  • 84

1 Answers1

0

There is a configuration key "ipc.client.connect.timeout",which "Indicates the number of milliseconds a client will wait for the socket to establish a server connection". You may set it directly or via org.apache.hadoop.ipc.Client#setConnectTimeout(Configuration conf, int timeout)

ZHAO Bo
  • 71
  • 5
  • Thank you for contributing to the Stack Overflow community. This may be a correct answer, but it’d be really useful to provide additional explanation of your code so developers can understand your reasoning. This is especially useful for new developers who aren’t as familiar with the syntax or struggling to understand the concepts. **Would you kindly [edit] your answer to include additional details for the benefit of the community?** – Jeremy Caney Aug 06 '23 at 00:54