Retrying after a SQLException gives false results.

23 views
Skip to first unread message

andrewjam...@gmail.com

unread,
May 5, 2015, 2:30:45 AM5/5/15
to activate-p...@googlegroups.com

Sorry I posted this in github issues, but it seems like no one is maintaining it.

Hi,

What I did is, 
1. boot up my application. 
2.Then turn off my mysql.
3. Send a request to my webservice that would trigger a transaction. (Simple byId)

I am using:

 val storage = new PooledJdbcRelationalStorage {
 val jdbcDriver = "com.mysql.jdbc.Driver"
}

This is my code for catching the exception and retrying.

class EntityManager(implicit val ctx: ActivateContext) extends Actor {

def receive ={
   case message =>  doAction(Find[SampleEntity]("ID1"),0 ,sender)
}

def doAction(a:Action,count:Int, sender:ActorRef):Unit ={
     a.eval onComplete{
       case Success(message) => 
         log.debug("SUCCESS " +message)
         message match{

            case Some(data) => sender ! data
            case None =>  sender ! Fail

        }
       case Failure(exception) => 
         exception match{

           case e:JdbcStatementException =>
                 log.debug("FAIL" + e)
                 if(count >= 2){ sender ! Fail
               }else{  doAction(a,count + 1,sender) }

           case e:java.sql.SQLException => 
               log.debug("FAIL " + e)
               if(count >= 2){ sender ! Fail
               }else{  doAction(a,count + 1,sender) }

         }
}

case class Find[E <: BaseEntity: Manifest](id: E#ID) extends Action {
    def eval(implicit ctx: ActivateContext, exec: ExecutionContext): Future[Option[EntityMap[E]]] = {
      import ctx._
      asyncTransactional {
        val entity = transactional { byId[E](id)}
        val map = transactional { entity.map(_.toMap) }
        map
      }
    }
  }

}

Here is the results (this is from my actual app name of package is changed)

2015-04-29 14:57:07,962 [DEBUG] c.o.m.managers.EntityManager ForkJoinPool-2-worker-5 -  FAIL java.sql.SQLTimeoutException: Timeout after 29999ms of waiting for a connection.

2015-04-29 14:57:07,985 [DEBUG] c.o.m.managers.EntityManager ForkJoinPool-2-worker-5 -  SUCCESS SampleEntity("ID1",null)

As you could see in the logs , after failing it tried that same transaction again. It succeded (MYSQL DB/SERVICE is down). The resulting entity that the retry find got is:

SampleEntity("ID1",null)

This id/entity entry doesn't even exist in my db.

This is the model of the Entity

SampleEntity(name:String) extends Entity

EDIT:

Temporary solution

reinitializeContext

But I am worried for multiple concurrent request that would try to reinitializeContext. I remember experiencing a exception when doing reinitializeContext alot of times.

Anyone know disadvantages of concurrent reinitializeContext



Related github issue:

https://github.com/fwbrasil/activate/issues/177

Flavio W. Brasil

unread,
May 5, 2015, 3:33:51 AM5/5/15
to andrewjam...@gmail.com, activate-p...@googlegroups.com
Hi,

Your transaction composition is wrong. Never mix `transactional` with `asyncTransactional`. More information here:


Regards,

-- 
Flavio W. Brasil

--
You received this message because you are subscribed to the Google Groups "Activate Persistence Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to activate-persist...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

andrewjam...@gmail.com

unread,
May 5, 2015, 8:22:00 AM5/5/15
to activate-p...@googlegroups.com, andrewjam...@gmail.com
I get it , but even if I use a driver which supports async, it still does this false result.

The one that is being committed in the liveCache is the failed result.
To unsubscribe from this group and stop receiving emails from it, send an email to activate-persistence+unsub...@googlegroups.com.

Flavio W. Brasil

unread,
May 5, 2015, 8:23:20 AM5/5/15
to andrewjam...@gmail.com, activate-p...@googlegroups.com
Could you provide a project that has the correct transaction composition and reproduces the issue?

-- 
Flavio W. Brasil

To unsubscribe from this group and stop receiving emails from it, send an email to activate-persist...@googlegroups.com.

andrewjam...@gmail.com

unread,
May 5, 2015, 8:30:01 AM5/5/15
to activate-p...@googlegroups.com, andrewjam...@gmail.com
Will do, but It might take awhile . Maybe tomorrow 

Thanks for the fast reply.
Reply all
Reply to author
Forward
0 new messages