マスター/スレーブ アーキテクチャで、MySQL にフェールオーバー クラスターをセットアップしています。JBoss Datasource も構成しています。接続をテストするためのより良い方法を探しています。これは Alfresco (Ibatis を使用) 用であることを知っています。
私は何度も MySQL を練習しましたが、MySQL Server の内部の実行メカニズムについてはよく知りません。
これまでのところ、このクエリを使用して SQL 接続をテストしています (このスレッドのように: Database Fail Over in Jboss Data sources )
SELECT 1;
ここに完全なデータソースがあります。
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>alfresco-datasource</jndi-name>
<connection-url>
jdbc:mysql://10.1.2.13,10.1.2.14:3306/alfresco
</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>alfresco</user-name>
<password>alfresco</password>
<exception-sorter-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
</exception-sorter-class-name>
<connection-property name="readOnly">false</connection-property>
<failOverReadOnly>false</failOverReadOnly>
<!-- Automatic reconnecion - desactivated to preserve transactions -->
<!-- http://dev.mysql.com/doc/refman/5.0/en/connector-j-reference-configuration-properties.html :
Failover happens when the driver determines that the connection has failed (checked before every query), and falls back to the first host when it determines that the host has become available again (after queriesBeforeRetryMaster queries have been issued). -->
<!--<autoReconnect>true</autoReconnect>-->
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<valid-connection-checker-class-name>
org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker
</valid-connection-checker-class-name>
<!-- If you're using Connector/J 3.1.8 or newer, you can use our implementation
of these to increase the robustness "mysql-ds.xml" 64L, 3683C of the connection
pool. -->
<exception-sorter-class-name>
com.mysql.jdbc.integration.jboss.ExtendedMysqlExceptionSorter
</exception-sorter-class-name>
<valid-connection-checker-class-name>
com.mysql.jdbc.integration.jboss.MysqlValidConnectionChecker
</valid-connection-checker-class-name>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
自分では答えられない質問が複数あります。
- この単純なクエリは Ibatis (または任意の種類または ORM) によってキャッシュされませんか? これは、誤った結果を返す可能性があることを意味します。
- そのクエリは単純すぎませんか? サーバーの状態を表す内部メカニズムを本当に実行しようとしていますか? それとも接続のみをテストしますか?
- それは本当に信頼できるテストですか?
- 他の種類のテストはありますか (たとえば、すでに Connector/J と統合されています)。
- 私にとってパフォーマンスも重要なので、SELECT 1 はヘルスチェックとパフォーマンスの間の適切な妥協点です
ためらわずにいくつかのリンクを指摘してください (Stackoverflow 内かどうかに関係なく)。この質問に既に回答がある場合 (私が検索した限りではそうではないようです)、私は明らかにこのスレッドを削除します。
mysql の開発者または管理者の経験をお返しできれば幸いです。私はそれを行うための最良の方法を探しています。
ご協力いただきありがとうございます。