Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 1.01 KB

switching-between-main-and-replica.md

File metadata and controls

21 lines (16 loc) · 1.01 KB

How DualConnection chooses between main and replica?

DualConnection takes multiple aspects while deciding which connection to use:

  1. A connection's state.
  2. A replica's consistency.
  3. Context of java.sql.Connection/java.sql.Statement API usage.

Some of the methods are intended to write into the database. For example every call to java.sq.PreparedStatement#executeUpdate will switch the connection's state to the main database.

  1. Availability of replica

  2. The query will use the main database in case it's:

    • SELECT FOR UPDATE statement.
    • UPDATE statement.
    • DELETE statement.
    • All calls with transaction isolation level higher than TRANSACTION_READ_COMMITTED.
  3. The query will use the main database in case it's an unknown function call. Known read-only functions are standard SQL functions and user defined functions.