Thanks a lot, Ryan. In my application, I just need to delete a row after it is returned to my client code via Scanner.next(), so thankfully I don't have to worry about later rows in the scanner's cache.
Also, I noticed that HTable.ClientScanner.iterator returns an Iterator<RowResult> that returns UnsupportedOperationException for the Iterator.remove() method, so I guess this approach is not feasible currently. I'll use HTable.deleteAll(rowResult.getRow()) instead. -jp -----Original Message----- From: Ryan Rawson [mailto:[email protected]] Sent: Thursday, March 25, 2010 12:44 AM To: [email protected] Subject: Re: Is it safe to delete a row inside a scanner loop? You'll see the rows then. If this is a serious requirement, you might have to set scanner caching = 1 or do something else client side in your own app code. -ryan On Thu, Mar 25, 2010 at 12:40 AM, Angus He <[email protected]> wrote: > Hi Ryan, > > What if the rows to be deleted have been already in the client scanner cache? > > > > On Thu, Mar 25, 2010 at 2:07 PM, Ryan Rawson <[email protected]> wrote: >> 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 >> <[email protected]> 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 >>> >>> >> > > > > -- > Regards > Angus >
