orientechnologies / spring-data-orientdb

OrientDB implementation for SpringData

Home Page:http://forum.springsource.org/showthread.php?99627-OrientDB-support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Errors for version 3.1.0 for idle connections in a pool managed by spring-data-orientdb

adepase opened this issue · comments

Dear all,
I recently switched to Orientdb version 3.1.0 and adapted the spring-data-orientdb code.
Now I receive errors I didn't received when using version 2.X. I'm pretty sure that they are due to idle connections, (it happens only if I don't use the connections for several minutes), but the connections are opened and managed by the pool by this module, not directly by me.

At least, I cannot found an example or documentation to understand how to make the pool check the connections and reload them, if needed.

My code is here below (yes, deprecated graph API: if it is an issue of this API, maybe corrected in the new Multi-Model API, please, let me know and I'll anticipate the currently planned dates):

public ODocument execCommand(String query,Map<String,Object> params, int retryTimes){
  ODocument result=null;
  OrientGraph graph = orientFactory.getTx(); // I expect here to receive the connection from the pool
  graph.makeActive(); // To bind the connection to the current thread, as specified in the docs
  try{
	  result= graph.command(new OCommandSQL(query)).execute(params);
	  graph.commit();
  } catch (OCommandExecutionException e) {
      graph.rollback();
      logger.debug("Rollback because of OrientDB Exception: "+e.getMessage());
  } catch( ONeedRetryException e ) {
         if (retryTimes > 0){
    	   retryTimes--;
    	   execCommand(query, params, retryTimes);
         }
  } finally {
	 graph.shutdown(); // To push connection back to the pool
  }
     return result;
}

And orientFactory was created by this code:


        @Value( "${spring.data.orient.url}" )
	private String orientUrl;
	@Value( "${spring.data.orient.username}" )
	private String orientUsername;
	@Value( "${spring.data.orient.password}" )
	private String orientPassword;
	
	@Value( "${spring.data.orient.minPool}")
	private int orientMinPool;
	@Value( "${spring.data.orient.maxPool}")
	private int orientMaxPool;
	
	@Bean
	public OrientGraphFactory orientFactory(){

		logger.debug("Initializing OrientDB Pool");
		OrientGraphFactory factory = new OrientGraphFactory(orientUrl,orientUsername, orientPassword).setupPool(orientMinPool,orientMaxPool);
		
		logger.debug("OrientDB Pool initialized");
		return factory;  
	}

I receive a Error: java.io.EOFException when executing the line:
result= graph.command(new OCommandSQL(query)).execute(params);
and I have to restart my app.
I think there should be a way to manage idle times and connection checking on the pool, but I don't know how to set them.
If this is due to idle connection closed, but this is just an hypothesis, at this time
Can you please help me?
Thank you in advance