You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Mark Kerzner <ma...@gmail.com> on 2011/01/27 18:07:27 UTC

HBase example in Definitive Hadoop Guide - hangs?

Example 12-1. A MapReduce application to count the number of rows in an
HBase table

The code below hangs. Could it be because I am using the 0.89 version of
HBase when running, but 0.20 for the API (that's what this is example is
written for?

Thank you,
Mark

public class RowCounter extends Configured implements Tool {
  // Name of this 'program'
  static final String NAME = "rowcounter";

  static class RowCounterMapper
  implements TableMap<ImmutableBytesWritable, RowResult> {
    private static enum Counters {ROWS}

    public void map(ImmutableBytesWritable row, RowResult value,
        OutputCollector<ImmutableBytesWritable, RowResult> output,
        Reporter reporter)
    throws IOException {
      boolean content = false;
      for (Map.Entry<byte [], Cell> e: value.entrySet()) {
        Cell cell = e.getValue();
        if (cell != null && cell.getValue().length > 0) {
          content = true;
          break;
        }
      }
      if (!content) {
        // Don't count rows that are all empty values.
        return;
      }
      // Give out same value every time.  We're only interested in the row/key
      reporter.incrCounter(Counters.ROWS, 1);
    }

    public void configure(JobConf jc) {
      // Nothing to do.
    }

    public void close() throws IOException {
      // Nothing to do.
    }
  }

  public JobConf createSubmittableJob(String[] args) throws IOException {
    JobConf c = new JobConf(getConf(), getClass());
    c.setJobName(NAME);
    // Columns are space delimited
    StringBuilder sb = new StringBuilder();
    final int columnoffset = 2;
    for (int i = columnoffset; i < args.length; i++) {
      if (i > columnoffset) {
        sb.append(" ");
      }
      sb.append(args[i]);
    }
    // Second argument is the table name.
    TableMapReduceUtil.initTableMapJob(args[1], sb.toString(),
      RowCounterMapper.class, ImmutableBytesWritable.class, RowResult.class, c);
    c.setNumReduceTasks(0);
    // First arg is the output directory.
    FileOutputFormat.setOutputPath(c, new Path(args[0]));
    return c;
  }

  static int printUsage() {
    System.out.println(NAME +
      " <outputdir> <tablename> <column1> [<column2>...]");
    return -1;
  }

  public int run(final String[] args) throws Exception {
    // Make sure there are at least 3 parameters
    if (args.length < 3) {
      System.err.println("ERROR: Wrong number of parameters: " + args.length);
      return printUsage();
    }
    JobClient.runJob(createSubmittableJob(args));
    return 0;
  }

  public static void main(String[] args) throws Exception {
    HBaseConfiguration c = new HBaseConfiguration();
    int errCode = ToolRunner.run(c, new RowCounter(), args);
    System.exit(errCode);
  }
}

Re: HBase example in Definitive Hadoop Guide - hangs?

Posted by Mark Kerzner <ma...@gmail.com>.
The example is from the first version of the book, and I had to switch back
to V 0.20 of HBase for it to compile.

I read them on Safari. I got the second edition, and it does not have this
example at all.

After I have gone back to HBase .20 as a server, the example ran.

Thank you,
Mark

On Thu, Jan 27, 2011 at 11:51 AM, Stack <st...@duboce.net> wrote:

> Where did you get the code from?   From
> https://github.com/tomwhite/hadoop-book/?  Version 1 or 2 of the book?
>  If the code at github hangs, let us know and we'll fix it.
>
> St.Ack
>
> On Thu, Jan 27, 2011 at 9:07 AM, Mark Kerzner <ma...@gmail.com>
> wrote:
> > Example 12-1. A MapReduce application to count the number of rows in an
> > HBase table
> >
> > The code below hangs. Could it be because I am using the 0.89 version of
> > HBase when running, but 0.20 for the API (that's what this is example is
> > written for?
> >
> > Thank you,
> > Mark
> >
> > public class RowCounter extends Configured implements Tool {
> >  // Name of this 'program'
> >  static final String NAME = "rowcounter";
> >
> >  static class RowCounterMapper
> >  implements TableMap<ImmutableBytesWritable, RowResult> {
> >    private static enum Counters {ROWS}
> >
> >    public void map(ImmutableBytesWritable row, RowResult value,
> >        OutputCollector<ImmutableBytesWritable, RowResult> output,
> >        Reporter reporter)
> >    throws IOException {
> >      boolean content = false;
> >      for (Map.Entry<byte [], Cell> e: value.entrySet()) {
> >        Cell cell = e.getValue();
> >        if (cell != null && cell.getValue().length > 0) {
> >          content = true;
> >          break;
> >        }
> >      }
> >      if (!content) {
> >        // Don't count rows that are all empty values.
> >        return;
> >      }
> >      // Give out same value every time.  We're only interested in the
> row/key
> >      reporter.incrCounter(Counters.ROWS, 1);
> >    }
> >
> >    public void configure(JobConf jc) {
> >      // Nothing to do.
> >    }
> >
> >    public void close() throws IOException {
> >      // Nothing to do.
> >    }
> >  }
> >
> >  public JobConf createSubmittableJob(String[] args) throws IOException {
> >    JobConf c = new JobConf(getConf(), getClass());
> >    c.setJobName(NAME);
> >    // Columns are space delimited
> >    StringBuilder sb = new StringBuilder();
> >    final int columnoffset = 2;
> >    for (int i = columnoffset; i < args.length; i++) {
> >      if (i > columnoffset) {
> >        sb.append(" ");
> >      }
> >      sb.append(args[i]);
> >    }
> >    // Second argument is the table name.
> >    TableMapReduceUtil.initTableMapJob(args[1], sb.toString(),
> >      RowCounterMapper.class, ImmutableBytesWritable.class,
> RowResult.class, c);
> >    c.setNumReduceTasks(0);
> >    // First arg is the output directory.
> >    FileOutputFormat.setOutputPath(c, new Path(args[0]));
> >    return c;
> >  }
> >
> >  static int printUsage() {
> >    System.out.println(NAME +
> >      " <outputdir> <tablename> <column1> [<column2>...]");
> >    return -1;
> >  }
> >
> >  public int run(final String[] args) throws Exception {
> >    // Make sure there are at least 3 parameters
> >    if (args.length < 3) {
> >      System.err.println("ERROR: Wrong number of parameters: " +
> args.length);
> >      return printUsage();
> >    }
> >    JobClient.runJob(createSubmittableJob(args));
> >    return 0;
> >  }
> >
> >  public static void main(String[] args) throws Exception {
> >    HBaseConfiguration c = new HBaseConfiguration();
> >    int errCode = ToolRunner.run(c, new RowCounter(), args);
> >    System.exit(errCode);
> >  }
> > }
> >
>

Re: HBase example in Definitive Hadoop Guide - hangs?

Posted by Stack <st...@duboce.net>.
Where did you get the code from?   From
https://github.com/tomwhite/hadoop-book/?  Version 1 or 2 of the book?
 If the code at github hangs, let us know and we'll fix it.

St.Ack

On Thu, Jan 27, 2011 at 9:07 AM, Mark Kerzner <ma...@gmail.com> wrote:
> Example 12-1. A MapReduce application to count the number of rows in an
> HBase table
>
> The code below hangs. Could it be because I am using the 0.89 version of
> HBase when running, but 0.20 for the API (that's what this is example is
> written for?
>
> Thank you,
> Mark
>
> public class RowCounter extends Configured implements Tool {
>  // Name of this 'program'
>  static final String NAME = "rowcounter";
>
>  static class RowCounterMapper
>  implements TableMap<ImmutableBytesWritable, RowResult> {
>    private static enum Counters {ROWS}
>
>    public void map(ImmutableBytesWritable row, RowResult value,
>        OutputCollector<ImmutableBytesWritable, RowResult> output,
>        Reporter reporter)
>    throws IOException {
>      boolean content = false;
>      for (Map.Entry<byte [], Cell> e: value.entrySet()) {
>        Cell cell = e.getValue();
>        if (cell != null && cell.getValue().length > 0) {
>          content = true;
>          break;
>        }
>      }
>      if (!content) {
>        // Don't count rows that are all empty values.
>        return;
>      }
>      // Give out same value every time.  We're only interested in the row/key
>      reporter.incrCounter(Counters.ROWS, 1);
>    }
>
>    public void configure(JobConf jc) {
>      // Nothing to do.
>    }
>
>    public void close() throws IOException {
>      // Nothing to do.
>    }
>  }
>
>  public JobConf createSubmittableJob(String[] args) throws IOException {
>    JobConf c = new JobConf(getConf(), getClass());
>    c.setJobName(NAME);
>    // Columns are space delimited
>    StringBuilder sb = new StringBuilder();
>    final int columnoffset = 2;
>    for (int i = columnoffset; i < args.length; i++) {
>      if (i > columnoffset) {
>        sb.append(" ");
>      }
>      sb.append(args[i]);
>    }
>    // Second argument is the table name.
>    TableMapReduceUtil.initTableMapJob(args[1], sb.toString(),
>      RowCounterMapper.class, ImmutableBytesWritable.class, RowResult.class, c);
>    c.setNumReduceTasks(0);
>    // First arg is the output directory.
>    FileOutputFormat.setOutputPath(c, new Path(args[0]));
>    return c;
>  }
>
>  static int printUsage() {
>    System.out.println(NAME +
>      " <outputdir> <tablename> <column1> [<column2>...]");
>    return -1;
>  }
>
>  public int run(final String[] args) throws Exception {
>    // Make sure there are at least 3 parameters
>    if (args.length < 3) {
>      System.err.println("ERROR: Wrong number of parameters: " + args.length);
>      return printUsage();
>    }
>    JobClient.runJob(createSubmittableJob(args));
>    return 0;
>  }
>
>  public static void main(String[] args) throws Exception {
>    HBaseConfiguration c = new HBaseConfiguration();
>    int errCode = ToolRunner.run(c, new RowCounter(), args);
>    System.exit(errCode);
>  }
> }
>

RE: HPROF Files

Posted by Peter Haidinyak <ph...@local.com>.
Thanks

-----Original Message-----
From: jdcryans@gmail.com [mailto:jdcryans@gmail.com] On Behalf Of Jean-Daniel Cryans
Sent: Thursday, January 27, 2011 9:29 AM
To: user@hbase.apache.org
Subject: Re: HPROF Files

hprof files are heap dumps from java when you get an OutOfMemoryError,
it's generated because HBase ships with
-XX:+HeapDumpOnOutOfMemoryError in conf/hbase-env.sh

J-D

On Thu, Jan 27, 2011 at 9:25 AM, Peter Haidinyak <ph...@local.com> wrote:
> Hi,
>   My cluster went do because some HPROF files appeared in the HBase Home directory. Are these being generated by HBase? If so, how do I turn these off?
>
> Thanks
>
> -Pete
>

Re: HPROF Files

Posted by Jean-Daniel Cryans <jd...@apache.org>.
hprof files are heap dumps from java when you get an OutOfMemoryError,
it's generated because HBase ships with
-XX:+HeapDumpOnOutOfMemoryError in conf/hbase-env.sh

J-D

On Thu, Jan 27, 2011 at 9:25 AM, Peter Haidinyak <ph...@local.com> wrote:
> Hi,
>   My cluster went do because some HPROF files appeared in the HBase Home directory. Are these being generated by HBase? If so, how do I turn these off?
>
> Thanks
>
> -Pete
>

HPROF Files

Posted by Peter Haidinyak <ph...@local.com>.
Hi,
   My cluster went do because some HPROF files appeared in the HBase Home directory. Are these being generated by HBase? If so, how do I turn these off?

Thanks

-Pete