Database operation method and device applied to micro-service gray release scene

By intercepting and parsing SQL statements in the microservice grayscale release scenario, rewriting and replacing them, and routing them to the specified database table, the problem of high data maintenance costs after grayscale is solved and lower operation and maintenance costs are achieved.

CN119690941APending Publication Date: 2025-03-25CHINA TELECOM CLOUD TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411696620.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-25
Publication Date
2025-03-25

AI Technical Summary

Technical Problem

In the microservice grayscale release scenario, the data maintenance cost after grayscale is relatively high.

Method used

After the grayscale service is released, the database operation requests carrying SQL statements are intercepted, the SQL statements are parsed to build an abstract syntax tree, and the SQL statements are rewritten and replaced based on pre-fetched SQL rules, obtain the rewritten and replaced SQL statements, and then route them to the specified data table of the baseline database or grayscale database.

Benefits of technology

By supporting rule parsing and custom SQL rewriting, the data maintenance cost after grayscale is reduced and the burden on development and operation and maintenance personnel is reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119690941A_ABST
    Figure CN119690941A_ABST
Patent Text Reader

Abstract

The embodiment of the invention provides a database operation method and device applied to a micro-service gray release scene, and the method comprises the steps: intercepting a database operation request carrying an SQL statement when a database operation needs to be carried out after a gray service is released; wherein the database operation request is a gray level request; analyzing the SQL statement to construct an abstract syntax tree, and rewriting and replacing the SQL statement based on an SQL rule obtained from a configuration center in advance and the abstract syntax tree to obtain a rewritten and replaced SQL statement; routing the rewritten and replaced SQL statement to a specified data table in a database corresponding to the database operation request; wherein the specified database corresponding to the database operation request is a baseline database or a grayscale database, so that the data maintenance cost after grayscale can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of microservice technology, and in particular to a database operation method applied in a microservice grayscale release scenario and a database operation device applied in a microservice grayscale release scenario. Background Art

[0002] At present, the patent with application number 202211257146.5 discloses a method for implementing full-link grayscale, which includes responding to a user request, obtaining an environment tag carried in the user request, wherein the environment tag includes a first environment tag or a second environment tag, and the second environment tag is a grayscale version tag corresponding to the first environment tag; according to the environment tag, routing the user request to a first database corresponding to the first environment tag or a second database corresponding to the second environment tag.

[0003] Although this method can realize the grayscale release of microservices, since it directly routes the grayscale data to the shadow data table, it at least has the problem of high data maintenance cost after grayscale. Summary of the invention

[0004] The embodiment of the present application provides a database operation method and device applied to a microservice grayscale release scenario to solve the problem of high data maintenance cost after grayscale in the prior art.

[0005] An embodiment of the present application discloses a database operation method applied to a microservice grayscale release scenario, comprising: when a database operation is required after a grayscale service is released, intercepting a database operation request carrying an SQL statement; wherein the database operation request is a grayscale request; parsing the SQL statement to construct an abstract syntax tree, and rewriting and replacing the SQL statement based on SQL rules and the abstract syntax tree pre-acquired from a configuration center to obtain a rewritten and replaced SQL statement; routing the rewritten and replaced SQL statement to a specified data table in a database corresponding to the database operation request; wherein the specified database corresponding to the database operation request is a baseline database or a grayscale database.

[0006] In a possible embodiment, before intercepting a database operation request carrying an SQL statement, the database operation method includes: after the grayscale service is released, obtaining a microservice request through JAVA Agent technology; based on the characteristics in the microservice request, determining the environment tag corresponding to the microservice request, and establishing an independent connection to the database table corresponding to the environment tag according to the environment tag.

[0007] In one possible embodiment, the rewritten and replaced SQL statement is routed to a designated database corresponding to the database operation request, including: based on routing rules and environment tags pre-acquired from a configuration center, routing the rewritten and replaced SQL statement to a designated data table in the database corresponding to the database operation request.

[0008] In one possible embodiment, based on routing rules and environment tags pre-acquired from a configuration center, the rewritten and replaced SQL statements are routed to a designated database corresponding to a database operation request, including: in a data table where routing rules are used to indicate that the rewritten and replaced SQL statements are routed to a baseline database, based on routing rules and environment tags, the rewritten and replaced SQL statements are routed to a data table in the baseline database to achieve incremental synchronization.

[0009] In one possible embodiment, based on routing rules and environment tags pre-acquired from a configuration center, the rewritten and replaced SQL statements are routed to a designated database corresponding to a database operation request, including: in a data shadow table where the routing rules are used to indicate that the rewritten and replaced SQL statements are routed to a baseline database, based on the routing rules and environment tags, the rewritten and replaced SQL statements are routed to the data shadow table of the baseline database.

[0010] In a possible embodiment, based on routing rules and environment tags pre-acquired from a configuration center, the rewritten and replaced SQL statements are routed to a designated database corresponding to a database operation request, including: in a data grayscale table in which the routing rules are used to indicate that the rewritten and replaced SQL statements are routed to a grayscale database, based on the routing rules and environment tags, the rewritten and replaced SQL statements are routed to the data grayscale table in the grayscale database.

[0011] The embodiment of the present application also provides a database operation device applied to a microservice grayscale release scenario, including: an interception module, which is used to intercept a database operation request carrying an SQL statement when a database operation is required after the grayscale service is released; wherein the database operation request is a grayscale request; a parsing module, which is used to parse the SQL statement to construct an abstract syntax tree, and rewrite and replace the SQL statement based on the SQL rules and abstract syntax tree pre-acquired from the configuration center to obtain the rewritten and replaced SQL statement; a routing module, which is used to route the rewritten and replaced SQL statement to a specified data table in a database corresponding to the database operation request; wherein the specified database corresponding to the database operation request is a baseline database or a grayscale database.

[0012] In a possible embodiment, the database operation device includes: an acquisition module, which is used to obtain the microservice request through JAVA Agent technology before intercepting the database operation request carrying the SQL statement and after the grayscale service is released; a determination module, which is used to determine the environment tag corresponding to the microservice request based on the characteristics in the microservice request, and establish an independent connection to the database table corresponding to the environment tag according to the environment tag.

[0013] The present application also provides a storage medium in an embodiment, on which a computer program is stored. When the computer program is executed by a processor, the method described in the embodiment of the present application is executed.

[0014] The present application also provides an electronic device in an embodiment, comprising: a processor, a memory and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor and the memory communicate via the bus, and when the machine-readable instructions are executed by the processor, the method described in the embodiment of the present application is performed.

[0015] The present application also provides a computer program product. When the computer program product is run on a computer, it enables the computer to execute the method described in the embodiments of the present application.

[0016] The embodiments of the present application include the following advantages:

[0017] The embodiment of the present application provides a database operation method and device applied to a microservice grayscale release scenario, by intercepting a database operation request carrying an SQL statement when a database operation is required after the grayscale service is released, wherein the database operation request is a grayscale request, and parsing the SQL statement to build an abstract syntax tree, and rewriting and replacing the SQL statement based on the SQL rules and abstract syntax tree pre-acquired from the configuration center to obtain the rewritten and replaced SQL statement, and routing the rewritten and replaced SQL statement to a designated database corresponding to the database operation request, wherein the designated database corresponding to the database operation request is a baseline database or a grayscale database. Compared with the prior art, since the present application can support rule parsing and data operation SQL statements can be custom rewritten and replaced, the data flow can be customized based on the consideration of subsequent data revisions, thereby reducing the data maintenance cost after grayscale.

[0018] In order to make the above-mentioned objectives, features and advantages to be achieved by the embodiments of the present application more obvious and understandable, the following specifically cites preferred embodiments and describes them in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.

[0020] Figure 1 A structural diagram of an existing microservice grayscale release scenario is shown;

[0021] Figure 2 A schematic diagram of the structure of a microservice grayscale release scenario provided by an embodiment of the present application is shown;

[0022] Figure 3 A flowchart of a database operation method applied to a microservice grayscale release scenario provided by an embodiment of the present application is shown;

[0023] Figure 4 A structural block diagram of a database operation device applied to a microservice grayscale release scenario provided by an embodiment of the present application is shown;

[0024] Figure 5 A block diagram of an electronic device provided by an embodiment of the present application is shown;

[0025] Figure 6 It is a schematic diagram of a readable medium provided in an embodiment of the present application. DETAILED DESCRIPTION

[0026] The following will clearly and completely describe the technical solutions of various embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.

[0027] A microservice system usually contains multiple microservices. Significant changes to some businesses or services will affect the full-link calling process of the system and the user experience of the entire product. At this time, the service release will introduce a gray release strategy, and the new version of the software will be gradually pushed to a small number of users to test the stability and performance of the new version in a real environment. Through gray release, the software development team can gradually expand the audience of the new version within the control range, discover problems and fix them in time, ensure safe production and achieve project iteration. How to control the impact of problems in gray and avoid polluting the system steady state is the key to the gray release process.

[0028] At present, the common method is to add grayscale traffic to features and route it to grayscale services. At the same time, the database operations involved in the grayscale services are performed in an independently built database grayscale instance. The overall process of the existing solution is as follows: Figure 1 In scenarios where grayscale data is important, especially when data operations in business processes are complex, this approach has its own limitations: Both grayscale and non-grayscale data are real business data that need to be retained and adapted to database changes. In addition to requiring additional machine resources to support instance construction, the grayscale solution for independent database grayscale instances also requires configuration and maintenance of database instance connections in the service code.

[0029] In addition, in the related technology, there is a solution to route SQL requests to the grayscale database within the application, but it cannot adapt to the data revision requirements of complex business changes and rollback processes.

[0030] In addition, in addition to the patent with application number 202211257146.5 that discloses a method for implementing full-link grayscale, the existing patent with application number 202310417535.8 discloses a method for database grayscale switching, but this method only switches the database connection based on the added grayscale identifier, so it cannot achieve flexible operation to adapt to multiple scenarios.

[0031] Based on this, an embodiment of the present application provides a database operation method and device applied to a microservice grayscale release scenario, by intercepting a database operation request carrying an SQL statement when a database operation is required after the grayscale service is released, wherein the database operation request is a grayscale request, and parsing the SQL statement to build an abstract syntax tree, and rewriting and replacing the SQL statement based on the SQL rules and abstract syntax tree pre-acquired from the configuration center to obtain the rewritten and replaced SQL statement, and routing the rewritten and replaced SQL statement to a designated database corresponding to the database operation request, wherein the designated database corresponding to the database operation request is a baseline database or a grayscale database. Compared with the prior art, since the present application can support rule parsing and data operation SQL statements can be custom rewritten and replaced, the data flow can be customized based on the consideration of subsequent data revisions, thereby reducing the data maintenance cost after grayscale.

[0032] In order to better understand the above technical solution, exemplary embodiments of the present invention will be described in more detail below with reference to the accompanying drawings. Although exemplary embodiments of the present invention are shown in the accompanying drawings, it should be understood that the present invention can be implemented in various forms and should not be limited by the embodiments described herein. On the contrary, these embodiments are provided to enable a clearer and more thorough understanding of the present invention and to fully convey the scope of the present invention to those skilled in the art.

[0033] In order to facilitate understanding of the embodiments of the present application, the terms involved in the present application are explained as follows:

[0034] "SQL (Structured Query Language)": It is a standard language for managing and operating relational databases. It is widely used in operations such as data query, update, insert, delete, and database schema creation and modification. In addition, SQL is widely used in data query, data operation, data definition, and data control.

[0035] "Java Agent": It is a special Java application that can intercept and modify the bytecode of other Java applications, thereby dynamically changing the behavior of the application at runtime. Java Agent is often used in scenarios such as performance monitoring, code coverage testing, logging, and memory analysis. The implementation of Java Agent is based on the Java Instrumentation API, which provides powerful bytecode manipulation capabilities. In addition, it refers to a mechanism that is loaded into the Java virtual machine in the form of an "agent" when the Java virtual machine is started and can interact with programs running on the Java virtual machine. Through Java Agent, developers can dynamically monitor, analyze, and even modify executing Java programs while the application is running.

[0036] "Druid": It is an open source, high-performance relational database connection pool. It provides a manageable and efficient way for Java applications to maintain database connections, thereby helping applications to access databases more efficiently and reliably. In addition, it aims to address the shortcomings of existing database connection pools in terms of performance, monitoring, and scalability, and provides rich configuration options and powerful monitoring capabilities. Druid can be used in a variety of Java applications, especially those scenarios that require efficient management and monitoring of database connections.

[0037] "Java Database Connectivity (JDBC)": It is a standard API provided by the Java platform for interacting with databases. Through JDBC, Java applications can connect to various relational databases (such as MySQL, Oracle, PostgreSQL, etc.), execute SQL statements, and process query results. JDBC provides a unified set of interfaces and classes that allow developers to write database-independent code. In other words, it is an API used by the Java language to interact with databases. It provides a standard method that enables Java applications to communicate and interact with different relational databases.

[0038] "Data shadow table": It is a table created in the database. It is a copy of the actual business data table and is usually used for data isolation, testing or backup purposes. The shadow table can be a complete copy of the source table or contain part of the source table's data.

[0039] "Data grayscale table": It is a technology used in databases to implement grayscale release (also known as canary release or progressive release). Grayscale release means gradually directing some users or traffic to the new version when the new version is launched, so as to test and verify it without affecting most users. If there is a problem with the new version, it can be rolled back quickly to reduce the impact on users.

[0040] See also Figure 2 , Figure 2 A schematic diagram of the structure of a microservice grayscale release scenario provided by an embodiment of the present application is shown. Figure 2 As shown, compared to Figure 1 In the existing scenario shown, a first data isolation module is added to the baseline microservice application module, a data shadow table is added to the baseline database, and a second data isolation module and a parser are added to the grayscale microservice application module.

[0041] Based on the above structure, before the grayscale service is released, the data shadow table and data grayscale table of the grayscale environment are established on the existing database instance. In addition, for the original baseline service and grayscale service, the bytecode enhancement technology is used to inject the data isolation module. After the service is enhanced and released, the service responds to the upstream request, and based on the characteristics in the request information, it determines whether the request belongs to the baseline environment or the grayscale environment. According to the environment label, the data isolation module obtains the corresponding database table in the environment and establishes a connection independently. When the service needs to perform database operations, the data isolation module injects the database request and label into the built-in parser, and the parser rewrites the original SQL according to the custom operation rules. Among them, the operation rules can define the SQL dimensions involved in the request, such as database, data table, table structure, data value, etc. The revised one or more SQL requests generated will be routed to the database instance by the data isolation module and act on the corresponding database table of the baseline or grayscale environment.

[0042] See also Figure 3 , Figure 3A flowchart of a database operation method applied to a microservice grayscale release scenario provided by an embodiment of the present application is shown. It should be understood that the database operation method can be executed by a database operation device in a microservice grayscale release scenario, and the specific device of the database operation device can be set according to actual needs, and the embodiment of the present application is not limited to this. For example, the database operation device can be a computer, or a server, etc. Specifically, the database operation method includes:

[0043] Step S310: When a database operation is required after the grayscale service is released, a database operation request carrying an SQL statement is intercepted, wherein the database operation request is a grayscale request.

[0044] Specifically, after the grayscale service is released, the microservice request is obtained through JAVA Agent technology, and the environment tag corresponding to the microservice request is determined based on the characteristics in the microservice request, and an independent connection to the database table corresponding to the environment tag is established according to the environment tag. And, when database operations are required after the grayscale service is released, database operation requests carrying SQL statements are intercepted.

[0045] For example, a new data shadow table related to the grayscale environment is added to the existing database instance, and the data shadow table corresponds to the library table structure change of the grayscale release, and the grayscale environment and the original production environment (i.e., the baseline environment) can be distinguished by name. In addition, for the services changed in the grayscale, the JAVA Agent bytecode enhancement technology is used to inject the first data isolation module and the second data isolation module.

[0046] Furthermore, the first data isolation module can obtain the microservice request, determine the environment tag corresponding to the microservice request as the baseline environment tag based on the characteristics in the microservice request, and establish an independent connection with the data table in the baseline database according to the baseline environment tag. Furthermore, when the database operation request passes through the service connection driver, the first data isolation module intercepts the database operation request carrying the SQL statement.

[0047] Furthermore, the second data isolation module can obtain the microservice request, determine that the environment tag corresponding to the microservice request is a grayscale environment tag based on the features in the microservice request, and establish an independent connection to the data table corresponding to the grayscale environment tag according to the grayscale environment tag. The data table corresponding to the grayscale environment tag can be a data table in the baseline database, a data shadow table in the baseline database, or a data grayscale table in the grayscale database. Furthermore, when the database operation request is driven by the service connection, the second data isolation module intercepts the database operation request carrying the SQL statement.

[0048] It should be understood that the specific process of determining the environment tag corresponding to the microservice request based on the characteristics in the microservice request can be set according to actual needs, and the embodiments of the present application are not limited to this.

[0049] For example, the first data isolation module may determine that the environment to which the microservice request belongs is the baseline environment based on information such as a user ID, region, or tag carried in the microservice request, and mark the microservice request with the baseline environment tag;

[0050] For another example, the second data isolation module may determine that the environment to which the microservice request belongs is a grayscale environment based on information such as a user ID, region, or tag carried in the microservice request, and mark the microservice request with a grayscale environment tag.

[0051] Step S320, parse the SQL statement to construct an abstract syntax tree, and rewrite and replace the SQL statement based on the SQL rules and abstract syntax tree pre-acquired from the configuration center to obtain a rewritten and replaced SQL statement.

[0052] Specifically, after intercepting the database operation request, the second data isolation module will pull the database table information, pre-set routing rules and pre-configured SQL rules of the grayscale environment from the configuration center. The database table information of the grayscale environment includes the address information of the database related to the grayscale environment and the address information of the data table related to the grayscale environment. For example, the address information of the data shadow table in the baseline database; another example, the address information of the data grayscale table in the grayscale database; the pre-set routing rules can represent the rules for routing data to that data table in that database; the pre-configured SQL rules can be the rewriting rules and replacement rules of the SQL statement.

[0053] Thus, the second data isolation module can parse the SQL statement in the database operation request to construct an abstract syntax tree. The abstract syntax tree includes multiple nodes. And, based on the SQL rules and abstract syntax tree obtained in advance from the configuration center, the SQL statement in the database operation request is rewritten and replaced to obtain the rewritten and replaced SQL statement.

[0054] Step S330: Routing the rewritten and replaced SQL statement to a designated data table in a database corresponding to the database operation request, wherein the designated database corresponding to the database operation request is a baseline database or a grayscale database.

[0055] Specifically, based on the routing rules and environment tags pre-acquired from the configuration center, the rewritten and replaced SQL statements are routed to a specified data table in the database corresponding to the database operation request.

[0056] That is, the parser will build an abstract syntax tree according to the custom SQL rules, mark the SQL characters, and rewrite and replace the SQL according to the matching SQL rules. After the replacement is completed, the second data isolation module will execute the rewritten and replaced SQL statements, and the data will act on one or more database tables in multiple environments.

[0057] To facilitate understanding of step S330, a specific embodiment is used to describe it below.

[0058] Optionally, the first data isolation module may route the rewritten and replaced SQL statements to a data table in the baseline database based on routing rules and baseline environment labels pre-acquired from the configuration center.

[0059] Optionally, in a routing rule for indicating that the rewritten and replaced SQL statements are routed to a data table of a baseline database, the second data isolation module may route the rewritten and replaced SQL statements to a data table of the baseline database based on the routing rule and the environment tag to achieve incremental synchronization.

[0060] Optionally, in the routing rule for instructing to route the rewritten and replaced SQL statement to the data shadow table of the baseline database, the rewritten and replaced SQL statement is routed to the data shadow table of the baseline database based on the routing rule and the environment tag.

[0061] Optionally, in the routing rule for indicating that the rewritten and replaced SQL statement is routed to the data grayscale table of the grayscale database, the rewritten and replaced SQL statement is routed to the data grayscale table of the grayscale database based on the routing rule and the environment tag.

[0062] Therefore, with the help of the above-mentioned technical solution, this application adopts bytecode injection technology to add a data isolation module to the service, so that the service judges the label according to the request characteristics and rewrites SQL on demand based on the rules. This solution can flexibly route the database operations involved in the grayscale traffic to the database table in the baseline or grayscale environment, while being compatible with changes in database tables or businesses. In the grayscale release scenario, it reduces the possible manpower costs of development and operation and maintenance personnel, including but not limited to the establishment and maintenance of grayscale database instances, adaptation of project source code, revision of grayscale data or dirty data, and configuration of service call links.

[0063] In addition, the present application also uses JAVA Agent technology to inject data into the data isolation module, thereby eliminating the need for code parsing and reducing the intrusiveness to the engineering code.

[0064] In addition, this application also uses an SQL parser based on an abstract syntax tree to rewrite SQL according to environment tags and configuration rules, thereby controlling the flow of data to achieve an isolation effect. This method can flexibly adapt to the data isolation requirements of different scenarios in a grayscale release environment and reduce the labor cost of environment configuration and data revision.

[0065] In order to facilitate understanding of the technical solution of the present application, two specific embodiments are described below.

[0066] First embodiment

[0067] A grayscale database or data shadow table of the grayscale environment is established on the database instance, and the database table name is marked with a suffix to mark the environment. For example, the data shadow table in the baseline database can be marked as a grayscale environment;

[0068] In addition, JAVA Agent technology is used in the change service, and the data isolation module is injected into the baseline service and the grayscale service in an attach manner to enhance the service;

[0069] And, the second data isolation module will obtain the database table information, pre-set routing rules and pre-configured SQL rules of the grayscale environment from the Nacos configuration center;

[0070] And, when the application is changed to receive a database operation request, the second data isolation module intercepts the database operation request, obtains the grayscale environment tag according to the request header of the database operation request, and marks the grayscale environment in the thread memory;

[0071] And, the request is driven by the Druid connection pool, triggering the parser, which obtains the SQL statement and builds an abstract syntax tree. And, the parser obtains the SQL rule (tag=gray, table_tag=gray) from the second data isolation module, modifies the table name tableA of the SQL statement to the gray table tableA_gray, establishes a gray database database_gray connection, executes the SQL statement to the table tableA_gray under database_gray, and implements the gray traffic data operation in the gray shadow database table.

[0072] Second embodiment

[0073] A grayscale database or data shadow table of the grayscale environment is established on the database instance, and the database table name is marked with a suffix to mark the environment. For example, the data shadow table in the baseline database can be marked as a grayscale environment;

[0074] In addition, JAVA Agent technology is used in the change service, and the data isolation module is injected into the baseline service and the grayscale service in an attach manner to enhance the service;

[0075] And, the second data isolation module will regularly access the http interface of the remote configuration center to obtain the database table information, pre-set routing rules and pre-configured SQL rules of the grayscale environment;

[0076] Also, when the change application receives a database operation request, the second data isolation module intercepts the database operation request, determines the source region of the request according to the parameter region of the database operation request, obtains the grayscale environment tag, and records the grayscale environment tag and the request ID in the shared memory.

[0077] And, the request is driven by the JDBC database, triggering the parser, which obtains the SQL statement and builds the abstract syntax tree. In addition, the parser obtains the SQL rule (tag=gray, table_tag=gray, attribute_tag=gray) from the second data isolation module, copies the SQL statement and modifies the table name tableA to the gray table tableA_gray, the field attribute to attribute_gray, and executes the SQL statement to the table tableA and tableA_gray at the same time, realizing the incremental synchronization of data under database changes.

[0078] It should be understood that the above-mentioned database operation method applied to the microservice grayscale release scenario is only exemplary, and those skilled in the art can make various modifications based on the above-mentioned method, and the modified scheme also belongs to the protection scope of this application.

[0079] See also Figure 4 , Figure 4 The structural block diagram of a database operation device 400 applied to a microservice grayscale release scenario provided by an embodiment of the present application is shown. Specifically, the database operation device 400 is applied to a task scheduling platform in a task scheduling system, and the task scheduling system includes a control platform, a task scheduling platform and multiple hosts, and each of the multiple hosts has a long connection relationship with the control platform; the database operation device 400 includes:

[0080] The interception module 410 is used to intercept database operation requests carrying SQL statements when database operations are required after the grayscale service is released; wherein the database operation request is a grayscale request;

[0081] The parsing module 420 is used to parse the SQL statement to construct an abstract syntax tree, and rewrite and replace the SQL statement based on the SQL rules and abstract syntax tree pre-acquired from the configuration center to obtain the rewritten and replaced SQL statement;

[0082] The routing module 430 is used to route the rewritten and replaced SQL statement to a designated data table in a database corresponding to the database operation request; wherein the designated database corresponding to the database operation request is a baseline database or a grayscale database.

[0083] In a possible embodiment, the database operation device 400 includes:

[0084] An acquisition module (not shown) is used to acquire microservice requests through JAVA Agent technology before intercepting database operation requests carrying SQL statements and after the grayscale service is released;

[0085] A determination module (not shown) is used to determine an environment tag corresponding to the microservice request based on the features in the microservice request, and to establish an independent connection to a database table corresponding to the environment tag according to the environment tag.

[0086] In a possible embodiment, the routing module 430 is specifically configured to route the rewritten and replaced SQL statement to a specified data table in a database corresponding to the database operation request based on routing rules and environment tags pre-acquired from the configuration center.

[0087] In one possible embodiment, the routing module 430 is specifically used to route the rewritten and replaced SQL statements to the data table of the baseline database based on the routing rules and environment tags in order to achieve incremental synchronization when the routing rules are used to indicate that the rewritten and replaced SQL statements are routed to the data table of the baseline database.

[0088] In one possible embodiment, the routing module 430 is specifically used to route the rewritten and replaced SQL statements to the data shadow table of the baseline database based on the routing rules and environment tags when the routing rules are used to indicate that the rewritten and replaced SQL statements are routed to the data shadow table of the baseline database.

[0089] In one possible embodiment, the routing module 430 is specifically used to route the rewritten and replaced SQL statements to the data grayscale table of the grayscale database based on the routing rules and environment tags when the routing rules are used to indicate that the rewritten and replaced SQL statements are routed to the data grayscale table of the grayscale database.

[0090] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0091] In addition, the present application also provides an electronic device, such as Figure 5 As shown, it includes a processor 501, a communication interface 502, a memory 503 and a communication bus 504, wherein the processor 501, the communication interface 502, and the memory 503 communicate with each other through the communication bus 504.

[0092] Memory 503, used for storing computer programs;

[0093] The processor 501 is used to execute the program stored in the memory 503, and implements the following steps:

[0094] When database operations are required after the grayscale service is released, database operation requests carrying SQL statements are intercepted; database operation requests are grayscale requests;

[0095] Parse the SQL statement to construct an abstract syntax tree, and rewrite and replace the SQL statement based on the SQL rules and abstract syntax tree obtained in advance from the configuration center to obtain the rewritten and replaced SQL statement;

[0096] The rewritten and replaced SQL statement is routed to a specified data table in a database corresponding to the database operation request; wherein the specified database corresponding to the database operation request is a baseline database or a grayscale database.

[0097] The communication bus mentioned in the above terminal can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0098] The communication interface is used for communication between the above terminal and other devices.

[0099] The memory may include a random access memory (RAM) or a non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.

[0100] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.

[0101] like Figure 6 As shown, in another embodiment provided by the present invention, a readable medium 601 is also provided, in which instructions are stored, and when the instructions are executed on a computer, the computer executes the database operation method applied to the microservice grayscale release scenario described in the above embodiment. The readable medium refers to a computer-readable storage medium.

[0102] In another embodiment provided by the present invention, a computer program product including instructions is also provided. When the computer is run on a computer, the computer executes the database operation method described in the above embodiment applied to the microservice grayscale release scenario.

[0103] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system described above can refer to the corresponding process in the aforementioned method, and will not be elaborated here.

[0104] It should be noted that each embodiment in this specification is described in a progressive manner, and each embodiment focuses on the differences from other embodiments, and the same or similar parts between the embodiments can be referred to each other. For the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.

[0105] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0106] In several embodiments provided by the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.

[0107] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.

[0108] If the function is implemented in the form of a software function module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or the part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a disk or an optical disk. It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variation thereof are intended to encompass non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements, but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus. In the absence of further limitations, an element defined by the phrase "comprising a ..." does not exclude the presence of additional identical elements in the process, method, article, or apparatus that includes the element.

[0109] The above description is only a preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application. It should be noted that similar numbers and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.

[0110] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A database operation method applied to a microservice grayscale release scenario, characterized in that: include: When a database operation is required after the grayscale service is released, intercept the database operation request carrying the SQL statement; wherein the database operation request is a grayscale request; Parsing the SQL statement to construct an abstract syntax tree, and rewriting and replacing the SQL statement based on the SQL rule pre-acquired from the configuration center and the abstract syntax tree to obtain a rewritten and replaced SQL statement; The rewritten and replaced SQL statement is routed to a designated data table in a database corresponding to the database operation request; wherein the designated database corresponding to the database operation request is a baseline database or a grayscale database.

2. The database operation method according to claim 1, characterized in that: Before intercepting the database operation request carrying the SQL statement, the database operation method includes: After the grayscale service is released, the microservice request is obtained through JAVA Agent technology; Based on the features in the microservice request, an environment tag corresponding to the microservice request is determined, and according to the environment tag, an independent connection to a database table corresponding to the environment tag is established.

3. The database operation method according to claim 2, characterized in that: The step of routing the rewritten and replaced SQL statement to a designated database corresponding to the database operation request includes: Based on the routing rules and the environment tags pre-acquired from the configuration center, the rewritten and replaced SQL statements are routed to a designated data table in the database corresponding to the database operation request.

4. The database operation method according to claim 3, characterized in that: The step of routing the rewritten and replaced SQL statement to a designated database corresponding to the database operation request based on the routing rules and the environment tag pre-acquired from the configuration center includes: In the routing rule for instructing to route the rewritten and replaced SQL statements to the data table of the baseline database, based on the routing rule and the environment tag, the rewritten and replaced SQL statements are routed to the data table of the baseline database to achieve incremental synchronization.

5. The database operation method according to claim 3, characterized in that: The step of routing the rewritten and replaced SQL statement to a designated database corresponding to the database operation request based on the routing rules and the environment tag pre-acquired from the configuration center includes: When the routing rule is used to instruct to route the rewritten and replaced SQL statement to the data shadow table of the baseline database, the rewritten and replaced SQL statement is routed to the data shadow table of the baseline database based on the routing rule and the environment tag.

6. The database operation method according to claim 3, characterized in that: The step of routing the rewritten and replaced SQL statement to a designated database corresponding to the database operation request based on the routing rules and the environment tag pre-acquired from the configuration center includes: In the case where the routing rule is used to instruct to route the rewritten and replaced SQL statement to the data grayscale table of the grayscale database, the rewritten and replaced SQL statement is routed to the data grayscale table of the grayscale database based on the routing rule and the environment tag.

7. A database operation device applied to a microservice grayscale release scenario, characterized in that: include: An interception module, used to intercept database operation requests carrying SQL statements when database operations are required after the grayscale service is released; wherein the database operation request is a grayscale request; A parsing module, used to parse the SQL statement to construct an abstract syntax tree, and rewrite and replace the SQL statement based on the SQL rules pre-acquired from the configuration center and the abstract syntax tree to obtain a rewritten and replaced SQL statement; A routing module is used to route the rewritten and replaced SQL statement to a specified data table in a database corresponding to the database operation request; wherein the specified database corresponding to the database operation request is a baseline database or a grayscale database.

8. The database operation device according to claim 7, characterized in that: The database operation device comprises: An acquisition module, used to acquire microservice requests through JAVAAgent technology before intercepting the database operation request carrying the SQL statement and after the grayscale service is released; The determination module is used to determine the environment tag corresponding to the microservice request based on the characteristics in the microservice request, and establish an independent connection to the database table corresponding to the environment tag according to the environment tag.

9. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; The memory is used to store computer programs; The processor is used to implement the database operation method applied to the microservice grayscale release scenario as described in any one of claims 1 to 6 when executing the program stored in the memory.

10. A readable medium having instructions stored thereon, which, when executed by one or more processors, enables the processors to execute the database operation method applied to the microservice grayscale release scenario as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method, system and device for realizing full-link gray scale

    CN116303333A

  • Method and system for database gray scale switching and electronic equipment

    CN116595075A