Alice Chen created TRAFODION-980:
------------------------------------

             Summary: LP Bug: 1418215 - JDBC stmt.cancel does not work and a 
error msg logged in dcs master log
                 Key: TRAFODION-980
                 URL: https://issues.apache.org/jira/browse/TRAFODION-980
             Project: Apache Trafodion
          Issue Type: Bug
          Components: client-jdbc-t4
            Reporter: Aruna Sadashiva
            Assignee: Zbigniew Omanski
            Priority: Critical
             Fix For: 1.1 (pre-incubation)


JDBC stmt.cancel is not behaving as expected. I first noticed this in 
DBVisualizer. Cancel used to work from DBViz, but it does not work anymore, so 
tried it from a java test program. 

When stmt.cancel is issued, the cancel thread gets this exception:

Got SQLException in queryThread.....
org.trafodion.jdbc.t4.HPT4Exception: The message id: problem_with_server_read
        at 
org.trafodion.jdbc.t4.HPT4Messages.createSQLException(HPT4Messages.java:304)
        at org.trafodion.jdbc.t4.InputOutput.doIO(InputOutput.java:371)
        at org.trafodion.jdbc.t4.T4_Dcs_Cancel.cancel(T4_Dcs_Cancel.java:83)
        at 
org.trafodion.jdbc.t4.InterfaceConnection.cancel(InterfaceConnection.java:478)
        at 
org.trafodion.jdbc.t4.InterfaceStatement.cancel(InterfaceStatement.java:1044)
        at 
org.trafodion.jdbc.t4.TrafT4Statement.cancel(TrafT4Statement.java:104)
        at qc1$cancelThread.run(qc1.java:139)
  SQLMessage The message id: problem_with_server_read
  SQLState   HY000
  Error Code -1

After this the test does not exit and I can see the query stats using GET 
STATISTICS FOR QID <qid> command. The query seems to continue executing in sql. 
The query thread gets this exception after the query completes:

Got SQLException in queryThread.....
org.trafodion.jdbc.t4.HPT4Exception: The message id: invalid_cursor_state
        at 
org.trafodion.jdbc.t4.HPT4Messages.createSQLException(HPT4Messages.java:304)
        at 
org.trafodion.jdbc.t4.TrafT4ResultSet.getType(TrafT4ResultSet.java:2368)
        at 
org.trafodion.jdbc.t4.TrafT4ResultSet.setFetchOutputs(TrafT4ResultSet.java:4596)
        at 
org.trafodion.jdbc.t4.InterfaceResultSet.setExecute2FetchOutputs(InterfaceResultSet.java:729)
        at 
org.trafodion.jdbc.t4.InterfaceResultSet.fetch(InterfaceResultSet.java:796)
        at org.trafodion.jdbc.t4.TrafT4ResultSet.next(TrafT4ResultSet.java:2869)
        at qc1$queryThread.run(qc1.java:76)
  SQLMessage The message id: invalid_cursor_state
  SQLState   HY000
  Error Code -1

And this message is logged in the dcs master log:

2015-02-04 20:32:38,737 ERROR 
org.trafodion.dcs.master.listener.ListenerService: IOException: 
/16.235.158.28:36460: Wrong signature in read Header : 959447040

Below is the cancel test code:

import java.sql.*;
import java.math.*;
import java.util.*;
import java.io.*;

public class qc1 
{

    public static boolean is25 = false;

    public static void main(String[] args) 
    {
        Connection conn = null;
        CallableStatement cs = null;
        Properties props = null;
        String cat = null;
        String sch = null;
        String IN1 = null;
        String IN2 = null;
        String defsch = null;
        String url = null;
        Statement stmt = null;
        String ISTBL = "SITBL";
        String colName = null;

        try 
         {
                //Class.forName("org.trafodion.jdbc.t2.T2Driver");
                //conn = DriverManager.getConnection("jdbc:t2jdbc:", "usr", 
"pwd");
                conn = Utils.getUserConnection();

                System.out.println("Connection established....");
                //String query1 = "select count(*) from g_arkcasedb.branch a, 
g_arkcasedb.customer b, g_arkcasedb.employee c, g_arkcasedb.orders d, 
g_arkcasedb.parts e, g_arkcasedb.region f, g_arkcasedb.supplier g, 
g_arkcasedb.odetail h, g_arkcasedb.fromsup i";
                String query1 = "select count(*) from g_arkcasedb.branch a, 
g_arkcasedb.customer b, g_arkcasedb.employee c, g_arkcasedb.orders d, 
g_arkcasedb.parts e, g_arkcasedb.region f, g_arkcasedb.supplier g, 
g_arkcasedb.odetail h";

                PreparedStatement pStmt = conn.prepareStatement(query1);

                System.out.println("Calling queryThread.....");
                queryThread qt = new queryThread(pStmt);
                qt.start();
                Thread.currentThread().sleep(5000);
                System.out.println("Calling cancelThread.....");
                cancelThread ct = new cancelThread(pStmt);
                ct.start();

                System.out.println("Check if the query is canceled....");
                //Thread.currentThread().sleep(10000);
                System.out.println("Now exiting the application.....");
                pStmt.close();
                conn.close();
                return;
        }// end of try
        catch (Exception e) {
                e.printStackTrace();
                System.out.println(e.getMessage());
        }
    }

    static class queryThread extends Thread 
    {
        private PreparedStatement ps;
        private boolean pass = false;

        public queryThread(PreparedStatement pstmt) 
        {
            ps = pstmt;
        }

        public void run() 
        {

            try {
                ResultSet rs = ps.executeQuery();
                ResultSetMetaData rsMD = rs.getMetaData();
                int total = 0;
                while (rs.next()) 
              {
                        total++;
                     String data;
                        for (int j = 1; j <= rsMD.getColumnCount(); j++)
                     {
                                data = rsMD.getColumnName(j) + rs.getObject(j);
                     }
                }
                rs.close();
                System.out.println("Query thread : total of " + total   + " 
rows selected");
            }// end of try
            catch (SQLException se) {
                System.out.println("Got SQLException in queryThread.....");
                se.printStackTrace();
                System.out.println("  SQLMessage " + se.getMessage());
                System.out.println("  SQLState   " + se.getSQLState());
                System.out.println("  Error Code " + se.getErrorCode());
            } catch (Exception e) {
                System.out.println("Got Exception in queryThread.....");
                e.printStackTrace();
                System.out.println(e.getMessage());
            }
        }

    } // end queryThread

    static class cancelThread extends Thread 
    {
        private PreparedStatement ps;

        public cancelThread(PreparedStatement pstmt) 
        {
            ps = pstmt;
        }

        public void run() 
        {
            // adjust waitTime for the cancel to happen while the query is in
            // progress
            int waitTime = 3;
            int waitTimeMill = waitTime * 1000;
            java.util.Date startDate = new java.util.Date();
            long startDateMilliseconds = startDate.getTime();
            long endDateMilliseconds = startDateMilliseconds + waitTimeMill;
            long nowTimeMills = 0;
            long dot;

            try
            {
                // Wait "waitTime" seconds to make sure query is running.
                System.out.print("  In cancelThread: About to Cancel");

                nowTimeMills = new java.util.Date().getTime();
                dot = nowTimeMills + 1000;
                while (nowTimeMills < endDateMilliseconds) {
                        nowTimeMills = new java.util.Date().getTime();
                        if (nowTimeMills > dot) {
                                System.out.print(".");
                                dot = nowTimeMills + 1000;
                        }
                }

                ps.cancel();
                System.out.println("Statement canceled .....");
            }// end of try
            catch (SQLException se) {
                System.out.println("Got SQLException in queryThread.....");
                se.printStackTrace();
                System.out.println("  SQLMessage " + se.getMessage());
                System.out.println("  SQLState   " + se.getSQLState());
                System.out.println("  Error Code " + se.getErrorCode());
            } catch (Exception e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            } catch (Throwable e) {
                System.out.println(e.getMessage());
                e.printStackTrace();
            }
        }

    } // end cancelThread

} // end qc1



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to