Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close DB Sessions in Spring Boot application to avoid reaching limit of max DB sessions #10040

Open
ChaitraSatish opened this issue Nov 22, 2023 · 0 comments

Comments

@ChaitraSatish
Copy link

ChaitraSatish commented Nov 22, 2023

OrientDB Version: 3.1.16

Java Version: 1.8

OS: Linux

Expected behavior

We are currently using OrientDB version 3.1.16 for our Production Project. There are 6-7 Spring Boot applications which involve in various read and write operations on database.
For every API call, check if connections are available from Graph Factory Pool, if present then get the connection else establish a new connection to Database and perform the required operation.

Actual behavior

The session established by an API call is not getting closed or released back to Graph pool factory due to which we are not able to establish new connection after some point of time.

Steps to reproduce

Following is sample code being used:

  1. OrientDB Connection class
    public class OrientDBConnection {
    /**

    • Handles connection to Orient DB,
    • Creates a connection pool to DB if
    • not created already
    • @return poolFactory for DB transactions
      */
      protected OrientGraphFactory getConnectionPool() {
      if(poolFactory == null) {
      poolFactory = createConnPool();
      }
      return poolFactory;
      }

    /**

    • Creates Orient DB connection Pool
    • @return poolFactory
      /
      protected OrientGraphFactory createConnPool() {
      logger.info("Creating DB connection pool");
      String dbUrl= AppConfigProperties.getConfigValue("orientDB.url");
      poolFactory = new OrientGraphFactory(dbUrl).setupPool(1, 500);
      poolFactory.setProperty("password", "
      ***");
      poolFactory.setProperty("username", "**");
      return poolFactory;
      }

    /**

    • Acquires pool from poolFactory and

    • established graph connection

    • @return Graph
      */
      public OrientGraph createGraphConnection() {
      OrientGraph graph = null;
      try {
      if (poolFactory == null) {
      poolFactory = createConnPool();
      }
      graph = poolFactory.getTx();

       logger.info("graph from pool factory is created");
      

      } catch (Exception ex) {
      logger.info("Cannot create Graph from pool factory with exception {}", ex);
      }

      return graph;
      }
      }

  2. Service Layer
    public class SampleServiceLayer
    {
    /* Establish DB connection */
    OrientGraph checkConnection() {
    OrientGraph graph = dbConnection.createGraphConnection();
    return graph;
    }
    // sample function
    public List getSampleList() {
    List result = new ArrayList();

    OrientGraph graph = checkConnection();
    try {
    	// call Impl layer here
    } finally {
    	graph.shutdown();
    }
    
    return result;
    

    }

}

Since we are already in Production mode, this issue has become extremely critical to us.
Request you to provide feedback at earliest.

Also, with reference to the above code - is it the correct way to connect to Orient Database? Any reference on how to connect to database from Java application would be really helpful.

@ChaitraSatish ChaitraSatish changed the title Close DB Sessions from Spring Boot application to avoid reaching limit of max DB sessions Close DB Sessions in Spring Boot application to avoid reaching limit of max DB sessions Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant