- 浏览: 3470581 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
wanglf1207:
EJB的确是个不错的产品,只是因为用起来有点门槛,招来太多人吐 ...
weblogic-ejb-jar.xml的元素解析 -
qwfys200:
总结的不错。
Spring Web Flow 2.0 入门 -
u011577913:
u011577913 写道也能给我发一份翻译文档? 邮件437 ...
Hazelcast 参考文档-4 -
u011577913:
也能给我发一份翻译文档?
Hazelcast 参考文档-4 -
songzj001:
DbUnit入门实战
Some time ago I worked on a project which was in need of a way to cluster databases. For those of you who don’t exactly know what database clustering is: database clustering is a way to have multiple databases work together to act like a single database. A cluster of databases typically has the following benefits:
- A cluster has a query throughput that is much higher than just a single database.
- A database in the cluster can fail without losing access to the data.
The result is that you now have access to a ‘database’ that is never down and can handle a lot more queries than a single database could. We didn’t care much about the higher query throughput but were very interested in a database that would always be available.
After some research I found out that there were a lot of products available to accomplish this.
We decided to use HA-JDBC (= High Availability Java DataBase Connectivity), an open source Java framework that offers database clustering. In this blog entry, I will tell you about my experiences with this relatively unknown framework, and hopefully share experiences with people who also use it. But first, I will try to explain how this framework does its job.
HOW HA-JDBC WORKS
Normally when you connect to a database, you use a JDBC connection. HA-JDBC wraps one or more connections and acts like a proxy in your javacode. This means that your javacode interacts with the proxy and is transparently communicating with multiple databases.
In order for HA-JDBC to know which connections to proxy, it needs an XML configuration file. This file defines how the cluster is configured. It defines the information needed to connect to the databases, but also the behaviour of the cluster itself. Below you can read about the experiences I’ve had with a few different aspects of HA-JDBC.
SYNCHRONIZATION
One aspect of HA-JDBC is synchronization. Synchronization in HA-JDBC is the process of making an out-of-date database up-to-date again by comparing its data with other databases in the cluster. A database can get out-of-date when it gets turned off for some reason. It could have died on its own or someone could have turned it off on purpose, but in any case: it needs synchronization to have its data up-to-date again. When a database goes down, users of the application will not notice. They can continue using the application like nothing is going on because other databases of the cluster are still available.
When a database is down, it will rapidly get out-of-date because it will not process any updates anymore. When the database is started again, HA-JDBC will pick this up and executes a synchronization strategy that is configured in the XML configuration file. The downside to this is that the built-in strategies of HA-JDBC are not very efficient. These are the ones packaged with HA-JDBC:
- <!-- [if !supportLists]--><!-- [endif]-->FullSynchronizationStrategy : Deletes the content of all tables of the database that is being updated and fills them again with data from a different (up-to-date) database in the cluster.
- <!-- [if !supportLists]-->DifferentialSynchronizationStrategy: Compares all rows of the out-of-date database with a different (up-to-date) database in the cluster to find out which rows need to be updated, inserted or deleted.
- <!-- [if !supportLists]-->PassiveSynchronizationStrategy : There also is a strategy that assumes no updates have taken place during the down-time and is therefore doing nothing.
A nice thing about HA-JDBC is that you can implement your own synchronization strategy. Since the above mentioned strategies will take hours to complete on large tables we decided to write a strategy ourselves. This strategy requires tables to have a timestamp for versioning, does not support deletes but turned out to be a lot faster than the built-in strategies of HA-JDBC.
ID GENERATION
When using a single database you can let the database itself generate IDs for records you insert. When using multiple databases with HA-JDBC you can still do that, but there is no guarantee that all databases in the cluster will generate the same ID. When a different ID is generated in each database, this will leave your cluster in an invalid state because now all the databases in this cluster contain different data.
Of course there is a solution to this problem but this isn’t pretty. When using an ORM tool like Hibernate , you can specify a generator for the ID field. By default Hibernate makes the database responsible for generating IDs which is not what we want. When using HA-JDBC you should use one of the following generators:
- UUID-generator
- HiLo-generator.
These two generators both don’t depend on an individual database, which is just what we need, but they do not produce normal IDs. For example the UUID generator generates IDs like ‘4028828d-0dc7f2a2-010d-c7f2a4d3-0013’. This value is based on the current timestamp and the IP address of the machine the application is on. The HiLo generator generates normal numbers but they don’t increase like you’re used to. It is possible that the first number it generates is 432 and the next one is 33200, which you wouldn’t expect from IDs.
NON-INTRUSIVE?
When I started using
HA-JDBC, I expected it to be non-intrusive to our project. Because the
only thing we needed was to change our JDBC driver and write a simple
XML configuration file for it. But as you have read in this blog entry,
you first of all need to write your own strategy for synchronization,
and second of all, you probably have to switch to UUIDs. This requires
a lot of refactoring all over your code because you are now switching
from Long typed IDs to String typed IDs. So in fact it does influence
your project more than you would expect.
CONCLUSION
In conclusion, HA-JDBC is very easy to set up and has well written documentation on its website. It performs quite well, especially when writing a customized strategy for synchronization. Since it delegates calls to underlying JDBC drivers directly, it is fast and has full JDBC support. You also don’t need anything else then just your database servers and your application servers. But there are a few issues with HA-JDBC that are a bit annoying, you will probably end up with having UUIDs for records in your database and having to write your own synchronization strategy.
I was wondering if there were any other people that have some experience with this database clustering approach and would like to share their experiences. So if you have any experience with HA-JDBC, don’t hesitate to leave a comment!
发表评论
-
oracle复制表数据,复制表结构
2011-07-25 21:19 361331.不同用户之间的表数据复制 对于在一个数据库上的两个 ... -
删除 SQL Server 的所有已知实例
2011-04-05 18:42 1997如果提示实例已经被注册,无法安装,那么: 删除 SQL ... -
【SQL】安装 SQL SERVER MsiGetProductInfo 无法检索 Product Code 1605错误 解决方案
2011-04-05 17:10 4802重装数据库服务器上的SQL SERVER 2008 上遇到了以 ... -
Mysql Using Master/Slave Replication with ReplicationConnection
2011-03-24 15:19 1945Starting with Connector/J 3.1.7 ... -
oracle网络配置listener.ora、sqlnet.ora、tnsnames.ora
2010-12-03 12:36 33293oracle网络配置 三个配置文件 listener.ora ... -
Oracle XE的数据库创建过程
2010-12-02 22:55 4286今天安装了Oracle XE,发现并没有自动创建数据库。趁着 ... -
实现数据库TPC性能测试的开源及商业软件
2010-12-02 01:11 3092商业软件 Benchmark Factory ... -
MySQL压力测试工具mysqlslap
2010-11-07 17:13 1735MySQL从5.1.4版开始带有一个压力测试工具mys ... -
一台机器上安装多个mysqld实例
2010-11-06 16:09 2124一台机器安装多个mysqld实例 1. ps -aux | ... -
MySQL数据库双向同步
2010-08-25 20:23 40281. 主从关系的同步 master端 192.168.5 ... -
MySQL 数据库之间的同步(windows与linux)
2010-08-25 20:14 31561.导出windows mysql的test库到linux m ... -
Ubuntu Server 下开启远程连接 MySQL
2010-03-16 23:24 3073要通过远程连接MySQL,需要做两步:第一步是要创建一个可以远 ... -
DB2 在REDHAT 5下的详细安装过程 DB2 9.5 C EXPRESS
2010-03-02 10:43 4533过详细测试并且补充后发表, 括号内的为自行添加的内容. ... -
IBM DB2 Express-C 9.5.2
2010-03-02 09:44 3468或许您已经知 ... -
Oracle Database 10g Express Edition安装小结
2010-03-01 15:28 9130racle Database 10g Express Edit ... -
数据归档将走向何方
2010-02-25 11:50 2239数据量的爆炸性增长,让我们不得不更加关心存储。这也造成 ... -
Database
2010-02-18 15:53 2281下一代数据库发展的4大趋势 趋势之一:对XML的支 ... -
免安装Oracle运行pl/sql developer
2010-02-16 20:27 2158Sql客户端中,虽然最便捷的是万能而且轻量无比的Sql Wor ... -
在debian上安装oracle 10g express
2010-02-16 18:46 4881在debian上安装oracle 10g express 若 ... -
Oracle 数据库 10g 特别版:并非只适合初学者
2010-02-16 17:24 2037作者:Lewis Cunningham ...
相关推荐
Part I Understanding High Availability 1 Understanding High Availability 2 Microsoft High Availability Options Part II Choosing the Right High Availability Approaches 3 Choosing High Availability Part...
CentOS High Availability
PostgreSQL 9 High Availability Cookbook 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,...
Cost efective high availability for virtual machines
Neo4j High Availability 配置
Leverage the power of high availability clusters on CentOS Linux, the enterprise-class, open source operating system
唐继元Kubernetes Master High Availability 高级实践.pdf
The High Availability Framework Developer's Guide describes how to build robust high-availability software running on the QNX Neutrino RTOS.
The high performance and stability of CentOS Linux are the key factors that make CentOS Linux the right Linux distribution to build high availability solutions on. This book introduces you to high ...
Oracle High Availability, Disaster Recovery, and Cloud Services
Campus Network for High Availability Design Guide
MySQL High Availability 2nd Edition – PDF Books
SQL Server 2008 High Availability SQL Server 2008 High Availability
This book is for MySQL professionals. We expect you to have basic knowledge of SQL, MySQL administration, and the operating system you are running. We provide ...key topics of high availability
Title: CentOS High Availability Author: Mitja Resman Length: 156 pages Edition: 1 Language: English Publisher: Packt Publishing Publication Date: 2015-04-30 ISBN-10: 1785282484 ISBN-13: 9781785282485 ...
High Availability and Disaster Recovery Options for DB2 on LUW
MySQL High Availability 英文 第二版
相当经典的HA文档. 英文的. Providing Open Architecture High Availability Solutions Revision 1.0 Published by the HA Forum
High Availability MySQL Cookbook High Availability MySQL Cookbook High Availability MySQL Cookbook