WO2024103902A1 - Database access method, apparatus and system, and device and readable storage medium - Google Patents

Database access method, apparatus and system, and device and readable storage medium Download PDF

Info

Publication number
WO2024103902A1
WO2024103902A1 PCT/CN2023/115587 CN2023115587W WO2024103902A1 WO 2024103902 A1 WO2024103902 A1 WO 2024103902A1 CN 2023115587 W CN2023115587 W CN 2023115587W WO 2024103902 A1 WO2024103902 A1 WO 2024103902A1
Authority
WO
WIPO (PCT)
Prior art keywords
database
node
virtual
mysql
mysql database
Prior art date
Application number
PCT/CN2023/115587
Other languages
French (fr)
Chinese (zh)
Inventor
高长玉
Original Assignee
苏州元脑智能科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 苏州元脑智能科技有限公司 filed Critical 苏州元脑智能科技有限公司
Publication of WO2024103902A1 publication Critical patent/WO2024103902A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/25Integrating or interfacing systems involving database management systems
    • G06F16/256Integrating or interfacing systems involving database management systems in federated or virtual databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5083Techniques for rebalancing the load in a distributed system

Definitions

  • the present application relates to the field of computer technology, and in particular to a database access method, device, system, equipment and non-volatile readable storage medium.
  • a master node and a slave node are generally set.
  • the master node is used to process write operations
  • the slave node is used to process query operations.
  • the master node After the master node completes the write operation, it will synchronize the currently written data to the slave node. Therefore, if the current amount of written data is large, the amount of synchronized data will be large. Therefore, in the case of a large number of write operations or low network bandwidth, there will be a delay in data synchronization, which will reduce the performance of the database service.
  • the purpose of this application is to provide a database access method, device, system, equipment and non-volatile readable storage medium to improve the database service performance in high concurrency scenarios.
  • the specific scheme is as follows:
  • the present application provides a database access method, which is applied to a virtual database, comprising:
  • the target database node completes the processing of the database access request by accessing the repository.
  • routing a database access request to any target database node managed by a virtual database according to a load balancing strategy includes:
  • the MySQL database node with the smallest weight is determined as the target database node, and the database access request is routed to the target database node.
  • the weight calculation process of any MySQL database node includes:
  • the sum of the routing frequency and the load score is used as the weight of the current MySQL database node.
  • calculating the routing frequency of the current MySQL database node includes:
  • calculating the load score of the current MySQL database node at the current moment includes:
  • it also includes:
  • it also includes:
  • the MySQL database nodes in the node sequence managed by the virtual database are added, deleted or modified by configuring update commands to obtain an updated node sequence;
  • managing and configuring each MySQL database node in the updated node sequence one by one includes:
  • managing and configuring the newly added MySQL database node includes:
  • it also includes:
  • the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
  • it also includes:
  • the present application provides a database access device, applied to a virtual database, comprising:
  • a receiving module used for receiving a database access request
  • a routing module used to route database access requests to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository;
  • the processing module is used to enable the target database node to complete the processing of the database access request by accessing the storage repository.
  • the routing module is specifically configured to:
  • the MySQL database node with the smallest weight is determined as the target database node, and the database access request is routed to the target database node.
  • it also includes:
  • the health monitoring module is used to periodically collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault mark is added to the MySQL database node.
  • it also includes:
  • the node configuration online update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through the configuration update command during the operation of the virtual database to obtain the updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
  • the node configuration online update module is specifically used to: determine the newly added MySQL database nodes in the updated node sequence; manage and configure the newly added MySQL database nodes one by one, and then manage and configure the remaining MySQL database nodes in the updated node sequence.
  • the node configuration online update module is specifically used to: configure the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database.
  • it also includes:
  • the service configuration operation module is used to query, add, delete or modify the service configuration of the virtual database according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
  • it also includes:
  • the node configuration offline update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database if the virtual database stops running, and restart the virtual database.
  • the present application provides a database access system, comprising: the aforementioned disclosed virtual database, multiple MySQL database nodes and a storage repository.
  • the virtual database is used to: receive database access requests; route the database access requests to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository; and enable the target database node to complete the processing of the database access request by accessing the repository.
  • the virtual database is used to: determine the MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy; determine the MySQL database node with the smallest weight as the target database node, and route the database access request to the target database node.
  • the virtual database is used to: calculate the routing frequency of the current MySQL database node; calculate the load score of the current MySQL database node at the current moment; and use the sum of the routing frequency and the load score as the weight of the current MySQL database node.
  • the virtual database is used to: regularly collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault mark is added to the MySQL database node.
  • the virtual database is used to: during the operation of the virtual database, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through configuration update commands to obtain an updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
  • the virtual database is used to: determine newly added MySQL database nodes in the updated node sequence; manage and configure the newly added MySQL database nodes one by one, and then manage and configure the remaining MySQL database nodes in the updated node sequence.
  • the virtual database is used to configure the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database.
  • the virtual database is used to query, add, delete or modify the service configuration of the virtual database according to user operations;
  • the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
  • the virtual database is used to: if the virtual database stops running, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database, and restart the virtual database.
  • the present application provides an electronic device, including:
  • the processor is used to execute the computer program to implement the aforementioned disclosed database access method.
  • the present application provides a non-volatile readable storage medium for storing a computer program, wherein the computer program implements the aforementioned disclosed database access method when executed by a processor.
  • the present application provides a database access method, which is applied to a virtual database, including: receiving a database access request; routing the database access request to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository; and enabling the target database node to complete the processing of the database access request by accessing the repository.
  • the present application adopts a virtual database to manage multiple MySQL database nodes that share the same repository, and when a database access request is received, the database access request can be routed to any target database node managed by the virtual database according to the load balancing strategy, so that each MySQL database node can complete the processing of the database access request by accessing the repository.
  • This solution abandons the master-slave concept of the database and instead enables each MySQL database node to share the same repository, which not only avoids synchronous operations in high-concurrency scenarios, thereby avoiding the impact of synchronous operations on database service performance, but also allows the same copy of data to exist in one copy, thereby ensuring data consistency.
  • the various database nodes managed by the virtual database can share access requests according to the load balancing strategy, so as to maximize the availability of each database node, thereby ensuring the stability, reliability and high availability of the entire database access service.
  • a database access device, system, equipment and non-volatile readable storage medium provided by the present application also have the above-mentioned technical effects.
  • FIG1 is a flow chart of a database access method disclosed in some embodiments of the present application.
  • FIG2 is a schematic diagram of a database access system disclosed in some embodiments of the present application.
  • FIG3 is a schematic diagram of a database access device disclosed in some embodiments of the present application.
  • FIG. 4 is a schematic diagram of an electronic device disclosed in some embodiments of the present application.
  • MySQL databases generally set up master nodes and slave nodes.
  • the master node is used to process write operations
  • the slave node is used to process query operations.
  • the master node will synchronize the currently written data to the slave node. Therefore, if the current amount of written data is large, the amount of synchronized data will be large. Therefore, in the case of a large number of write operations or when the network bandwidth is low, there will be a delay in data synchronization, which will reduce the database service performance.
  • the present application provides a database access solution that enables each MySQL database node to share the same repository, avoids the impact of synchronization operations on database service performance, and can also ensure the consistency of data storage and the stability, reliability and high availability of the entire database access service.
  • the embodiment of the present application discloses a database access method, which is applied to a virtual database, including:
  • a database access request is an SQL statement for implementing a query operation or an SQL statement for implementing a write operation.
  • the virtual database in this embodiment can be understood as a software service that can simultaneously manage multiple MySQL database nodes, which are connected to the same storage repository through network devices such as switches, that is, these MySQL database nodes share the same storage repository, thereby realizing a shared storage service.
  • a database access request is routed to any target database node managed by the virtual database according to a load balancing strategy, including: determining a MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy; determining the MySQL database node with the smallest weight as the target database node, and routing the database access request to the target database node.
  • the weight calculation process of any MySQL database node includes: calculating the routing frequency of the current MySQL database node; calculating the load evaluation of the current MySQL database node at the current moment; The sum of the routing frequency and the load score is used as the weight of the current MySQL database node.
  • the current MySQL database node is any node managed by the virtual database.
  • S103 Enable the target database node to complete the processing of the database access request by accessing the storage repository.
  • the target database node can query the corresponding information in the repository or write certain information into the repository by executing the SQL statement.
  • the service configuration of the virtual database can be queried, added, deleted or modified according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
  • this embodiment uses a virtual database to manage multiple MySQL database nodes that share the same repository, and when a database access request is received, the database access request can be routed to any target database node managed by the virtual database according to the load balancing strategy, so that each MySQL database node can complete the processing of the database access request by accessing the repository.
  • This solution abandons the master-slave concept of the database and instead enables each MySQL database node to share the same repository, thereby not only avoiding synchronous operations in high-concurrency scenarios, thereby avoiding the impact of synchronous operations on database service performance, but also allowing the same copy of data to exist in one copy, thereby ensuring data consistency.
  • the various database nodes managed by the virtual database can share access requests according to the load balancing strategy, thereby maximizing the availability of each database node, thereby ensuring the stability, reliability and high availability of the entire database access service.
  • the virtual database can monitor the status of each MySQL database node it manages.
  • the operating status of all MySQL database nodes managed by the virtual database is regularly collected and recorded; if any MySQL database node fails, a fault mark is added to the MySQL database node.
  • the MySQL database nodes managed by the virtual database can also be flexibly adjusted, including online adjustment and offline adjustment.
  • Online adjustment means during the operation of the virtual database, the MySQL database nodes in the node sequence managed by the virtual database are added, deleted or modified through the configuration update command to obtain the updated node sequence; each MySQL database node in the updated node sequence is managed and configured one by one.
  • Offline adjustment means if the virtual database stops running, the MySQL database nodes in the node sequence managed by the virtual database are added, deleted or modified, and the virtual database is restarted.
  • the managed nodes of the virtual database refer to: nodes that can be used to process requests. In other words, faulty nodes or nodes that have been disconnected from the service are not in the node sequence.
  • each MySQL database node in the updated node sequence is managed and configured one by one, including: determining the newly added MySQL database node in the updated node sequence; after managing and configuring the newly added MySQL database node one by one, the remaining MySQL database nodes in the updated node sequence are managed and configured (such as: when the node IP, port and other information are checked to be updated, the corresponding information is updated).
  • the management and configuration of the newly added MySQL database node includes: configuring the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database. For example: a certain MySQL database node is recorded in the node sequence as: IP: port: username: password.
  • nodes A and B were changed to nodes C and D. Then nodes C and D should be configured first so that they can accept access requests. If nodes A and B are stopped first, the virtual database service will be interrupted.
  • this embodiment provides a specific structure for the virtual database, including: virtual service, configuration center, virtual service, load balancing, health check and other modules.
  • the configuration center module can be used to change and read the relevant configuration information of the virtual database, including: basic connection configuration and service configuration.
  • the basic connection configuration is used to set each node managed by the virtual database. It uses the form of ip:port:username:password to record each node managed by the virtual database.
  • config.dbpool.serverList 10.0.0.1:3306:root:mysqladmin
  • x is an increasing Arabic numeral. It can be seen that multiple user IPs can be set to access the virtual database as needed.
  • Both the basic connection configuration and the service configuration can be recorded in the configuration file, and the user can modify the configuration file at any time.
  • the configuration center will read the configuration file and assist other modules to complete the service initialization.
  • the user can also query and modify the relevant configuration through the following commands. For example: Use lssharedbconfig-i configName to query the service configuration information. "–i" is an optional parameter. If it is not filled in, all information will be returned. If it is filled in, specific configuration content will be returned.
  • Use chgsharedbconfig-i configName configValue to modify the service configuration information. "–i" is an optional parameter. This parameter has two parameter values. The first item is the configuration name, and the second item is the configuration item content.
  • Use refreshsharedbconfig to read the configuration information and restart the virtual service.
  • the virtual database is the intermediate bridge between the underlying real database cluster and the user service request.
  • the underlying database cluster is in a black box state for users. Users will not directly access specific database nodes, but access the virtual services provided by the virtual database, so that the virtual services can route requests to specific database nodes. Therefore, the virtual service provides users with a unified access entrance, which can shield the complex internal design and improve the simplicity of the system.
  • the load balancing module is a pre-function for virtual service routing. This module can select the most suitable node in the current database cluster for virtual service routing according to the set routing rules. This module can ensure that service requests can fall on each node as evenly as possible, providing the load capacity of the entire system.
  • the load balancing routing rules include: (1) Recording the node routing times of the last 1000 requests, and counting the usage weight score of each node (i.e., routing frequency) each time routing, and the calculation rule is: node routing times/total routing times 1000.
  • the health check module will regularly check the health status of each database node and collect relevant data for use by the load balancing module. If a node fails, the load balancing module will identify this event, and the node will no longer be included in the routing scope until the health check module reports that it has returned to normal. This module is responsible for troubleshooting node failures in the system and has the ability to automatically recover after the node is normal, ensuring the high availability of the entire system.
  • each database node in the database cluster uses shared storage as data storage space to ensure the consistency of data storage.
  • the instance information of each database node is registered in the virtual database through the configuration file.
  • the configuration center When the virtual database service is started, the configuration center will read the relevant configuration file. After reading, it will notify the health check module to connect and initialize the database node. After checking the connectivity of each database node in turn, the health check module records the database nodes in a healthy state and notifies the virtual service to route the request.
  • the database cluster can be expanded or reduced in capacity by either stopping or starting the system.
  • the virtual service handles the downtime state. Users can directly modify the configuration file to change the database node list. After the change, restart the service and the scaling will take effect.
  • each database node is initialized one by one to ensure that at least one node can process access requests during the entire process, thereby ensuring service availability and avoiding the situation where no available database node can be found when a new request comes in.
  • the processing of a service request includes: after the request reaches the virtual service, the virtual service tries to obtain an available high-performance node with the help of the load balancing module, that is, the load balancing module selects the healthy node with the lowest weight score from the current database cluster as the routing node and returns it to the virtual service. At this time, the virtual service enables the routing node to execute the SQL statement to complete the service request to access the shared storage.
  • this embodiment provides a unified access entrance for user requests, and establishes a multi-node database cluster based on shared storage, canceling the synchronization mechanism of the master-slave node.
  • it can overcome the data synchronization delay when writing large amounts of data, and on the other hand, it can expand the number of nodes horizontally.
  • the unified access entrance shields the underlying cluster structure, and with the help of load balancing strategies, the database service can run normally in high concurrency and high pressure scenarios, ensuring the stability, reliability and high availability of the entire service.
  • a database access device provided in an embodiment of the present application is introduced below.
  • the database access device described below and the database access method described above can be referenced to each other.
  • the embodiment of the present application discloses a database access device, which is applied to a virtual database, including:
  • Receiving module 301 used for receiving a database access request
  • the routing module 302 is used to route the database access request to any target database node managed by the virtual database according to the load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same storage repository;
  • the processing module 303 is used to enable the target database node to complete the processing of the database access request by accessing the storage repository.
  • the routing module is specifically used to:
  • the MySQL database node with the smallest weight is determined as the target database node, and the database access request is routed to the target database node.
  • the following further includes:
  • the health monitoring module is used to periodically collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault mark is added to the MySQL database node.
  • the following further includes:
  • the node configuration online update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through the configuration update command during the operation of the virtual database to obtain the updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
  • the node configuration online update module is specifically used to: configure the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database.
  • the following further includes:
  • the service configuration operation module is used to query, add, delete or modify the service configuration of the virtual database according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
  • the following further includes:
  • the node configuration offline update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database if the virtual database stops running, and restart the virtual database.
  • a database access device provided in an embodiment of the present application is introduced below.
  • the database access device described below and the database access method described above can be referenced to each other.
  • the embodiment of the present application discloses a database access system, including: the virtual database disclosed in the above embodiment, multiple MySQL database nodes and a storage repository. Specifically, please refer to Figure 2, where the shared storage in Figure 2 is the storage repository.
  • the virtual database is used to: calculate the routing frequency of the current MySQL database node; calculate the load score of the current MySQL database node at the current moment; and use the sum of the routing frequency and the load score as the weight of the current MySQL database node.
  • the virtual database is used to: regularly collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault identifier is added to the MySQL database node.
  • the virtual database is used to: during the operation of the virtual database, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through configuration update commands to obtain an updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
  • the virtual database is used to: determine newly added MySQL database nodes in the updated node sequence; manage and configure the newly added MySQL database nodes one by one, and then manage and configure the remaining MySQL database nodes in the updated node sequence.
  • the virtual database is used to query, add, delete or modify the service configuration of the virtual database according to user operations;
  • the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
  • the virtual database is used to: if the virtual database stops running, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database, and restart the virtual database.
  • An electronic device provided in an embodiment of the present application is introduced below.
  • the electronic device described below and the database access method and device described above can be referenced to each other.
  • an electronic device including:
  • Memory 401 used for storing computer programs
  • the processor 402 is used to execute the computer program to implement the method disclosed in any of the above embodiments.
  • an embodiment of the present application also provides a server as the above-mentioned electronic device.
  • the server may specifically include: at least one processor, at least one memory, a power supply, a communication interface, an input/output interface, and a communication bus.
  • the memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the relevant steps in the database access method disclosed in any of the above-mentioned embodiments.
  • the power supply is used to provide working voltage for each hardware device on the server;
  • the communication interface can create a data transmission channel between the server and external devices, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here;
  • the input and output interface is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
  • the memory as a carrier for resource storage can be a read-only memory, random access memory, disk or CD, etc.
  • the resources stored thereon include operating system, computer programs and data, etc.
  • the storage method can be temporary storage or permanent storage.
  • the operating system is used to manage and control the hardware devices and computer programs on the server to realize the operation and processing of the data in the memory by the processor, which can be Windows Server, Netware, Unix, Linux, etc.
  • computer programs can also further include computer programs that can be used to complete other specific tasks.
  • data can also include data such as the developer information of the virtual machine.
  • the embodiment of the present application also provides a terminal as the above electronic device.
  • the terminal may specifically include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.
  • the terminal in this embodiment includes: a processor and a memory.
  • the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc.
  • the processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array).
  • the processor may also include a main processor and a coprocessor.
  • the main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state.
  • the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen.
  • the processor may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
  • AI Artificial Intelligence
  • the memory may include one or more computer non-volatile readable storage media, which may be non-transitory.
  • the memory may also include high-speed random access memory, and non-volatile memory, such as one or more disk storage devices, flash memory storage devices.
  • the memory is at least used to store the following computer program, wherein, after the computer program is loaded and executed by the processor, it can implement the relevant steps in the database access method performed by the terminal side disclosed in any of the aforementioned embodiments.
  • the resources stored in the memory may also include an operating system and data, etc., and the storage method may be temporary storage or permanent storage.
  • the operating system may include Windows, Unix, Linux, etc.
  • the data may include, but is not limited to, update information of the application.
  • the terminal may also include a display screen, an input and output interface, a communication interface, a sensor, a power supply, and a communication bus.
  • a non-volatile readable storage medium provided in an embodiment of the present application is introduced below.
  • the non-volatile readable storage medium described below and the database access method, apparatus and device described above can be referenced to each other.
  • a non-volatile readable storage medium is used to store a computer program, wherein the computer program implements the database access method disclosed in the above embodiment when executed by a processor.
  • the steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two.
  • the software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of non-volatile readable storage medium known in the art.

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

Disclosed in the present application are a database access method, apparatus and system, and a device and a readable storage medium in the technical field of computers. The method in the present application is applied to a virtual database, and can comprise: according to a load balancing policy, routing a database access request to any target database node managed by a virtual database, wherein the virtual database manages a plurality of MySQL database nodes, and all the MySQL database nodes share the same repository; and enabling the target database node to complete the processing of the request by means of accessing the repository. The present application abandons the master-slave database concept and makes MySQL database nodes share the same repository, such that a synchronization operation in a high-concurrency scenario can be avoided, and data storage can also be made consistent; in addition, the stability, reliability and high availability of a database access service can also be ensured by means of load balancing. The database access apparatus and system, and the device and the non-volatile readable storage medium provided in the present application also have the above technical effects.

Description

一种数据库访问方法、装置、系统、设备及可读存储介质A database access method, device, system, equipment and readable storage medium
本申请要求于2022年11月14日提交中国专利局,申请号为202211417410.7,申请名称为“一种数据库访问方法、装置、系统、设备及可读存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to a Chinese patent application filed with the China Patent Office on November 14, 2022, with application number 202211417410.7 and application name “A Database Access Method, Device, System, Equipment and Readable Storage Medium”, all contents of which are incorporated by reference into this application.
技术领域Technical Field
本申请涉及计算机技术领域,特别涉及一种数据库访问方法、装置、系统、设备及非易失性可读存储介质。The present application relates to the field of computer technology, and in particular to a database access method, device, system, equipment and non-volatile readable storage medium.
背景技术Background technique
相关技术中,为了保证MySQL数据库服务的高可用以及稳定运行,一般会设置主节点和从节点。其中,主节点用于处理写操作,从节点用于处理查操作。并且,主节点在完成写操作后,会同步当前所写数据至从节点。因此,若当前所写数据量大,那么同步数据量就大,因此在大量写操作情况下或网络带宽较低的情况下,会有数据同步的延时,会降低数据库服务性能。In the related art, in order to ensure the high availability and stable operation of the MySQL database service, a master node and a slave node are generally set. Among them, the master node is used to process write operations, and the slave node is used to process query operations. In addition, after the master node completes the write operation, it will synchronize the currently written data to the slave node. Therefore, if the current amount of written data is large, the amount of synchronized data will be large. Therefore, in the case of a large number of write operations or low network bandwidth, there will be a delay in data synchronization, which will reduce the performance of the database service.
发明内容Summary of the invention
有鉴于此,本申请的目的在于提供一种数据库访问方法、装置、系统、设备及非易失性可读存储介质,以提高高并发场景下的数据库服务性能。其具体方案如下:In view of this, the purpose of this application is to provide a database access method, device, system, equipment and non-volatile readable storage medium to improve the database service performance in high concurrency scenarios. The specific scheme is as follows:
第一方面,本申请提供了一种数据库访问方法,应用于虚拟数据库,包括:In a first aspect, the present application provides a database access method, which is applied to a virtual database, comprising:
接收数据库访问请求;receiving a database access request;
按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点;其中,虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;Routing database access requests to any target database node managed by the virtual database according to the load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository;
使目标数据库节点通过访问存储库完成数据库访问请求的处理。The target database node completes the processing of the database access request by accessing the repository.
在一些实施例中,按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点,包括:In some embodiments, routing a database access request to any target database node managed by a virtual database according to a load balancing strategy includes:
按照负载均衡策略在虚拟数据库纳管的所有MySQL数据库节点中确定权重最小的MySQL数据库节点;Determine the MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy;
将权重最小的MySQL数据库节点确定为目标数据库节点,并将数据库访问请求路由至目标数据库节点。The MySQL database node with the smallest weight is determined as the target database node, and the database access request is routed to the target database node.
在一些实施例中,任一MySQL数据库节点的权重计算过程包括:In some embodiments, the weight calculation process of any MySQL database node includes:
计算当前MySQL数据库节点的路由频繁程度;Calculate the routing frequency of the current MySQL database node;
计算当前MySQL数据库节点在当前时刻的负载评分;Calculate the load score of the current MySQL database node at the current moment;
将路由频繁程度和负载评分之和,作为当前MySQL数据库节点的权重。The sum of the routing frequency and the load score is used as the weight of the current MySQL database node.
在一些实施例中,计算当前MySQL数据库节点的路由频繁程度,包括:In some embodiments, calculating the routing frequency of the current MySQL database node includes:
按照第一公式计算当前MySQL数据库节点的路由频繁程度;第一公式为:Wu=Ci/CS,Wu为MySQL数据库节点i的路由频繁程度,Ci为MySQL数据库节点i的被路由次数,CS为预设的被路由次数最大值。 The routing frequency of the current MySQL database node is calculated according to the first formula; the first formula is: Wu = Ci /C S , Wu is the routing frequency of MySQL database node i, Ci is the number of times MySQL database node i is routed, and C S is the preset maximum number of times of being routed.
在一些实施例中,计算当前MySQL数据库节点在当前时刻的负载评分,包括:In some embodiments, calculating the load score of the current MySQL database node at the current moment includes:
按照第二公式计算当前MySQL数据库节点在当前时刻的负载评分;第二公式为:Wload=LCPU×a+Lm×b+LIO×c,Wload为当前MySQL数据库节点的负载评分,LCPU为当前MySQL数据库节点的CPU负载,Lm为当前MySQL数据库节点的内存负载,LIO为当前MySQL数据库节点的IO负载,a、b、c均为预设系数。The load score of the current MySQL database node at the current moment is calculated according to the second formula; the second formula is: W load =L CPU ×a+L m ×b+L IO ×c, W load is the load score of the current MySQL database node, L CPU is the CPU load of the current MySQL database node, L m is the memory load of the current MySQL database node, L IO is the IO load of the current MySQL database node, and a, b, and c are all preset coefficients.
在一些实施例中,还包括:In some embodiments, it also includes:
定时采集并记录虚拟数据库纳管的所有MySQL数据库节点的运行状态;Regularly collect and record the operating status of all MySQL database nodes managed by the virtual database;
若任意MySQL数据库节点故障,则为该MySQL数据库节点添加故障标识。If any MySQL database node fails, a failure flag is added to the MySQL database node.
在一些实施例中,还包括:In some embodiments, it also includes:
在虚拟数据库运行过程中,通过配置更新命令对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,得到更新后的节点序列;During the operation of the virtual database, the MySQL database nodes in the node sequence managed by the virtual database are added, deleted or modified by configuring update commands to obtain an updated node sequence;
逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置。Manage and configure each MySQL database node in the updated node sequence one by one.
在一些实施例中,逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置,包括:In some embodiments, managing and configuring each MySQL database node in the updated node sequence one by one includes:
在更新后的节点序列中确定新增MySQL数据库节点;Determine the newly added MySQL database node in the updated node sequence;
逐一对新增MySQL数据库节点进行管理配置后,再对更新后的节点序列中的剩余MySQL数据库节点进行管理配置。After managing and configuring the newly added MySQL database nodes one by one, manage and configure the remaining MySQL database nodes in the updated node sequence.
在一些实施例中,对新增MySQL数据库节点进行管理配置,包括:In some embodiments, managing and configuring the newly added MySQL database node includes:
将新增MySQL数据库节点的IP地址、端口、数据库账号及数据库登录密码配置于虚拟数据库。Configure the IP address, port, database account, and database login password of the newly added MySQL database node in the virtual database.
在一些实施例中,还包括:In some embodiments, it also includes:
根据用户操作对虚拟数据库的服务配置进行查询、增加、删除或修改;服务配置包括:最大可用连接数、最大空闲连接数、最长等待时间、访问地址、访问端口、虚拟数据库账号及虚拟数据库登录密码。Query, add, delete or modify the service configuration of the virtual database according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
在一些实施例中,还包括:In some embodiments, it also includes:
若虚拟数据库停止运行,则对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,并重启虚拟数据库。If the virtual database stops running, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database, and restart the virtual database.
第二方面,本申请提供了一种数据库访问装置,应用于虚拟数据库,包括:In a second aspect, the present application provides a database access device, applied to a virtual database, comprising:
接收模块,用于接收数据库访问请求;A receiving module, used for receiving a database access request;
路由模块,用于按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点;其中,虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;A routing module, used to route database access requests to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository;
处理模块,用于使目标数据库节点通过访问存储库完成数据库访问请求的处理。The processing module is used to enable the target database node to complete the processing of the database access request by accessing the storage repository.
在一些实施例中,路由模块具体用于:In some embodiments, the routing module is specifically configured to:
按照负载均衡策略在虚拟数据库纳管的所有MySQL数据库节点中确定权重最小的MySQL数据库节点;Determine the MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy;
将权重最小的MySQL数据库节点确定为目标数据库节点,并将数据库访问请求路由至目标数据库节点。 The MySQL database node with the smallest weight is determined as the target database node, and the database access request is routed to the target database node.
在一些实施例中,还包括:In some embodiments, it also includes:
健康监测模块,用于定时采集并记录虚拟数据库纳管的所有MySQL数据库节点的运行状态;若任意MySQL数据库节点故障,则为该MySQL数据库节点添加故障标识。The health monitoring module is used to periodically collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault mark is added to the MySQL database node.
在一些实施例中,还包括:In some embodiments, it also includes:
节点配置在线更新模块,用于在虚拟数据库运行过程中,通过配置更新命令对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,得到更新后的节点序列;逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置。The node configuration online update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through the configuration update command during the operation of the virtual database to obtain the updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
在一些实施例中,节点配置在线更新模块具体用于:在更新后的节点序列中确定新增MySQL数据库节点;逐一对新增MySQL数据库节点进行管理配置后,再对更新后的节点序列中的剩余MySQL数据库节点进行管理配置。In some embodiments, the node configuration online update module is specifically used to: determine the newly added MySQL database nodes in the updated node sequence; manage and configure the newly added MySQL database nodes one by one, and then manage and configure the remaining MySQL database nodes in the updated node sequence.
在一些实施例中,节点配置在线更新模块具体用于:将新增MySQL数据库节点的IP地址、端口、数据库账号及数据库登录密码配置于虚拟数据库。In some embodiments, the node configuration online update module is specifically used to: configure the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database.
在一些实施例中,还包括:In some embodiments, it also includes:
服务配置操作模块,用于根据用户操作对虚拟数据库的服务配置进行查询、增加、删除或修改;服务配置包括:最大可用连接数、最大空闲连接数、最长等待时间、访问地址、访问端口、虚拟数据库账号及虚拟数据库登录密码。The service configuration operation module is used to query, add, delete or modify the service configuration of the virtual database according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
在一些实施例中,还包括:In some embodiments, it also includes:
节点配置离线更新模块,用于若虚拟数据库停止运行,则对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,并重启虚拟数据库。The node configuration offline update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database if the virtual database stops running, and restart the virtual database.
第三方面,本申请提供了一种数据库访问系统,包括:前述公开的虚拟数据库、多个MySQL数据库节点以及存储库。In a third aspect, the present application provides a database access system, comprising: the aforementioned disclosed virtual database, multiple MySQL database nodes and a storage repository.
在一些实施例中,虚拟数据库用于:接收数据库访问请求;按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点;其中,虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;使目标数据库节点通过访问存储库完成数据库访问请求的处理。In some embodiments, the virtual database is used to: receive database access requests; route the database access requests to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository; and enable the target database node to complete the processing of the database access request by accessing the repository.
在一些实施例中,虚拟数据库用于:按照负载均衡策略在虚拟数据库纳管的所有MySQL数据库节点中确定权重最小的MySQL数据库节点;将权重最小的MySQL数据库节点确定为目标数据库节点,并将数据库访问请求路由至目标数据库节点。In some embodiments, the virtual database is used to: determine the MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy; determine the MySQL database node with the smallest weight as the target database node, and route the database access request to the target database node.
在一些实施例中,虚拟数据库用于:计算当前MySQL数据库节点的路由频繁程度;计算当前MySQL数据库节点在当前时刻的负载评分;将路由频繁程度和负载评分之和,作为当前MySQL数据库节点的权重。In some embodiments, the virtual database is used to: calculate the routing frequency of the current MySQL database node; calculate the load score of the current MySQL database node at the current moment; and use the sum of the routing frequency and the load score as the weight of the current MySQL database node.
在一些实施例中,虚拟数据库用于:按照第一公式计算当前MySQL数据库节点的路由频繁程度;第一公式为:Wu=Ci/CS,Wu为MySQL数据库节点i的路由频繁程度,Ci为MySQL数据库节点i的被路由次数,CS为预设的被路由次数最大值。In some embodiments, the virtual database is used to calculate the routing frequency of the current MySQL database node according to a first formula; the first formula is: Wu = Ci / Cs , Wu is the routing frequency of MySQL database node i, Ci is the number of times MySQL database node i is routed, and Cs is the preset maximum number of times of being routed.
在一些实施例中,虚拟数据库用于:按照第二公式计算当前MySQL数据库节点在当前时刻的负载评分;第二公式为:Wload=LCPU×a+Lm×b+LIO×c,Wload为当前MySQL数据库节点的负载评分,LCPU为当前MySQL数据库节点的CPU负载,Lm为当前MySQL数据库节点的内存负载,LIO为当前MySQL数据库节点的IO负载,a、b、c均为预设系数。 In some embodiments, the virtual database is used to: calculate the load score of the current MySQL database node at the current moment according to the second formula; the second formula is: W load =L CPU ×a+L m ×b+L IO ×c, W load is the load score of the current MySQL database node, L CPU is the CPU load of the current MySQL database node, L m is the memory load of the current MySQL database node, L IO is the IO load of the current MySQL database node, and a, b, and c are all preset coefficients.
在一些实施例中,虚拟数据库用于:定时采集并记录虚拟数据库纳管的所有MySQL数据库节点的运行状态;若任意MySQL数据库节点故障,则为该MySQL数据库节点添加故障标识。In some embodiments, the virtual database is used to: regularly collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault mark is added to the MySQL database node.
在一些实施例中,虚拟数据库用于:在虚拟数据库运行过程中,通过配置更新命令对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,得到更新后的节点序列;逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置。In some embodiments, the virtual database is used to: during the operation of the virtual database, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through configuration update commands to obtain an updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
在一些实施例中,虚拟数据库用于:在更新后的节点序列中确定新增MySQL数据库节点;逐一对新增MySQL数据库节点进行管理配置后,再对更新后的节点序列中的剩余MySQL数据库节点进行管理配置。In some embodiments, the virtual database is used to: determine newly added MySQL database nodes in the updated node sequence; manage and configure the newly added MySQL database nodes one by one, and then manage and configure the remaining MySQL database nodes in the updated node sequence.
在一些实施例中,虚拟数据库用于:将新增MySQL数据库节点的IP地址、端口、数据库账号及数据库登录密码配置于虚拟数据库。In some embodiments, the virtual database is used to configure the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database.
在一些实施例中,虚拟数据库用于:根据用户操作对虚拟数据库的服务配置进行查询、增加、删除或修改;服务配置包括:最大可用连接数、最大空闲连接数、最长等待时间、访问地址、访问端口、虚拟数据库账号及虚拟数据库登录密码。In some embodiments, the virtual database is used to query, add, delete or modify the service configuration of the virtual database according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
在一些实施例中,虚拟数据库用于:若虚拟数据库停止运行,则对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,并重启虚拟数据库。In some embodiments, the virtual database is used to: if the virtual database stops running, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database, and restart the virtual database.
第四方面,本申请提供了一种电子设备,包括:In a fourth aspect, the present application provides an electronic device, including:
存储器,用于存储计算机程序;Memory for storing computer programs;
处理器,用于执行计算机程序,以实现前述公开的数据库访问方法。The processor is used to execute the computer program to implement the aforementioned disclosed database access method.
第五方面,本申请提供了一种非易失性可读存储介质,用于保存计算机程序,其中,计算机程序被处理器执行时实现前述公开的数据库访问方法。In a fifth aspect, the present application provides a non-volatile readable storage medium for storing a computer program, wherein the computer program implements the aforementioned disclosed database access method when executed by a processor.
通过以上方案可知,本申请提供了一种数据库访问方法,应用于虚拟数据库,包括:接收数据库访问请求;按照负载均衡策略将所述数据库访问请求路由至所述虚拟数据库纳管的任一目标数据库节点;其中,所述虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;使所述目标数据库节点通过访问所述存储库完成所述数据库访问请求的处理。It can be seen from the above scheme that the present application provides a database access method, which is applied to a virtual database, including: receiving a database access request; routing the database access request to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository; and enabling the target database node to complete the processing of the database access request by accessing the repository.
可见,本申请采用虚拟数据库纳管多个共享同一存储库的MySQL数据库节点,并在接收到数据库访问请求时,按照负载均衡策略可以将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点上,从而使各个MySQL数据库节点都能通过访问存储库完成数据库访问请求的处理。该方案抛弃了数据库主从概念,转而使各个MySQL数据库节点共享同一存储库,由此不仅可避免高并发场景下的同步操作,从而避免同步操作对数据库服务性能的影响,还可以使同一份数据存在一份,以此来保证数据一致性。并且,可以按照负载均衡策略使虚拟数据库纳管的各个数据库节点分担访问请求,从而尽可能发挥每个数据库节点的可用性,从而保证整个数据库访问服务的稳定性、可靠性以及高可用。It can be seen that the present application adopts a virtual database to manage multiple MySQL database nodes that share the same repository, and when a database access request is received, the database access request can be routed to any target database node managed by the virtual database according to the load balancing strategy, so that each MySQL database node can complete the processing of the database access request by accessing the repository. This solution abandons the master-slave concept of the database and instead enables each MySQL database node to share the same repository, which not only avoids synchronous operations in high-concurrency scenarios, thereby avoiding the impact of synchronous operations on database service performance, but also allows the same copy of data to exist in one copy, thereby ensuring data consistency. In addition, the various database nodes managed by the virtual database can share access requests according to the load balancing strategy, so as to maximize the availability of each database node, thereby ensuring the stability, reliability and high availability of the entire database access service.
相应地,本申请提供的一种数据库访问装置、系统、设备及非易失性可读存储介质,也同样具有上述技术效果。Correspondingly, a database access device, system, equipment and non-volatile readable storage medium provided by the present application also have the above-mentioned technical effects.
附图说明 BRIEF DESCRIPTION OF THE DRAWINGS
为了更清楚地说明本申请实施例或相关技术中的技术方案,下面将对实施例或相关技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the technical solutions in the embodiments of the present application or the related technologies, the drawings required for use in the embodiments or the related technical descriptions are briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
图1为本申请一些实施例中公开的一种数据库访问方法流程图;FIG1 is a flow chart of a database access method disclosed in some embodiments of the present application;
图2为本申请一些实施例中公开的一种数据库访问系统示意图;FIG2 is a schematic diagram of a database access system disclosed in some embodiments of the present application;
图3为本申请一些实施例中公开的一种数据库访问装置示意图;FIG3 is a schematic diagram of a database access device disclosed in some embodiments of the present application;
图4为本申请一些实施例中公开的一种电子设备示意图。FIG. 4 is a schematic diagram of an electronic device disclosed in some embodiments of the present application.
具体实施方式Detailed ways
下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本申请保护的范围。The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
目前,MySQL数据库一般会设置主节点和从节点。其中,主节点用于处理写操作,从节点用于处理查操作。并且,主节点在完成写操作后,会同步当前所写数据至从节点。因此,若当前所写数据量大,那么同步数据量就大,因此在大量写操作情况下或网络带宽较低的情况下,会有数据同步的延时,会降低数据库服务性能。为此,本申请提供了一种数据库访问方案,能够使各个MySQL数据库节点共享同一存储库,避免同步操作对数据库服务性能的影响,还能保证数据存储的一致性以及整个数据库访问服务的稳定性、可靠性以及高可用。At present, MySQL databases generally set up master nodes and slave nodes. Among them, the master node is used to process write operations, and the slave node is used to process query operations. In addition, after completing the write operation, the master node will synchronize the currently written data to the slave node. Therefore, if the current amount of written data is large, the amount of synchronized data will be large. Therefore, in the case of a large number of write operations or when the network bandwidth is low, there will be a delay in data synchronization, which will reduce the database service performance. To this end, the present application provides a database access solution that enables each MySQL database node to share the same repository, avoids the impact of synchronization operations on database service performance, and can also ensure the consistency of data storage and the stability, reliability and high availability of the entire database access service.
参见图1所示,本申请实施例公开了一种数据库访问方法,应用于虚拟数据库,包括:As shown in FIG1 , the embodiment of the present application discloses a database access method, which is applied to a virtual database, including:
S101、接收数据库访问请求。S101: Receive a database access request.
在本申请一些实施例中,数据库访问请求即:用于实现查询操作的SQL语句或用于实现写操作的SQL语句。本实施例中的虚拟数据库可以理解为一个软件服务,该软件服务能够同时管理多个MySQL数据库节点,这些MySQL数据库节点通过交换机等网络设备连接同一存储库,也就是:这些MySQL数据库节点共享同一存储库,从而实现了共享存储服务。In some embodiments of the present application, a database access request is an SQL statement for implementing a query operation or an SQL statement for implementing a write operation. The virtual database in this embodiment can be understood as a software service that can simultaneously manage multiple MySQL database nodes, which are connected to the same storage repository through network devices such as switches, that is, these MySQL database nodes share the same storage repository, thereby realizing a shared storage service.
S102、按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点;其中,虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库。S102. Routing a database access request to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same storage repository.
在一些可行的实施方式中,按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点,包括:按照负载均衡策略在虚拟数据库纳管的所有MySQL数据库节点中确定权重最小的MySQL数据库节点;将权重最小的MySQL数据库节点确定为目标数据库节点,并将数据库访问请求路由至目标数据库节点。In some feasible implementations, a database access request is routed to any target database node managed by the virtual database according to a load balancing strategy, including: determining a MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy; determining the MySQL database node with the smallest weight as the target database node, and routing the database access request to the target database node.
在一些可行的实施方式中,任一MySQL数据库节点的权重计算过程包括:计算当前MySQL数据库节点的路由频繁程度;计算当前MySQL数据库节点在当前时刻的负载评 分;将路由频繁程度和负载评分之和,作为当前MySQL数据库节点的权重。当前MySQL数据库节点即:虚拟数据库纳管的任一个节点。In some feasible implementations, the weight calculation process of any MySQL database node includes: calculating the routing frequency of the current MySQL database node; calculating the load evaluation of the current MySQL database node at the current moment; The sum of the routing frequency and the load score is used as the weight of the current MySQL database node. The current MySQL database node is any node managed by the virtual database.
其中,计算当前MySQL数据库节点的路由频繁程度,包括:按照第一公式计算当前MySQL数据库节点的路由频繁程度;第一公式为:Wu=Ci/CS,Wu为MySQL数据库节点i的路由频繁程度,Ci为MySQL数据库节点i的被路由次数,CS为预设的被路由次数最大值。Wherein, calculating the routing frequency of the current MySQL database node includes: calculating the routing frequency of the current MySQL database node according to a first formula; the first formula is: Wu = Ci /C S , Wu is the routing frequency of MySQL database node i, Ci is the number of times MySQL database node i is routed, and C S is a preset maximum number of times of being routed.
其中,计算当前MySQL数据库节点在当前时刻的负载评分,包括:按照第二公式计算当前MySQL数据库节点在当前时刻的负载评分;第二公式为:Wload=LCPU×a+Lm×b+LIO×c,Wload为当前MySQL数据库节点的负载评分,LCPU为当前MySQL数据库节点的CPU负载,Lm为当前MySQL数据库节点的内存负载,LIO为当前MySQL数据库节点的IO负载,a、b、c均为预设系数。一般地,a+b+c=1。Wherein, calculating the load score of the current MySQL database node at the current moment includes: calculating the load score of the current MySQL database node at the current moment according to a second formula; the second formula is: W load = L CPU × a + L m × b + L IO × c, W load is the load score of the current MySQL database node, L CPU is the CPU load of the current MySQL database node, L m is the memory load of the current MySQL database node, L IO is the IO load of the current MySQL database node, and a, b, and c are all preset coefficients. Generally, a+b+c=1.
S103、使目标数据库节点通过访问存储库完成数据库访问请求的处理。S103: Enable the target database node to complete the processing of the database access request by accessing the storage repository.
由于数据库访问请求实际为SQL语句,因此目标数据库节点通过执行SQL语句便可实现:在存储库中查询相应信息或将某些信息写入存储库。Since the database access request is actually an SQL statement, the target database node can query the corresponding information in the repository or write certain information into the repository by executing the SQL statement.
需要说明的是,可以根据用户操作对虚拟数据库的服务配置进行查询、增加、删除或修改;服务配置包括:最大可用连接数、最大空闲连接数、最长等待时间、访问地址、访问端口、虚拟数据库账号及虚拟数据库登录密码。It should be noted that the service configuration of the virtual database can be queried, added, deleted or modified according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
可见,本实施例采用虚拟数据库纳管多个共享同一存储库的MySQL数据库节点,并在接收到数据库访问请求时,按照负载均衡策略可以将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点上,从而使各个MySQL数据库节点都能通过访问存储库完成数据库访问请求的处理。该方案抛弃了数据库主从概念,转而使各个MySQL数据库节点共享同一存储库,由此不仅可避免高并发场景下的同步操作,从而避免同步操作对数据库服务性能的影响,还可以使同一份数据存在一份,以此来保证数据一致性。并且,可以按照负载均衡策略使虚拟数据库纳管的各个数据库节点分担访问请求,从而尽可能发挥每个数据库节点的可用性,从而保证整个数据库访问服务的稳定性、可靠性以及高可用。It can be seen that this embodiment uses a virtual database to manage multiple MySQL database nodes that share the same repository, and when a database access request is received, the database access request can be routed to any target database node managed by the virtual database according to the load balancing strategy, so that each MySQL database node can complete the processing of the database access request by accessing the repository. This solution abandons the master-slave concept of the database and instead enables each MySQL database node to share the same repository, thereby not only avoiding synchronous operations in high-concurrency scenarios, thereby avoiding the impact of synchronous operations on database service performance, but also allowing the same copy of data to exist in one copy, thereby ensuring data consistency. In addition, the various database nodes managed by the virtual database can share access requests according to the load balancing strategy, thereby maximizing the availability of each database node, thereby ensuring the stability, reliability and high availability of the entire database access service.
基于上述实施例,需要说明的是,虚拟数据库可以对其纳管的各个MySQL数据库节点进行监控状态监测。在一些可行的实施方式中,定时采集并记录虚拟数据库纳管的所有MySQL数据库节点的运行状态;若任意MySQL数据库节点故障,则为该MySQL数据库节点添加故障标识。Based on the above embodiment, it should be noted that the virtual database can monitor the status of each MySQL database node it manages. In some feasible implementations, the operating status of all MySQL database nodes managed by the virtual database is regularly collected and recorded; if any MySQL database node fails, a fault mark is added to the MySQL database node.
当然,还可以灵活调整虚拟数据库纳管的MySQL数据库节点,包括在线调整和离线调整两种方式。在线调整即:在虚拟数据库运行过程中,通过配置更新命令对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,得到更新后的节点序列;逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置。离线调整即:若虚拟数据库停止运行,则对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,并重启虚拟数据库。其中,虚拟数据库已纳管节点指:可用于处理请求的节点。也就是说,故障节点或被断开服务的节点不在节点序列中。 Of course, the MySQL database nodes managed by the virtual database can also be flexibly adjusted, including online adjustment and offline adjustment. Online adjustment means: during the operation of the virtual database, the MySQL database nodes in the node sequence managed by the virtual database are added, deleted or modified through the configuration update command to obtain the updated node sequence; each MySQL database node in the updated node sequence is managed and configured one by one. Offline adjustment means: if the virtual database stops running, the MySQL database nodes in the node sequence managed by the virtual database are added, deleted or modified, and the virtual database is restarted. Among them, the managed nodes of the virtual database refer to: nodes that can be used to process requests. In other words, faulty nodes or nodes that have been disconnected from the service are not in the node sequence.
其中,逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置,包括:在更新后的节点序列中确定新增MySQL数据库节点;逐一对新增MySQL数据库节点进行管理配置后,再对更新后的节点序列中的剩余MySQL数据库节点进行管理配置(如:在检查到节点IP、端口等信息有更新时,进行相应信息的更新)。其中,对新增MySQL数据库节点进行管理配置,包括:将新增MySQL数据库节点的IP地址、端口、数据库账号及数据库登录密码配置于虚拟数据库。例如:某一MySQL数据库节点在节点序列中被记录为:IP:端口:username:password。Among them, each MySQL database node in the updated node sequence is managed and configured one by one, including: determining the newly added MySQL database node in the updated node sequence; after managing and configuring the newly added MySQL database node one by one, the remaining MySQL database nodes in the updated node sequence are managed and configured (such as: when the node IP, port and other information are checked to be updated, the corresponding information is updated). Among them, the management and configuration of the newly added MySQL database node includes: configuring the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database. For example: a certain MySQL database node is recorded in the node sequence as: IP: port: username: password.
需要说明的是,优先配置新增节点可以避免服务中断。例如:虚拟数据库原本纳管了节点A和节点B,某一次在线调整时,将节点A、B改成了节点C、D,那么优先配置节点C、D,以使节点C、D能够接受访问请求。如果先使节点A、B停止服务,那么虚拟数据库服务就会中断。It should be noted that configuring newly added nodes first can avoid service interruption. For example, the virtual database originally managed nodes A and B. During an online adjustment, nodes A and B were changed to nodes C and D. Then nodes C and D should be configured first so that they can accept access requests. If nodes A and B are stopped first, the virtual database service will be interrupted.
请参见图2,本实施例为虚拟数据库提供了具体组成结构,包括:虚拟服务、配置中心、虚拟服务、负载均衡、健康检查等模块。其中,借助配置中心模块可以更改、读取虚拟数据库的相关配置信息,包括:基础连接配置和服务配置。Please refer to Figure 2, this embodiment provides a specific structure for the virtual database, including: virtual service, configuration center, virtual service, load balancing, health check and other modules. Among them, the configuration center module can be used to change and read the relevant configuration information of the virtual database, including: basic connection configuration and service configuration.
其中,基础连接配置用于设定虚拟数据库纳管的各个节点,采用ip:port:username:password的形式,可以记录虚拟数据库纳管的各个节点。如:config.dbpool.serverList=10.0.0.1:3306:root:mysqladmin|10.0.0.2:3306:root:mysqladmin,就是某一节点对应的连接配置。The basic connection configuration is used to set each node managed by the virtual database. It uses the form of ip:port:username:password to record each node managed by the virtual database. For example, config.dbpool.serverList = 10.0.0.1:3306:root:mysqladmin|10.0.0.2:3306:root:mysqladmin is the connection configuration corresponding to a certain node.
其中,服务配置包括:最大可用连接数,如:config.dbpool.maxActive=100。最大空闲连接数,如:config.dbpool.maxIdle=20。初始化连接数,如:config.dbpool.initSize=10。最大等待时间,单位ms,如:config.dbpool.maxWait=1000。虚拟数据库地址及端口,如:config.server.url=10.1.1.1:3306。虚拟数据库访问账号及密码,可设置多个,如:config.server.userInfo=root:mysqladmin|test1:test1。当然,还可以设置能够访问虚拟数据库的用户IP,如:config.server.url:x=10.1.1.1:3306:root:mysqladmin、config.server.userInfo:x=root:mysqladmin|test1:test1,x为递增的阿拉伯数字。可见,可根据需要设定多个用户IP访问虚拟数据库。Among them, the service configuration includes: the maximum number of available connections, such as: config.dbpool.maxActive = 100. The maximum number of idle connections, such as: config.dbpool.maxIdle = 20. The number of initialized connections, such as: config.dbpool.initSize = 10. The maximum waiting time, in ms, such as: config.dbpool.maxWait = 1000. The virtual database address and port, such as: config.server.url = 10.1.1.1:3306. Multiple virtual database access accounts and passwords can be set, such as: config.server.userInfo = root:mysqladmin | test1:test1. Of course, you can also set the user IP that can access the virtual database, such as: config.server.url: x = 10.1.1.1:3306:root:mysqladmin, config.server.userInfo: x = root:mysqladmin | test1:test1, x is an increasing Arabic numeral. It can be seen that multiple user IPs can be set to access the virtual database as needed.
基础连接配置和服务配置都可以记录在配置文件中,用户可随时修改配置文件。虚拟数据库服务启动时,配置中心会读取配置文件,并辅助其他模块完成服务初始化。在服务正常启动后,用户也可通过如下命令进行相关配置的查询和修改。例如:采用lssharedbconfig-i configName查询服务配置信息,“–i”为可选参数,不填将返回所有信息,填写将返回特定配置内容。采用chgsharedbconfig-i configName configValue修改服务配置信息,“–i”为可选参数,该参数有两个参数值,第一项为配置名称,第二项为配置项内容。采用refreshsharedbconfig读取配置信息,并重启虚拟服务。Both the basic connection configuration and the service configuration can be recorded in the configuration file, and the user can modify the configuration file at any time. When the virtual database service is started, the configuration center will read the configuration file and assist other modules to complete the service initialization. After the service is started normally, the user can also query and modify the relevant configuration through the following commands. For example: Use lssharedbconfig-i configName to query the service configuration information. "–i" is an optional parameter. If it is not filled in, all information will be returned. If it is filled in, specific configuration content will be returned. Use chgsharedbconfig-i configName configValue to modify the service configuration information. "–i" is an optional parameter. This parameter has two parameter values. The first item is the configuration name, and the second item is the configuration item content. Use refreshsharedbconfig to read the configuration information and restart the virtual service.
需要说明的是,虚拟数据库是底层真实的数据库集群和用户服务请求的中间桥梁。底层的数据库集群对用户是处于黑盒状态的,用户不会直接访问到具体的数据库节点,而是访问虚拟数据库提供的虚拟服务,由此虚拟服务可以将请求路由到具体的数据库节点上。故虚拟服务为用户提供了统一访问入口,能屏蔽掉内部复杂的设计,提升系统简洁性。 It should be noted that the virtual database is the intermediate bridge between the underlying real database cluster and the user service request. The underlying database cluster is in a black box state for users. Users will not directly access specific database nodes, but access the virtual services provided by the virtual database, so that the virtual services can route requests to specific database nodes. Therefore, the virtual service provides users with a unified access entrance, which can shield the complex internal design and improve the simplicity of the system.
负载均衡模块是虚拟服务进行路由的前置功能,此模块可根据设置的路由规则,选择当前数据库集群中最适合的节点供虚拟服务路由。此模块能够保证服务请求能尽可能均匀的落到每个节点上,提供整个系统的负载能力。其中,负载均衡路由规则包括:(1)记录最近1000次请求的节点路由次数,每次路由时统计每个节点的使用率权重分(即路由频繁程度),计算规则为:节点路由次数/总路由次数1000。(2)定时扫描每个节点的基础性能信息,包含CPU使用率、内存使用率、IO使用率,根据这三个信息统计每个节点的服务器负载权重分(即负载评分),计算规则为:CPU使用率*50+内存使用率*30+IO使用率*20。(3)取各节点的使用率权重分与服务器负载权重分的和作为节点最终负载权重,最终负载权重最低的节点将作为此次路由的目标节点。The load balancing module is a pre-function for virtual service routing. This module can select the most suitable node in the current database cluster for virtual service routing according to the set routing rules. This module can ensure that service requests can fall on each node as evenly as possible, providing the load capacity of the entire system. Among them, the load balancing routing rules include: (1) Recording the node routing times of the last 1000 requests, and counting the usage weight score of each node (i.e., routing frequency) each time routing, and the calculation rule is: node routing times/total routing times 1000. (2) Regularly scan the basic performance information of each node, including CPU usage, memory usage, and IO usage, and count the server load weight score (i.e., load score) of each node based on these three pieces of information, and the calculation rule is: CPU usage * 50 + memory usage * 30 + IO usage * 20. (3) Take the sum of the usage weight score and the server load weight score of each node as the final load weight of the node, and the node with the lowest final load weight will be the target node of this routing.
健康检查模块会定期检查每个数据库节点的健康状态,并采集相关数据供负载均衡模块使用。如果某个节点出现故障,则负载均衡模块会识别出此事件,那么该节点不再纳入路由的范畴,直到健康检查模块上报其恢复正常。此模块负责排查系统内的节点故障,并有着节点正常后的自动恢复能力,保障整个系统的高可用性。The health check module will regularly check the health status of each database node and collect relevant data for use by the load balancing module. If a node fails, the load balancing module will identify this event, and the node will no longer be included in the routing scope until the health check module reports that it has returned to normal. This module is responsible for troubleshooting node failures in the system and has the ability to automatically recover after the node is normal, ensuring the high availability of the entire system.
其中,数据库集群中的各个数据库节点(如图2所示的A、B、C、D),使用共享存储作为数据存储空间,可以保证数据存储的一致性。各个数据库节点的实例信息通过配置文件注册在虚拟数据库中。启动虚拟数据库服务,配置中心会读取相关配置文件,读取完毕后,通知健康检查模块进行数据库节点的连接、初始化等操作。健康检查模块依次检查各个数据库节点的连通性后,记录处于健康状态的数据库节点,并通知虚拟服务进行请求的路由。Among them, each database node in the database cluster (A, B, C, D as shown in Figure 2) uses shared storage as data storage space to ensure the consistency of data storage. The instance information of each database node is registered in the virtual database through the configuration file. When the virtual database service is started, the configuration center will read the relevant configuration file. After reading, it will notify the health check module to connect and initialize the database node. After checking the connectivity of each database node in turn, the health check module records the database nodes in a healthy state and notifies the virtual service to route the request.
其中,可以采用停机扩缩容、开机扩缩容方式对数据库集群进行扩容或缩容。The database cluster can be expanded or reduced in capacity by either stopping or starting the system.
停机扩缩容时,虚拟服务处理停机状态,用户可直接修改配置文件,进行数据库节点列表的更改,更改后重启服务,扩缩容即可生效。When scaling up or down, the virtual service handles the downtime state. Users can directly modify the configuration file to change the database node list. After the change, restart the service and the scaling will take effect.
开机扩缩容时,用户可通过chgsharedbconfig命令对数据库节点列表进行增加或删除。配置中心可检测到此命令的结果,而后会通知健康检查模块进行新一轮的节点健康检查以及节点连接初始化。此时,逐个对各数据库节点进行连接初始化,以保证整个过程中有至少一个节点可以处理访问请求,从而保障服务的可用性,以免出现:新请求进入时,找不到可用的数据库节点。When scaling up or down at startup, users can add or delete the database node list through the chgsharedbconfig command. The configuration center can detect the result of this command, and then notify the health check module to perform a new round of node health checks and node connection initialization. At this time, each database node is initialized one by one to ensure that at least one node can process access requests during the entire process, thereby ensuring service availability and avoiding the situation where no available database node can be found when a new request comes in.
请参照图2,服务请求的处理过程包括:请求到达虚拟服务后,虚拟服务借助负载均衡模块尝试获取一个可用的高性能节点,也即:负载均衡模块从当前数据库集群中选取权重分最低的健康节点作为路由节点,并返回给虚拟服务。此时虚拟服务使该路由节点执行SQL语句,以完成服务请求对共享存储的访问。Please refer to Figure 2. The processing of a service request includes: after the request reaches the virtual service, the virtual service tries to obtain an available high-performance node with the help of the load balancing module, that is, the load balancing module selects the healthy node with the lowest weight score from the current database cluster as the routing node and returns it to the virtual service. At this time, the virtual service enables the routing node to execute the SQL statement to complete the service request to access the shared storage.
可见,本实施例为用户请求提供了统一的访问入口,且基于共享存储建立多节点的数据库集群,取消了主从节点的同步机制。一方面可以克服大数据量写入时的数据同步延时,另一方面可以横向拓展节点数量。并且,统一的访问入口,屏蔽了底层集群结构,并借助负载均衡策略使得在高并发、高压力场景下,数据库服务能正常运行,保证了整个服务的稳定性、可靠性以及高可用。 It can be seen that this embodiment provides a unified access entrance for user requests, and establishes a multi-node database cluster based on shared storage, canceling the synchronization mechanism of the master-slave node. On the one hand, it can overcome the data synchronization delay when writing large amounts of data, and on the other hand, it can expand the number of nodes horizontally. In addition, the unified access entrance shields the underlying cluster structure, and with the help of load balancing strategies, the database service can run normally in high concurrency and high pressure scenarios, ensuring the stability, reliability and high availability of the entire service.
下面对本申请实施例提供的一种数据库访问装置进行介绍,下文描述的一种数据库访问装置与上文描述的一种数据库访问方法可以相互参照。A database access device provided in an embodiment of the present application is introduced below. The database access device described below and the database access method described above can be referenced to each other.
参见图3所示,本申请实施例公开了一种数据库访问装置,应用于虚拟数据库,包括:As shown in FIG3 , the embodiment of the present application discloses a database access device, which is applied to a virtual database, including:
接收模块301,用于接收数据库访问请求;Receiving module 301, used for receiving a database access request;
路由模块302,用于按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点;其中,虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;The routing module 302 is used to route the database access request to any target database node managed by the virtual database according to the load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same storage repository;
处理模块303,用于使目标数据库节点通过访问存储库完成数据库访问请求的处理。The processing module 303 is used to enable the target database node to complete the processing of the database access request by accessing the storage repository.
在一些可行的实施方式中,路由模块具体用于:In some feasible implementations, the routing module is specifically used to:
按照负载均衡策略在虚拟数据库纳管的所有MySQL数据库节点中确定权重最小的MySQL数据库节点;Determine the MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy;
将权重最小的MySQL数据库节点确定为目标数据库节点,并将数据库访问请求路由至目标数据库节点。The MySQL database node with the smallest weight is determined as the target database node, and the database access request is routed to the target database node.
在一些可行的实施方式中,还包括:In some feasible implementations, the following further includes:
健康监测模块,用于定时采集并记录虚拟数据库纳管的所有MySQL数据库节点的运行状态;若任意MySQL数据库节点故障,则为该MySQL数据库节点添加故障标识。The health monitoring module is used to periodically collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault mark is added to the MySQL database node.
在一些可行的实施方式中,还包括:In some feasible implementations, the following further includes:
节点配置在线更新模块,用于在虚拟数据库运行过程中,通过配置更新命令对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,得到更新后的节点序列;逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置。The node configuration online update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through the configuration update command during the operation of the virtual database to obtain the updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
在一些可行的实施方式中,节点配置在线更新模块具体用于:在更新后的节点序列中确定新增MySQL数据库节点;逐一对新增MySQL数据库节点进行管理配置后,再对更新后的节点序列中的剩余MySQL数据库节点进行管理配置。In some feasible implementations, the node configuration online update module is specifically used to: determine the newly added MySQL database nodes in the updated node sequence; manage and configure the newly added MySQL database nodes one by one, and then manage and configure the remaining MySQL database nodes in the updated node sequence.
在一些可行的实施方式中,节点配置在线更新模块具体用于:将新增MySQL数据库节点的IP地址、端口、数据库账号及数据库登录密码配置于虚拟数据库。In some feasible implementations, the node configuration online update module is specifically used to: configure the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database.
在一些可行的实施方式中,还包括:In some feasible implementations, the following further includes:
服务配置操作模块,用于根据用户操作对虚拟数据库的服务配置进行查询、增加、删除或修改;服务配置包括:最大可用连接数、最大空闲连接数、最长等待时间、访问地址、访问端口、虚拟数据库账号及虚拟数据库登录密码。The service configuration operation module is used to query, add, delete or modify the service configuration of the virtual database according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
在一些可行的实施方式中,还包括:In some feasible implementations, the following further includes:
节点配置离线更新模块,用于若虚拟数据库停止运行,则对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,并重启虚拟数据库。The node configuration offline update module is used to add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database if the virtual database stops running, and restart the virtual database.
其中,关于本实施例中各个模块、单元更加具体的工作过程可以参考前述实施例中公开的相应内容,在此不再进行赘述。Among them, for more specific working processes of each module and unit in this embodiment, reference can be made to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.
可见,本实施例提供了一种数据库访问装置,能够使各个MySQL数据库节点共享同一存储库,避免同步操作对数据库服务性能的影响,还能保证数据存储的一致性以及整个数据库访问服务的稳定性、可靠性以及高可用。 It can be seen that this embodiment provides a database access device that enables various MySQL database nodes to share the same storage repository, avoids the impact of synchronous operations on database service performance, and ensures the consistency of data storage and the stability, reliability and high availability of the entire database access service.
下面对本申请实施例提供的一种数据库访问装置进行介绍,下文描述的一种数据库访问装置与上文描述的一种数据库访问方法可以相互参照。A database access device provided in an embodiment of the present application is introduced below. The database access device described below and the database access method described above can be referenced to each other.
本申请实施例公开了一种数据库访问系统,包括:前述实施例公开的虚拟数据库、多个MySQL数据库节点以及存储库。具体可参照图2,图2中的共享存储即存储库。The embodiment of the present application discloses a database access system, including: the virtual database disclosed in the above embodiment, multiple MySQL database nodes and a storage repository. Specifically, please refer to Figure 2, where the shared storage in Figure 2 is the storage repository.
在一些可行的实施方式中,虚拟数据库用于:接收数据库访问请求;按照负载均衡策略将数据库访问请求路由至虚拟数据库纳管的任一目标数据库节点;其中,虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;使目标数据库节点通过访问存储库完成数据库访问请求的处理。In some feasible implementations, the virtual database is used to: receive database access requests; route the database access requests to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same repository; and enable the target database node to complete the processing of the database access request by accessing the repository.
在一些可行的实施方式中,虚拟数据库用于:按照负载均衡策略在虚拟数据库纳管的所有MySQL数据库节点中确定权重最小的MySQL数据库节点;将权重最小的MySQL数据库节点确定为目标数据库节点,并将数据库访问请求路由至目标数据库节点。In some feasible implementations, the virtual database is used to: determine the MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy; determine the MySQL database node with the smallest weight as the target database node, and route the database access request to the target database node.
在一些可行的实施方式中,虚拟数据库用于:计算当前MySQL数据库节点的路由频繁程度;计算当前MySQL数据库节点在当前时刻的负载评分;将路由频繁程度和负载评分之和,作为当前MySQL数据库节点的权重。In some feasible implementations, the virtual database is used to: calculate the routing frequency of the current MySQL database node; calculate the load score of the current MySQL database node at the current moment; and use the sum of the routing frequency and the load score as the weight of the current MySQL database node.
在一些可行的实施方式中,虚拟数据库用于:按照第一公式计算当前MySQL数据库节点的路由频繁程度;第一公式为:Wu=Ci/CS,Wu为MySQL数据库节点i的路由频繁程度,Ci为MySQL数据库节点i的被路由次数,CS为预设的被路由次数最大值。In some feasible implementations, the virtual database is used to: calculate the routing frequency of the current MySQL database node according to a first formula; the first formula is: Wu = Ci /C S , Wu is the routing frequency of MySQL database node i, Ci is the number of times MySQL database node i is routed, and C S is the preset maximum number of times of being routed.
在一些可行的实施方式中,虚拟数据库用于:按照第二公式计算当前MySQL数据库节点在当前时刻的负载评分;第二公式为:Wload=LCPU×a+Lm×b+LIO×c,Wload为当前MySQL数据库节点的负载评分,LCPU为当前MySQL数据库节点的CPU负载,Lm为当前MySQL数据库节点的内存负载,LIO为当前MySQL数据库节点的IO负载,a、b、c均为预设系数。In some feasible implementations, the virtual database is used to: calculate the load score of the current MySQL database node at the current moment according to the second formula; the second formula is: W load =L CPU ×a+L m ×b+L IO ×c, W load is the load score of the current MySQL database node, L CPU is the CPU load of the current MySQL database node, L m is the memory load of the current MySQL database node, L IO is the IO load of the current MySQL database node, and a, b, and c are all preset coefficients.
在一些可行的实施方式中,虚拟数据库用于:定时采集并记录虚拟数据库纳管的所有MySQL数据库节点的运行状态;若任意MySQL数据库节点故障,则为该MySQL数据库节点添加故障标识。In some feasible implementations, the virtual database is used to: regularly collect and record the operating status of all MySQL database nodes managed by the virtual database; if any MySQL database node fails, a fault identifier is added to the MySQL database node.
在一些可行的实施方式中,虚拟数据库用于:在虚拟数据库运行过程中,通过配置更新命令对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,得到更新后的节点序列;逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置。In some feasible implementations, the virtual database is used to: during the operation of the virtual database, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database through configuration update commands to obtain an updated node sequence; and manage and configure each MySQL database node in the updated node sequence one by one.
在一些可行的实施方式中,虚拟数据库用于:在更新后的节点序列中确定新增MySQL数据库节点;逐一对新增MySQL数据库节点进行管理配置后,再对更新后的节点序列中的剩余MySQL数据库节点进行管理配置。In some feasible implementations, the virtual database is used to: determine newly added MySQL database nodes in the updated node sequence; manage and configure the newly added MySQL database nodes one by one, and then manage and configure the remaining MySQL database nodes in the updated node sequence.
在一些可行的实施方式中,虚拟数据库用于:将新增MySQL数据库节点的IP地址、端口、数据库账号及数据库登录密码配置于虚拟数据库。In some feasible implementations, the virtual database is used to configure the IP address, port, database account and database login password of the newly added MySQL database node in the virtual database.
在一些可行的实施方式中,虚拟数据库用于:根据用户操作对虚拟数据库的服务配置进行查询、增加、删除或修改;服务配置包括:最大可用连接数、最大空闲连接数、最长等待时间、访问地址、访问端口、虚拟数据库账号及虚拟数据库登录密码。 In some feasible implementations, the virtual database is used to query, add, delete or modify the service configuration of the virtual database according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the maximum waiting time, the access address, the access port, the virtual database account and the virtual database login password.
在一些可行的实施方式中,虚拟数据库用于:若虚拟数据库停止运行,则对虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,并重启虚拟数据库。In some feasible implementations, the virtual database is used to: if the virtual database stops running, add, delete or modify the MySQL database nodes in the node sequence managed by the virtual database, and restart the virtual database.
下面对本申请实施例提供的一种电子设备进行介绍,下文描述的一种电子设备与上文描述的一种数据库访问方法及装置可以相互参照。An electronic device provided in an embodiment of the present application is introduced below. The electronic device described below and the database access method and device described above can be referenced to each other.
参见图4所示,本申请实施例公开了一种电子设备,包括:As shown in FIG4 , an embodiment of the present application discloses an electronic device, including:
存储器401,用于保存计算机程序;Memory 401, used for storing computer programs;
处理器402,用于执行所述计算机程序,以实现上述任意实施例公开的方法。The processor 402 is used to execute the computer program to implement the method disclosed in any of the above embodiments.
进一步的,本申请实施例还提供了一种服务器来作为上述电子设备。该服务器,具体可以包括:至少一个处理器、至少一个存储器、电源、通信接口、输入输出接口和通信总线。其中,所述存储器用于存储计算机程序,所述计算机程序由所述处理器加载并执行,以实现前述任一实施例公开的数据库访问方法中的相关步骤。Furthermore, an embodiment of the present application also provides a server as the above-mentioned electronic device. The server may specifically include: at least one processor, at least one memory, a power supply, a communication interface, an input/output interface, and a communication bus. The memory is used to store a computer program, and the computer program is loaded and executed by the processor to implement the relevant steps in the database access method disclosed in any of the above-mentioned embodiments.
本实施例中,电源用于为服务器上的各硬件设备提供工作电压;通信接口能够为服务器创建与外界设备之间的数据传输通道,其所遵循的通信协议是能够适用于本申请技术方案的任意通信协议,在此不对其进行具体限定;输入输出接口,用于获取外界输入数据或向外界输出数据,其具体的接口类型可以根据具体应用需要进行选取,在此不进行具体限定。In this embodiment, the power supply is used to provide working voltage for each hardware device on the server; the communication interface can create a data transmission channel between the server and external devices, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
另外,存储器作为资源存储的载体,可以是只读存储器、随机存储器、磁盘或者光盘等,其上所存储的资源包括操作系统、计算机程序及数据等,存储方式可以是短暂存储或者永久存储。In addition, the memory as a carrier for resource storage can be a read-only memory, random access memory, disk or CD, etc. The resources stored thereon include operating system, computer programs and data, etc. The storage method can be temporary storage or permanent storage.
其中,操作系统用于管理与控制服务器上的各硬件设备以及计算机程序,以实现处理器对存储器中数据的运算与处理,其可以是Windows Server、Netware、Unix、Linux等。计算机程序除了包括能够用于完成前述任一实施例公开的数据库访问方法的计算机程序之外,还可以进一步包括能够用于完成其他特定工作的计算机程序。数据除了可以包括虚拟机等数据外,还可以包括虚拟机的开发商信息等数据。The operating system is used to manage and control the hardware devices and computer programs on the server to realize the operation and processing of the data in the memory by the processor, which can be Windows Server, Netware, Unix, Linux, etc. In addition to computer programs that can be used to complete the database access method disclosed in any of the aforementioned embodiments, computer programs can also further include computer programs that can be used to complete other specific tasks. In addition to data such as virtual machines, data can also include data such as the developer information of the virtual machine.
进一步的,本申请实施例还提供了一种终端来作为上述电子设备。该终端具体可以包括但不限于智能手机、平板电脑、笔记本电脑或台式电脑等。Furthermore, the embodiment of the present application also provides a terminal as the above electronic device. The terminal may specifically include but is not limited to a smart phone, a tablet computer, a laptop computer or a desktop computer.
通常,本实施例中的终端包括有:处理器和存储器。Generally, the terminal in this embodiment includes: a processor and a memory.
其中,处理器可以包括一个或多个处理核心,比如4核心处理器、8核心处理器等。处理器可以采用DSP(Digital Signal Processing,数字信号处理)、FPGA(Field-Programmable Gate Array,现场可编程门阵列)、PLA(Programmable Logic Array,可编程逻辑阵列)中的至少一种硬件形式来实现。处理器也可以包括主处理器和协处理器,主处理器是用于对在唤醒状态下的数据进行处理的处理器,也称CPU(Central Processing Unit,中央处理器);协处理器是用于对在待机状态下的数据进行处理的低功耗处理器。在一些实施例中,处理器可以在集成有GPU(Graphics Processing Unit,图像处理器),GPU用于负责显示屏所需要显示的内容的渲染和绘制。一些实施例中,处理器还可以包括AI(Artificial Intelligence,人工智能)处理器,该AI处理器用于处理有关机器学习的计算操作。 Among them, the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
存储器可以包括一个或多个计算机非易失性可读存储介质,该计算机非易失性可读存储介质可以是非暂态的。存储器还可包括高速随机存取存储器,以及非易失性存储器,比如一个或多个磁盘存储设备、闪存存储设备。本实施例中,存储器至少用于存储以下计算机程序,其中,该计算机程序被处理器加载并执行之后,能够实现前述任一实施例公开的由终端侧执行的数据库访问方法中的相关步骤。另外,存储器所存储的资源还可以包括操作系统和数据等,存储方式可以是短暂存储或者永久存储。其中,操作系统可以包括Windows、Unix、Linux等。数据可以包括但不限于应用程序的更新信息。The memory may include one or more computer non-volatile readable storage media, which may be non-transitory. The memory may also include high-speed random access memory, and non-volatile memory, such as one or more disk storage devices, flash memory storage devices. In this embodiment, the memory is at least used to store the following computer program, wherein, after the computer program is loaded and executed by the processor, it can implement the relevant steps in the database access method performed by the terminal side disclosed in any of the aforementioned embodiments. In addition, the resources stored in the memory may also include an operating system and data, etc., and the storage method may be temporary storage or permanent storage. Among them, the operating system may include Windows, Unix, Linux, etc. The data may include, but is not limited to, update information of the application.
在一些实施例中,终端还可包括有显示屏、输入输出接口、通信接口、传感器、电源以及通信总线。In some embodiments, the terminal may also include a display screen, an input and output interface, a communication interface, a sensor, a power supply, and a communication bus.
下面对本申请实施例提供的一种非易失性可读存储介质进行介绍,下文描述的一种非易失性可读存储介质与上文描述的一种数据库访问方法、装置及设备可以相互参照。A non-volatile readable storage medium provided in an embodiment of the present application is introduced below. The non-volatile readable storage medium described below and the database access method, apparatus and device described above can be referenced to each other.
一种非易失性可读存储介质,用于保存计算机程序,其中,所述计算机程序被处理器执行时实现前述实施例公开的数据库访问方法。A non-volatile readable storage medium is used to store a computer program, wherein the computer program implements the database access method disclosed in the above embodiment when executed by a processor.
本申请涉及的“第一”、“第二”、“第三”、“第四”等(如果存在)是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的实施例能够以除了在这里图示或描述的内容以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法或设备固有的其它步骤或单元。The "first", "second", "third", "fourth", etc. (if any) referred to in this application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods or devices.
需要说明的是,在本申请中涉及“第一”、“第二”等的描述仅用于描述目的,而不能理解为指示或暗示其相对重要性或者隐含指明所指示的技术特征的数量。由此,限定有“第一”、“第二”的特征可以明示或者隐含地包括至少一个该特征。另外,各个实施例之间的技术方案可以相互结合,但是必须是以本领域普通技术人员能够实现为基础,当技术方案的结合出现相互矛盾或无法实现时应当认为这种技术方案的结合不存在,也不在本申请要求的保护范围之内。It should be noted that the descriptions involving "first", "second", etc. in this application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in this field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
本说明书中各个实施例采用递进的方式描述,每个实施例重点说明的都是与其它实施例的不同之处,各个实施例之间相同或相似部分互相参见即可。The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
结合本文中所公开的实施例描述的方法或算法的步骤可以直接用硬件、处理器执行的软件模块,或者二者的结合来实施。软件模块可以置于随机存储器(RAM)、内存、只读存储器(ROM)、电可编程ROM、电可擦除可编程ROM、寄存器、硬盘、可移动磁盘、CD-ROM、或技术领域内所公知的任意其它形式的非易失性可读存储介质中。The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of non-volatile readable storage medium known in the art.
本文中应用了具体个例对本申请的原理及实施方式进行了阐述,以上实施例的说明只是用于帮助理解本申请的方法及其核心思想;同时,对于本领域的一般技术人员,依据本申请的思想,在具体实施方式及应用范围上均会有改变之处,综上所述,本说明书内容不应理解为对本申请的限制。 Specific examples are used herein to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation methods and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims (20)

  1. 一种数据库访问方法,其特征在于,应用于虚拟数据库,包括:A database access method, characterized in that it is applied to a virtual database and comprises:
    接收数据库访问请求;receiving a database access request;
    按照负载均衡策略将所述数据库访问请求路由至所述虚拟数据库纳管的任一目标数据库节点;其中,所述虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;Routing the database access request to any target database node managed by the virtual database according to the load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same storage repository;
    使所述目标数据库节点通过访问所述存储库完成所述数据库访问请求的处理。The target database node completes processing of the database access request by accessing the storage repository.
  2. 根据权利要求1所述的方法,其特征在于,所述按照负载均衡策略将所述数据库访问请求路由至所述虚拟数据库纳管的任一目标数据库节点,包括:The method according to claim 1, characterized in that routing the database access request to any target database node managed by the virtual database according to the load balancing strategy comprises:
    按照所述负载均衡策略在所述虚拟数据库纳管的所有MySQL数据库节点中确定权重最小的MySQL数据库节点;Determine the MySQL database node with the smallest weight among all MySQL database nodes managed by the virtual database according to the load balancing strategy;
    将权重最小的MySQL数据库节点确定为所述目标数据库节点,并将所述数据库访问请求路由至所述目标数据库节点。The MySQL database node with the smallest weight is determined as the target database node, and the database access request is routed to the target database node.
  3. 根据权利要求2所述的方法,其特征在于,任一MySQL数据库节点的权重计算过程包括:The method according to claim 2 is characterized in that the weight calculation process of any MySQL database node includes:
    计算当前MySQL数据库节点的路由频繁程度;Calculate the routing frequency of the current MySQL database node;
    计算当前MySQL数据库节点在当前时刻的负载评分;Calculate the load score of the current MySQL database node at the current moment;
    将所述路由频繁程度和所述负载评分之和,作为当前MySQL数据库节点的权重。The sum of the routing frequency and the load score is used as the weight of the current MySQL database node.
  4. 根据权利要求3所述的方法,其特征在于,所述计算当前MySQL数据库节点的路由频繁程度,包括:The method according to claim 3, characterized in that the calculating the routing frequency of the current MySQL database node comprises:
    按照第一公式计算当前MySQL数据库节点的路由频繁程度;所述第一公式为:Wu=Ci/CS,Wu为MySQL数据库节点i的路由频繁程度,Ci为MySQL数据库节点i的被路由次数,CS为预设的被路由次数最大值。The routing frequency of the current MySQL database node is calculated according to the first formula; the first formula is: Wu = Ci /C S , Wu is the routing frequency of MySQL database node i, Ci is the number of times MySQL database node i is routed, and C S is the preset maximum number of times of being routed.
  5. 根据权利要求3所述的方法,其特征在于,所述计算当前MySQL数据库节点在当前时刻的负载评分,包括:The method according to claim 3, characterized in that the calculating the load score of the current MySQL database node at the current moment comprises:
    按照第二公式计算当前MySQL数据库节点在当前时刻的负载评分;所述第二公式为:Wload=LCPU×a+Lm×b+LIO×c,Wload为当前MySQL数据库节点的负载评分,LCPU为当前MySQL数据库节点的CPU负载,Lm为当前MySQL数据库节点的内存负载,LIO为当前MySQL数据库节点的IO负载,a、b、c均为预设系数。The load score of the current MySQL database node at the current moment is calculated according to the second formula; the second formula is: W load =L CPU ×a+L m ×b+L IO ×c, W load is the load score of the current MySQL database node, L CPU is the CPU load of the current MySQL database node, L m is the memory load of the current MySQL database node, L IO is the IO load of the current MySQL database node, and a, b, and c are all preset coefficients.
  6. 根据权利要求1至5任一项所述的方法,其特征在于,还包括:The method according to any one of claims 1 to 5, further comprising:
    定时采集并记录所述虚拟数据库纳管的所有MySQL数据库节点的运行状态;Regularly collect and record the operating status of all MySQL database nodes managed by the virtual database;
    若任意MySQL数据库节点故障,则为该MySQL数据库节点添加故障标识。If any MySQL database node fails, a failure flag is added to the MySQL database node.
  7. 根据权利要求1至5任一项所述的方法,其特征在于,还包括:The method according to any one of claims 1 to 5, further comprising:
    在所述虚拟数据库运行过程中,通过配置更新命令对所述虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,得到更新后的节点序列;During the operation of the virtual database, adding, deleting or modifying the MySQL database nodes in the node sequence managed by the virtual database by configuring an update command to obtain an updated node sequence;
    逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置。Manage and configure each MySQL database node in the updated node sequence one by one.
  8. 根据权利要求7所述的方法,其特征在于,所述逐一对更新后的节点序列中的各MySQL数据库节点进行管理配置,包括: The method according to claim 7, characterized in that the step of managing and configuring each MySQL database node in the updated node sequence one by one comprises:
    在更新后的节点序列中确定新增MySQL数据库节点;Determine the newly added MySQL database node in the updated node sequence;
    逐一对所述新增MySQL数据库节点进行管理配置后,再对更新后的节点序列中的剩余MySQL数据库节点进行管理配置。After managing and configuring the newly added MySQL database nodes one by one, manage and configure the remaining MySQL database nodes in the updated node sequence.
  9. 根据权利要求8所述的方法,其特征在于,对所述新增MySQL数据库节点进行管理配置,包括:The method according to claim 8, characterized in that managing and configuring the newly added MySQL database node comprises:
    将所述新增MySQL数据库节点的IP地址、端口、数据库账号及数据库登录密码配置于所述虚拟数据库。The IP address, port, database account and database login password of the newly added MySQL database node are configured in the virtual database.
  10. 根据权利要求1至5任一项所述的方法,其特征在于,还包括:The method according to any one of claims 1 to 5, further comprising:
    根据用户操作对所述虚拟数据库的服务配置进行查询、增加、删除或修改;所述服务配置包括:最大可用连接数、最大空闲连接数、最长等待时间、访问地址、访问端口、虚拟数据库账号及虚拟数据库登录密码。The service configuration of the virtual database is queried, added, deleted or modified according to user operations; the service configuration includes: the maximum number of available connections, the maximum number of idle connections, the longest waiting time, the access address, the access port, the virtual database account and the virtual database login password.
  11. 根据权利要求1至5任一项所述的方法,其特征在于,所述虚拟数据库提供具体组成结构,所述具体组成结构至少包括虚拟服务模块、配置中心模块、虚拟服务模块、负载均衡模块以及健康检查模块中的一种;其中,所述配置中心模块允许更改、读取虚拟服务库中的相关配置信息,所述配置信息至少包括基础连接配置以及服务配置。According to the method described in any one of claims 1 to 5, it is characterized in that the virtual database provides a specific composition structure, and the specific composition structure includes at least one of a virtual service module, a configuration center module, a virtual service module, a load balancing module and a health check module; wherein the configuration center module allows the modification and reading of relevant configuration information in the virtual service library, and the configuration information includes at least basic connection configuration and service configuration.
  12. 根据权利要求12所述的方法,其特征在于,所述基础连接配置用于设定虚拟数据库纳管的各个节点,并采用ip:port:username:password的形式记录虚拟数据库纳管的各个节点。The method according to claim 12 is characterized in that the basic connection configuration is used to set each node managed by the virtual database, and each node managed by the virtual database is recorded in the form of ip:port:username:password.
  13. 根据权利要求11所述的方法,其特征在于,所述基础连接配置与所述服务配置记录于配置文件中,所述方法还包括:The method according to claim 11, characterized in that the basic connection configuration and the service configuration are recorded in a configuration file, and the method further comprises:
    响应于虚拟数据库服务启动,配置中心模块读取配置文件,并辅助其他虚拟服务模块、虚拟服务模块、负载均衡模块以及健康检查模块完成服务初始化。In response to the virtual database service being started, the configuration center module reads the configuration file and assists other virtual service modules, virtual service modules, load balancing modules, and health check modules to complete service initialization.
  14. 根据权利要求13所述的方法,其特征在于,还包括:The method according to claim 13, further comprising:
    在服务正常启动后,采用lssharedbconfig-i configName查询服务配置信息,所述-i为可选参数,不填将返回所有信息,填写将返回特定配置内容;After the service is started normally, use lssharedbconfig -i configName to query the service configuration information. The -i parameter is optional. If it is not filled in, all information will be returned. If it is filled in, specific configuration content will be returned.
    采用chgsharedbconfig-i configName configValue修改服务配置信息,所述-i为可选参数,该参数有两个参数值,第一项为配置名称,第二项为配置项内容;Use chgsharedbconfig -i configName configValue to modify the service configuration information. The -i parameter is an optional parameter with two parameter values. The first one is the configuration name and the second one is the configuration item content.
    采用refreshsharedbconfig读取配置信息,并重启虚拟服务模块。Use refreshsharedbconfig to read the configuration information and restart the virtual service module.
  15. 根据权利要求11所述的方法,其特征在于,所述负载均衡模块为虚拟服务模块进行路由的前置功能,配置有路由规则,所述路由规则至少包括以下中的一种:The method according to claim 11 is characterized in that the load balancing module is a pre-function for the virtual service module to perform routing, and is configured with routing rules, and the routing rules include at least one of the following:
    (1)记录最近1000次请求的节点路由次数,每次路由时统计每个节点的使用率权重分,计算规则为:节点路由次数/总路由次数1000;(1) Record the node routing times of the last 1000 requests, and count the usage weight of each node each time the routing is performed. The calculation rule is: node routing times/total routing times 1000;
    (2)定时扫描每个节点的基础性能信息,包含CPU使用率、内存使用率、IO使用率,根据这三个信息统计每个节点的服务器负载权重分,计算规则为:CPU使用率*50+内存使用率*30+IO使用率*20;(2) Regularly scan the basic performance information of each node, including CPU usage, memory usage, and IO usage. Based on these three pieces of information, the server load weight of each node is calculated. The calculation rule is: CPU usage*50+memory usage*30+IO usage*20;
    (3)取各节点的使用率权重分与服务器负载权重分的和作为节点最终负载权重,最终负载权重最低的节点将作为此次路由的目标节点。(3) The sum of the usage weight of each node and the server load weight is taken as the final load weight of the node. The node with the lowest final load weight will be used as the target node for this routing.
  16. 根据权利要求1至5任一项所述的方法,其特征在于,还包括: The method according to any one of claims 1 to 5, further comprising:
    若所述虚拟数据库停止运行,则对所述虚拟数据库已纳管的节点序列中的MySQL数据库节点进行增加、删除或修改,并重启所述虚拟数据库。If the virtual database stops running, the MySQL database nodes in the node sequence managed by the virtual database are added, deleted or modified, and the virtual database is restarted.
  17. 一种数据库访问装置,其特征在于,应用于虚拟数据库,包括:A database access device, characterized in that it is applied to a virtual database and comprises:
    接收模块,用于接收数据库访问请求;A receiving module, used for receiving a database access request;
    路由模块,用于按照负载均衡策略将所述数据库访问请求路由至所述虚拟数据库纳管的任一目标数据库节点;其中,所述虚拟数据库纳管多个MySQL数据库节点,且所有MySQL数据库节点共享同一存储库;A routing module, used for routing the database access request to any target database node managed by the virtual database according to a load balancing strategy; wherein the virtual database manages multiple MySQL database nodes, and all MySQL database nodes share the same storage repository;
    处理模块,用于使所述目标数据库节点通过访问所述存储库完成所述数据库访问请求的处理。The processing module is used to enable the target database node to complete the processing of the database access request by accessing the storage repository.
  18. 一种数据库访问系统,其特征在于,包括:如权利要求1至16任一项所述的虚拟数据库、多个MySQL数据库节点以及存储库。A database access system, characterized by comprising: a virtual database as claimed in any one of claims 1 to 16, a plurality of MySQL database nodes and a storage repository.
  19. 一种电子设备,其特征在于,包括:An electronic device, comprising:
    存储器,用于存储计算机程序;Memory for storing computer programs;
    处理器,用于执行所述计算机程序,以实现如权利要求1至16任一项所述的方法。A processor, configured to execute the computer program to implement the method according to any one of claims 1 to 16.
  20. 一种非易失性可读存储介质,其特征在于,用于保存计算机程序,其中,所述计算机程序被处理器执行时实现如权利要求1至16任一项所述的方法。 A non-volatile readable storage medium, characterized in that it is used to store a computer program, wherein the computer program, when executed by a processor, implements the method according to any one of claims 1 to 16.
PCT/CN2023/115587 2022-11-14 2023-08-29 Database access method, apparatus and system, and device and readable storage medium WO2024103902A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202211417410.7 2022-11-14
CN202211417410.7A CN115470303B (en) 2022-11-14 2022-11-14 Database access method, device, system, equipment and readable storage medium

Publications (1)

Publication Number Publication Date
WO2024103902A1 true WO2024103902A1 (en) 2024-05-23

Family

ID=84338237

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/115587 WO2024103902A1 (en) 2022-11-14 2023-08-29 Database access method, apparatus and system, and device and readable storage medium

Country Status (2)

Country Link
CN (1) CN115470303B (en)
WO (1) WO2024103902A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115470303B (en) * 2022-11-14 2023-03-03 苏州浪潮智能科技有限公司 Database access method, device, system, equipment and readable storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103905530A (en) * 2014-03-11 2014-07-02 浪潮集团山东通用软件有限公司 High-performance global load balance distributed database data routing method
CN107066575A (en) * 2017-04-11 2017-08-18 广东亿迅科技有限公司 Method and its system for realizing data base read-write load balancing
CN110727709A (en) * 2019-10-10 2020-01-24 北京优炫软件股份有限公司 Cluster database system
CN113377866A (en) * 2021-06-10 2021-09-10 全球能源互联网研究院有限公司 Load balancing method and device for virtualized database proxy service
CN115470303A (en) * 2022-11-14 2022-12-13 苏州浪潮智能科技有限公司 Database access method, device, system, equipment and readable storage medium

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US10528586B2 (en) * 2016-12-20 2020-01-07 International Business Machines Corporation Database process with virtual nodes
US20190065258A1 (en) * 2017-08-30 2019-02-28 ScalArc Inc. Automatic Provisioning of Load Balancing as Part of Database as a Service
CN110225087A (en) * 2019-05-08 2019-09-10 平安科技(深圳)有限公司 Cloud access method, device and storage medium based on global load balancing
CN114564530A (en) * 2022-02-25 2022-05-31 苏州浪潮智能科技有限公司 Database access method, device, equipment and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103905530A (en) * 2014-03-11 2014-07-02 浪潮集团山东通用软件有限公司 High-performance global load balance distributed database data routing method
CN107066575A (en) * 2017-04-11 2017-08-18 广东亿迅科技有限公司 Method and its system for realizing data base read-write load balancing
CN110727709A (en) * 2019-10-10 2020-01-24 北京优炫软件股份有限公司 Cluster database system
CN113377866A (en) * 2021-06-10 2021-09-10 全球能源互联网研究院有限公司 Load balancing method and device for virtualized database proxy service
CN115470303A (en) * 2022-11-14 2022-12-13 苏州浪潮智能科技有限公司 Database access method, device, system, equipment and readable storage medium

Also Published As

Publication number Publication date
CN115470303A (en) 2022-12-13
CN115470303B (en) 2023-03-03

Similar Documents

Publication Publication Date Title
US11533231B2 (en) Configuration and management of scalable global private networks
US11943104B2 (en) Application migration system
CN109328335B (en) Intelligent configuration discovery techniques
US9979596B2 (en) Configuration discovery service data visualization
US9934098B2 (en) Automatic serial order starting of resource groups on failover systems based on resource group usage prediction
US9817721B1 (en) High availability management techniques for cluster resources
CN106464532B (en) Network state management method and equipment
US11729077B2 (en) Configuration and management of scalable global private networks
US20180004777A1 (en) Data distribution across nodes of a distributed database base system
WO2024103902A1 (en) Database access method, apparatus and system, and device and readable storage medium
CN108319623A (en) A kind of fast resampling method, apparatus and data-base cluster
US11336528B2 (en) Configuration and management of scalable global private networks
WO2021108652A1 (en) Configuration and management of scalable global private networks
US10326826B1 (en) Migrating an on premises workload to a web services platform
US20170206027A1 (en) Management system and management method of computer system
US8621260B1 (en) Site-level sub-cluster dependencies
US10999169B1 (en) Configuration and management of scalable global private networks
WO2023029485A1 (en) Data processing method and apparatus, computer device, and computer-readable storage medium
CN105391790A (en) Database high-availability method similar to RAC One Node
CN115225642A (en) Elastic load balancing method and system of super-fusion system
US10365934B1 (en) Determining and reporting impaired conditions in a multi-tenant web services environment
US20200348868A1 (en) Online conversion of storage layout
BR112021015456A2 (en) INCREASING PARTITION PROCESSING CAPACITY FOR AN ABNORMAL EVENT
US11483381B1 (en) Distributing cloud migration
CN117119058B (en) Storage node optimization method in Ceph distributed storage cluster and related equipment