Uploaded image for project: 'Derby'
  1. Derby
  2. DERBY-6055

Drained metadata result sets can cause build up of open statements open on client/server until gc kicks in

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 10.8.3.0
    • None
    • Network Client
    • Normal
    • Repro attached, Workaround attached

    Description

      With client/server, depending on when garbage collection kicks in metadata related statements can build up until garbage collection. This is only potentially an issue I think with client where there is a limit of 32K statements and only if there is some sort of extremely deferred garbage collection.

      The program below shows the issue which is easy enough to work around by closing the statement associated with the metadata result set, uncommenting the line.

      //rs.getStatement().close();

      import java.sql.*;
      import java.net.*;
      import java.io.*;
      import org.apache.derby.drda.NetworkServerControl;

      /**

      • Show client/server Metadata statements can build up even when
      • Metadata result sets have been closed.
        */
        public class MetaDataStatements {

      public static void main(String[] args) throws Exception {
      try {
      // Load the driver. Not needed for network server.

      Class.forName("org.apache.derby.jdbc.ClientDriver");
      // Start Network Server
      startNetworkServer();
      // If connecting to a customer database. Change the URL
      Connection conn = DriverManager
      .getConnection("jdbc:derby://localhost:1527/wombat;create=true");
      // clean up from a previous run
      Statement s = conn.createStatement();
      try

      { s.executeUpdate("DROP TABLE T"); }

      catch (SQLException se)

      { if (!se.getSQLState().equals("42Y55")) throw se; }

      for (int i = 0; i < 50000; i++) {
      ResultSet rs = conn.getMetaData().getSchemas();
      while (rs.next())

      { //System.out.println("SCHEM NAME = " + rs.getString(1)); }

      //rs.getStatement().close();
      }

      // rs.close();
      // ps.close();
      // s.close();
      runtimeInfo();
      conn.close();
      // Shutdown the server
      shutdownServer();
      } catch (SQLException se) {
      while (se != null)

      { System.out.println("SQLState=" + se.getSQLState() + se.getMessage()); se.printStackTrace(); se = se.getNextException(); }

      }
      }

      /**

      • starts the Network server
      • */
        public static void startNetworkServer() throws SQLException {
        Exception failException = null;
        try {

      NetworkServerControl networkServer = new NetworkServerControl(
      InetAddress.getByName("localhost"), 1527);

      networkServer.start(new PrintWriter(System.out));

      // Wait for the network server to start
      boolean started = false;
      int retries = 10; // Max retries = max seconds to wait

      while (!started && retries > 0) {
      try

      { // Sleep 1 second and then ping the network server Thread.sleep(1000); networkServer.ping(); // If ping does not throw an exception the server has // started started = true; }

      catch (Exception e)

      { retries--; failException = e; }

      }

      // Check if we got a reply on ping
      if (!started)

      { throw failException; }

      } catch (Exception e)

      { SQLException se = new SQLException("Error starting network server"); se.initCause(failException); throw se; }

      }

      public static void shutdownServer() throws Exception

      { NetworkServerControl networkServer = new NetworkServerControl( InetAddress.getByName("localhost"), 1527); networkServer.shutdown(); }

      public static void runtimeInfo() throws Exception

      { NetworkServerControl networkServer = new NetworkServerControl( InetAddress.getByName("localhost"), 1527); System.out.println(networkServer.getRuntimeInfo()); }

      }

      ---------- Session Information ---------------
      Session # :2
      Database :wombat;create=true
      User :APP

      1. Statements:59
        Prepared Statement Information:
        Stmt ID SQLText
                              • -----------
                                SYSLH00032 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00033 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00060 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00058 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00059 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00056 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00057 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00054 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')
                                SYSLH00055 CALL SYSIBM.SQLTABLES('', '', '', '', 'GETSCHEMAS=1')

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              kmarsden Katherine Marsden
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated: