alexbrainman / odbc

odbc driver written in go
BSD 3-Clause "New" or "Revised" License
352 stars 140 forks source link

Does not close cursor after query when interacting with Apache Ignite #121

Closed nombiezinja closed 6 years ago

nombiezinja commented 6 years ago

First of all thank you for writing the package, fantastic work!

I've been trying to interact with a local Apache Ignite cluster. I have been able to hit the database and perform different operations with success. However, consecutive queries result in the error Too many open cursors. The code works fine with another driver, I have made sure to rows.Close() after dealing with the query results.

I have looked at your source code and saw that Close() calls SQLCloseCursor, which is supported by the Apache Ignite ODBC interface: https://apacheignite-sql.readme.io/docs/specification. Unfortunately due to my limited knowledge of C, java, and general database layer things, my investigation ends there.

Here is the code that, when run 128 times (the maximum amount of cursors I have set in my Ignite configuration) causes the too many open cursors error because each time it is run, it opens a cursor and never closes it

func foo(value string) {
    statement := fmt.Sprintf(`SELECT A, B, C
    FROM TABLE WHERE C IS NOT NULL
        ORDER BY C %s LIMIT 1`, value)

        // Bar is a struct
    var b Bar 

    rows, err := DB.Query(statement)

    if err != nil {
        log.Fatal(err)
    }

    for rows.Next() {
        err := rows.Scan(&b.A, &b.B, &b.C)
        if err != nil {
            log.Fatal(err)
        }
        log.Println("Retrieved result:", b)
    }
    rows.Close()
}

Do you have any insight into this? Is the code somehow problematic, or is it a ODBC level issue? Thanks again for any suggestion you are able to offer

alexbrainman commented 6 years ago

Please, show complete code - something I can compile myself and run here. You might left out important bits that make your code fail. Also, please, show complete output of your program - error messages are important - do not ignore output bits - they might be important.

Also you should be calling rows.Err() after rows.Next() returns false, to see if the loop finished because of end of rows or because of some error. If there is an error there, it might be relevant to your problem.

Alex

nombiezinja commented 6 years ago

Thank you for the quick reply. I have made a repo that reproduces the issue, the terminal output after compiling and running is in the README.md

https://github.com/nombiezinja/ignite-cursor-example

Thank you Ti

alexbrainman commented 6 years ago

https://github.com/nombiezinja/ignite-cursor-example

Thank you for providing sample program. Unfortunately I do not see anything that you are doing wrong. Perhaps you connection is not right, or your database is not configured properly. But I know nothing about Apache Ignite.

In your original message, you said:

The code works fine with another driver,

What driver is that? Why cannot you use it for your exercise?

Alex

nombiezinja commented 6 years ago

Thank you for looking over the sample program, at least that helps me rule out any code issues. Perhaps it is my Ignite configuration and I shall look into it further.

The code works fine if I connect to a postgres database with lib/pq, but I'm looking to use distributed in-memory data storage.

Thank you very much for your help.

alexbrainman commented 6 years ago

Thank you very much for your help.

Sorry I could not help. Feel free to ask here, if you think I can help.

Alex

nombiezinja commented 6 years ago

For anyone who potentially finds their way here with the same problem before Ignite comes up with a fix

I have made a post to the Apache Ignite mailing list after our team replicated the error with the mgodbc package, on both linux and windows, and then with c#. It has been deemed a bug by the Ignite team and is now an open issue: https://issues.apache.org/jira/browse/IGNITE-8930

Thank you Alex.

alexbrainman commented 6 years ago

SGTM. I am glad you found your problem.

I don't think there is anything else to do here, so closing this issue. Please, reopen if you think differently.

Alex