What is DatabaseSharding? In fact, it is a distributed computing that stores different types of data to different databases (with the same table structure) through business logic. Simply put, it is a server Load balancer technology. Because there is less data in each table, the query speed will be faster, and the system will be able to bear a large load. Many large companies are using this technology.
What is Database Sharding? In fact, it is a distributed computing that stores different types of data to different databases (with the same table structure) through business logic. Simply put, it is a server Load balancer technology. Because there is less data in each table, the query speed will be faster, and the system will be able to bear a large load. Many large companies are using this technology.
What is Database Sharding?
In fact, it is a distributed computing that stores different types of data to different databases (with the same table structure) through business logic. Simply put, it is a server Load balancer technology. Because there is less data in each table, the query speed will be faster, and the system will be able to bear a large load. Many large companies are using this technology, such as Google, Facebook, and Wikipedia.
What is the implementation policy of Liferay?
Liferay implements distribution based on the Portal Instance, that is, the data of different portal instances is stored in different databases. The data of the same portal instance is only in one database. Of course, some global data, such as ClassName, Company, and Counter, are stored on a node (default.
Configuration method in Liferay
1. First, you must have multiple Portal Instances on your system.
For example, babaodi.com, liushining.cn, smilingleo.cn, etc.
2. Install multiple databases (or multiple instances on one server), which can be heterogeneous. Create the minimum database using the create_minimal SQL script.
3. Remove the comments for the shard-data-source-spring.xml in portal. properties. And add the corresponding configuration content, such:
Jdbc. default. driverClassName = com. mysql. jdbc. Driverjdbc. default. url = jdbc: mysql: // localhost/lportal? UseUnicode = true & characterEncoding = UTF-8 & useFastDateParsing = falsejdbc. default. username = jdbc. default. password = jdbc. one. driverClassName = com. mysql. jdbc. driverjdbc. one. url = jdbc: mysql: // localhost/lportal1? UseUnicode = true & characterEncoding = UTF-8 & useFastDateParsing = falsejdbc. one. username = jdbc. one. password = jdbc. two. driverClassName = com. mysql. jdbc. driverjdbc. two. url = jdbc: mysql: // localhost/lportal? UseUnicode = true & characterEncoding = UTF-8 & useFastDateParsing = falsejdbc. two. username = jdbc. two. password = shard. available. names = default, one, two
In this way, your system can save the data of different portal instances to different databases.
Implementation Principle
The specific implementation of Liferay adopts AOP and defines a ShardAdvice in the shard-data-source-spring.xml,
</Aop: aspect> </aop: config>
It can be seen that all persistence Methods call the invokePersistence method, and this method is responsible for obtaining a data source (maintained in ThreadLocal) through the simple hash algorithm of instances % shards ).
Alternative Technology
Database Sharding is a distributed data processing technology related to businesses. It is not common enough and multiple data sources have multiple single points of failure.
A better general solution is C-JDBC (Sequoia), which evolves the concept of hardware RAID into Raidb, which solves the problem of distributed computing, you can also solve the single point of failure through RAIDb1.
Of course, C-JDBC is a cheap alternative with no money to buy "disk arrays", if you already have an array, then you don't need this technology. (When purchasing servers and other infrastructure, you need to consider what kind of software technology is useful, otherwise it will waste a lot of money .)