hbase-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ryan Rawson <ryano...@gmail.com>
Subject Re: Is it safe to delete a row inside a scanner loop?
Date Thu, 25 Mar 2010 06:07:27 GMT
Hey,

I'm pretty sure that Iterator.remove() will be local only and not
actually affect HBase.

But yes it is safe.  If you delete a row you just scanned, since the
scanner will be past the row in question, thus it is safe to delete
it.  And even if you deleted a row you were just about to see, you'd
just end up skipping that row.

-ryan

On Wed, Mar 24, 2010 at 10:12 AM, Jeyendran Balakrishnan
<jbalakrishnan@docomolabs-usa.com> wrote:
> Hi,
>
> I am running a scanner on a HBase table.
> After getting each row, and using the data, I want to delete the row.
> Is it safe to do so from inside the scanner loop?
>
> And if so, what is the best way to delete the row?:
> * Using HTable.deleteAll()
> or
> * Using Iterator.remove()
>
> My use case is something like this [I am using HBase 19.3, please don't
> kill me :-)]:
>
> HTable table = ...;
> Scanner scanner = table.getScanner(...);
>
> try
> {
>        Iterable<RowResult> I = scanner.iterator();
>        while (I.hasNext())
>        {
>                RowResult result = I.next();
>
>                //      Do something with result:
>                // ....
>
>                //      Now delete the row
>
>                //      HTable approach
>                byte[] rowKeyBytes = result.getRow();
>                table.deleteAll(rowKeyBytes);
>
>                //      OR Iterator.remove() approach:
>                //I.remove();
>        }
> }
> finally
> {
>        if (scanner != null)
>                scanner.close();
> }
>
> Thanks a lot,
> jp
>
>

Mime
View raw message