DBUtil tutorial-Database Cluster backup

Source: Internet
Author: User
Tags columnar database

In the current system, massive data has become a major problem for software engineers. Many people focus on programming and database structure optimization, and then build some indexes and views. But when programming and table structure reach the extreme, what should we do for database optimization.

Oracle has a popular database cluster technology called rac. Rac should be the most optimized and popular technology in database clusters. But it is limited to databases of the same type and homogeneous type.

RAC is a representative of Server Load balancer. Its cluster is mainly used for not large but complex database queries, but for a large number of connections. But how can we solve this problem if we are dealing with a heterogeneous database.

In recent years, a popular database has entered our daily life, columnar database. It is a database with high query performance and low insertion performance. Sybaseiq is currently the main representative, and monetdb is the main open-source columnar database. However, column-based databases have many problems, including slow insertion, unstable databases, weak support for traditional database syntaxes, low stability, low threads, and low scalability. However, after more than a few million rows of data, the query speed of the column-based data library is more than 10 times that of mysql.

In a large system, the advantages of Row-based and column-based databases complement each other, and rational use has become a concern of developers. Today's clusters are also facing this problem.

Cluster principle:

In the dbutil cluster, we use a row-based database and several column-based databases. Each time we update data, we use the broadcast mode, adds, deletes, and modifies data through the broadcast mode, and the group body updates all data. When querying data, we will use the Connection Pool Mode to find the data used by the minimum number of people and query the data. In addition, you can set daily scheduled data synchronization to synchronize the data stored in row-type data to all nodes at a specific time.

Configuration method:

We have seen the use of DBUtil in several previous articles. The configuration method is similar to the previous tutorial.

1. Configure xml

 
 
  1. <! -- Cluster test database -->
  2. <Resource jndi = "jdbc/Cluster1" driverClass = "com. mysql. jdbc. Driver"
  3. DbUserName = "root" dbPassWord = "root"
  4. JdbcUrl = "jdbc: mysql: // 127.0.0.1: 3306/test? UseUnicode = true & characterEncoding = UTF-8"
  5. InitSize = "2" minPoolSize = "1" maxPoolSize = "10" maxStatements = "50"
  6. MaxIdleTime = "60"/>
  7. <Resource jndi = "jdbc/Cluster2" driverClass = "com. mysql. jdbc. Driver"
  8. DbUserName = "root" dbPassWord = "root"
  9. JdbcUrl = "jdbc: mysql: // 127.0.0.1: 3306/test2? UseUnicode = true & characterEncoding = UTF-8"
  10. InitSize = "2" minPoolSize = "1" maxPoolSize = "10" maxStatements = "50"
  11. MaxIdleTime = "60"/>
  12. <! -- Cluster -->
  13. <Cluster jndiCluster = "jdbc/Cluster" mainDB = "jdbc/Cluster1"
  14. Synchronous = "off" synchronousTime = "00:00" protect = "on">
  15. <Resource jndi = "jdbc/Cluster1"/>
  16. <Resource jndi = "jdbc/Cluster2"/>
  17. </Cluster>

Configuring xml is also the first step to configure two database nodes and then add them to the cluster.

  • JndiCluster: the unique identifier of the cluster.
  • MainDB: master database of the Cluster. mysql database is recommended.
  • Synchronous: synchronize data
  • SynchronousTime: synchronization time
  • Protect: protects the mode of querying data. You do not need to use the primary database, but only obtain the data of the cluster database)

2. Update Data

 
 
  1. Package com. shine. DBUtil;
  2.  
  3. Import com. shine. DBUtil. manage. DBManager;
  4. Import com. shine. DBUtil. utils. ClusterList;
  5.  
  6. Public class ClusterUpdateExample {
  7.  
  8. /**
  9. * Cluster update example
  10. *
  11. * @ Param args
  12. */
  13. Public static void main (String [] args ){
  14. System. out. println ("ClusterUpdateExample ...");
  15. DBUtil
  16. . GetInstance ()
  17. . Init (
  18. "E: \ workspace \ JavaFramework2.5 \ src \ com \ shine \ DBUtil \ config \ dbXml. xml ");
  19.  
  20. ClusterList list = DBManager. getInstance ()
  21. . GetClusterConnectionNameList ("jdbc/Cluster ");
  22. System. out. println ("primary database:" + list. getMainDB ());
  23. String SQL = "insert into test1 (test) value ('test ')";
  24. Dbutil.getinstance(cmd.exe cuteClusterUpdate ("jdbc/Cluster", SQL );
  25.  
  26. }
  27.  
  28. }

3. query data

 
 
  1. Package com. shine. DBUtil;
  2.  
  3. Import com. shine. DBUtil. model. DBModel;
  4.  
  5. Public class ClusterSelectExample {
  6.  
  7. /**
  8. * Cluster Query
  9. *
  10. * @ Param args
  11. */
  12. Public static void main (String [] args ){
  13. System. out. println ("ClusterSelectExample ...");
  14. DBUtil
  15. . GetInstance ()
  16. . Init (
  17. "E: \ workspace \ JavaFramework2.5 \ src \ com \ shine \ DBUtil \ config \ dbXml. xml ");
  18.  
  19. String SQL = "select * from test1 ";
  20. String clusterJndi = "jdbc/Cluster ";
  21. DBModel dbmodel1 = dbutil.getinstance(cmd.exe cuteClusterQuery (
  22. ClusterJndi, SQL );
  23.  
  24. DBModel dbmodel2 = dbutil.getinstance(cmd.exe cuteClusterQuery (
  25. ClusterJndi, SQL );
  26.  
  27. }
  28.  
  29. }

In fact, it is best not to select regular synchronization for cluster Database Synchronization unless otherwise required, because if a database cluster is used, there will inevitably be massive data. While DBUtil's regular synchronization is full-Database Synchronization, users should split tables according to business logic, and some synchronization is more practical.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.