Skip to content

Commit

Permalink
Timeout on Avro file decodes because some people have ridiculously lo…
Browse files Browse the repository at this point in the history
…ng messages.
  • Loading branch information
rbpark committed Mar 20, 2012
1 parent 465524d commit 2f9c838
Showing 1 changed file with 5 additions and 2 deletions.
Expand Up @@ -27,7 +27,9 @@
public class HdfsAvroFileViewer implements HdfsFileViewer {

private static Logger logger = Logger.getLogger(HdfsAvroFileViewer.class);

// Will spend 5 seconds trying to pull data and then stop.
private static long STOP_TIME = 5000l;

@Override
public boolean canReadFile(FileSystem fs, Path path) {

Expand Down Expand Up @@ -79,8 +81,9 @@ public void displayFile(FileSystem fs,
g.useDefaultPrettyPrinter();
Encoder encoder = new JsonEncoder(schema, g);

long endTime = System.currentTimeMillis() + STOP_TIME;
int lineno = 1; // line number starts from 1
while(avroDatastream.hasNext() && lineno <= endLine) {
while(avroDatastream.hasNext() && lineno <= endLine && System.currentTimeMillis() <= endTime) {
Object datum = avroDatastream.next();
if(lineno >= startLine) {
String record = "\n\n Record " + lineno + ":\n";
Expand Down

0 comments on commit 2f9c838

Please sign in to comment.