My colleagues like to call me brother yuan, so I call this note a series of Brother yuan. Today I am interested in analyzing the amoeba source code, recording it here, and updating it at any time.
Amoeba currently has three project products:
Amoeba for MySQL:
Provides a database proxy solution for MySQL to implement read/write splitting between multiple MySQL databases, it has the following features: load balancing, high availability, query filtering, read/write splitting, routing-related query to the target database, and concurrent requests to merge results from multiple databases. On amoeba, you can achieve high availability, load balancing, and data slicing for multiple data sources.
Amoeba for Aladdin:
Similar to "amoeba for MySQL", "amoeba for MySQL" only supports MySQL databases, "amoeba for Aladdin" supports multiple databases, and multiple hybrid databases can be used in the background.
Amoeba for MongoDB:
Provides proxy functions for nosql database MongoDB, including heartbeat detection, load balancing, failover, and query aggregation.
From the perspective of amoeba products, they are all solutions for database storage applications in Distributed Cluster load scenarios, covering common database types.
The source code analysis of this series is true for amoeba for MySQL. The other two projects are actually changed after amoeba for MySQL. Therefore, I have understood amoeba for MySQL, you can understand the other two projects.
How to obtain the source code:
The Amoeba source code is currently on Google and can be pulled down using SVN:HTTP: // Amoeba.googlecode.com/svn/trunk
First, let's take a look at the source code project list:
Note: after creating a Maven project and associating the project code with Maven, I added it myself. If necessary, I can download the maven project that I added, you only need to import it.
Main categories:
Package name: COM. meidusa. amoeba. Server
Class Name: amoebaproxyserver
Responsibilities: amoeba starts the main entry. Note that for good scalability, this class is in the amoeba core project, not in the amoeba-mysql Project (whether amoeba for MySQL or amoeba for Aladdin, this class is used for the main portal)
Package name: COM. meidusa. amoeba. MySQL. Handler
Class Name: querycommandmessagehandler (inherited from Com. meidusa. amoeba. MySQL. handler. commandmessagehandler)
Responsibilities: SQL query command processor. The merging logic of database/table sharding query results is in the commandmessagehandler. mergemessages method of its parent class.
Package name: COM. meidusa. amoeba. MySQL. parser
Class Name: mysqlqueryrouter
Responsibilities: the MySQL route parser obtains the thread pool objects that comply with the routing rules based on SQL statements.
Package name: COM. meidusa. amoeba. MySQL. Handler
Class Name: mysqlcommanddispatcher (Implementation interface com.meidusa.amoeba.net. messagehandler)
Responsibilities: the SQL command issuer distributes the SQL commands requested by the client to the corresponding connection pool according to the amoeba routing configuration rules.
Package name: COM. meidusa. amoeba. MySQL. Handler
Class Name: commandqueue
Responsibilities: SQL command execution queue. All the statements sent by the client to Amoeba first enter this queue.
Package name: COM. meidusa. amoeba. MySQL. Context
Class Name: mysqlruntimecontext
Responsibilities: context information of amoeba runtime, including amoeba version number, SQL cache size, cache expiration time, etc.
Package name: com.meidusa.amoeba.mysql.net
Class Name: mysqlclientconnection
Responsibilities: encapsulate the object for connecting the client to Amoeba
Package name: com.meidusa.amoeba.mysql.net
Class Name: mysqlserverconnection
Responsibilities: encapsulate the object for connecting amoeba to the physical MySQL database
Package name: com.meidusa.amoeba.net. poolable
Class Name: multipleloadbalanceobjectpool
Responsibilities: implements an object pool that supports load balancing and uses commons-pool, an open-source project under Apache. In amoeba, this object pool is used to store server pool objects in Amoeba configuration.
Package name: COM. meidusa. amoeba. Route
Class Name: abstractqueryrouter
Responsibility: The logic for implementing read/write splitting is in this abstract class.