[storm] how to refresh store.find( )

Jamu Kakar jkakar at kakar.ca
Sat Jul 17 17:44:05 BST 2010


Hi,

On Sat, Jul 17, 2010 at 6:33 PM, Eduardo Willians <edujurista at gmail.com> wrote:
> Well, this may look stupid, but here is.
>
> I do:
>
> number = store.find(Broker).max(Broker.number)
>
> I get the number. But if another db connection adds a new row to DB,
> and the code is run again:
>
> number = store.find(Broker).max(Broker.number)
>
> I get the SAME number instead of the new one was just added, because
> storm's cache was not updated (I think).

Yes, this is expected because storm uses serializable transactions
(which means each transaction has a view of the database that is
based on a snapshot made when the transaction started).

> There at least two solutions:
>
> First:
> store.commit()
> number = store.find(Op).max(Op.number)
> This is very dangerous because if there's any pending transaction it
> will be committed to DB, so I can't use this.
>
> Second:
> store.rollback()
> number = store.find(Op).max(Op.number)
> This one is also dangerous, because if there's any pending transcation
> waiting to be commited it will go away.
>
> invalidate() and flush() does not work. And I think reset() is not recommended.
>
> So, is there any other way to refresh store.find( )?

There are two ways:

1. The way you described, use store.rollback.  If there are other
   changes that you don't want to rollback then you may need to
   rethink how your separating work among transactions.

2. Change the transaction isolation type to read committed, so that
   the underlying data retrieved from the database is always the
   most current.  You need to be careful when you do this because it
   breaks assumptions Storm makes with regard to what is safe to
   cache.  You can specify the transaction isolation mode in the URI:

   postgres://localhost/database?isolation=read-committed

Hope this helps!

Thanks,
J.



More information about the storm mailing list