aws/amazon-neptune-jdbc-driver

[BUG] openCypher queries fail against the read replica

asarkar opened this issue · 3 comments

Describe the bug

If being used outside of a BI Tool, fill in:
1. What version of the JDBC Driver are you using? v2.0.0
2. What language variant are you using (SPARQL, Gremlin, openCypher, SQL)? openCypher
3. What database are you connecting to (Amazon Neptune, Neo4J, etc)? Amazon Neptune
4. What engine version of the database are you using? 1.1.1.0.R6
5. What Java version are you using? N/A
6. Please attach a code snippet of the code that is causing the error: See below
7. If bug occurred during query execution attach the SQL: See below
8. Attach debug logs if applicable/possible (please ensure it doesn't contain any sensitive information): See below

import java.sql.*;
import [java.util.Properties](http://java.util.properties/);
class ExampleRo {
    static final String CONNECTION_STRING = "jdbc:neptune:opencypher://bolt://cluster-ro-endpoint:8182";

    public static void main(String[] args) throws SQLException {
          String query = "match (n) return n limit 1";
        Properties properties = new Properties();
        properties.put("authScheme", "IAMSigV4");
        properties.put("serviceRegion", "us-east-1");
        properties.put("useEncryption", true);
        System.setProperty("aws.accessKeyId","keyId");
        System.setProperty("aws.secretKey","key");
            Connection connection = DriverManager.getConnection(CONNECTION_STRING, properties);
            Statement statement = connection.createStatement();
            ResultSet results = statement.executeQuery(query);
         {
            while ([results.next](http://results.next/)()) {
                String rd = results.getString(1);
                System.out.println(rd);
            }
        }
    }
}

Error: Unexpected server exception 'Opening read/write transactions or executing read/write queries on read replicas is not supported.

Expected behavior

Should be able to execute read queries against the ro endpoint.

Screenshots

N/A.

Environment

N/A.

Since @asarkar is out of office, I (Erin Yoon) the current oncall have discussed this with the team. I think the behavior expected from JDBC driver is that it defaults to READ access mode following the principle of least privilege.

I have made a fix on the Neptune server such that even if client requests READ/WRITE conn, the Neptune read replica enforces to opening READ conn. This would be released in next engine release.
Since there is no code change required from client side, we can close.

After internal discussion, we decided to keep the driver behavior consistent with Bolt driver, which opens a rw connection if not specified. Thus, no change is required in this repo. As per the comment above, a fix has been made on the server so as not to throw an exception immediately. Of course, if the client tries to run a write query against the read endpoint, they'll get an exception.