True. Iterators are used widely in Java and contracts are often very different depending on where you got it from.
For HBase, I don't think it's that big of a deal, though we could throw a note into javadoc. Usually in databases, you don't expect returned data to be mutable. I don't iterate rows from a SQL cursor, mutate returned data, and expect that to be reflected in the database w/o issuing an additional remote request (or sql query in this case). That kind of stuff is the job of ORMs and the like. JG > -----Original Message----- > From: Jeyendran Balakrishnan [mailto:jbalakrish...@docomolabs-usa.com] > Sent: Thursday, March 25, 2010 10:01 AM > To: hbase-user@hadoop.apache.org > Subject: RE: Is it safe to delete a row inside a scanner loop? > > I agree.. :-) > > Wish Java had something like a ReadOnlyIterator or ImmutableIterator, > so users could immediately understand that one can't use the iterator > to modify the iterable. > > -jp > > > -----Original Message----- > From: Jonathan Gray [mailto:jg...@facebook.com] > Sent: Thursday, March 25, 2010 9:45 AM > To: hbase-user@hadoop.apache.org > Subject: RE: Is it safe to delete a row inside a scanner loop? > > Good thing it throws that exception. It definitely would not perform > any server-side actions as Ryan said. > > > -----Original Message----- > > From: Jeyendran Balakrishnan [mailto:jbalakrish...@docomolabs- > usa.com] > > Sent: Thursday, March 25, 2010 9:34 AM > > To: hbase-user@hadoop.apache.org > > Subject: RE: Is it safe to delete a row inside a scanner loop? > > > > 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:ryano...@gmail.com] > > Sent: Thursday, March 25, 2010 12:44 AM > > To: hbase-user@hadoop.apache.org > > 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 <angu...@gmail.com> 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 <ryano...@gmail.com> > > 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 > > >> <jbalakrish...@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 > > >>> > > >>> > > >> > > > > > > > > > > > > -- > > > Regards > > > Angus > > >