Database operation method and device, computer equipment and storage medium
By extracting and processing key-value database operation statements and identifying the target database object, the operation of a privatized relational database is realized, and the problem of strongly coupled access logic migration in software operation services is solved, and development efficiency is improved.
Patent Information
- Application Number
- CN202310498785.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-05
- Publication Date
- 2024-11-05
AI Technical Summary
In the process of privatization and deployment of software operation services, the existing technology requires the modification of strongly coupled key-value database access logic, which affects development efficiency.
By obtaining access requests for privatized relational databases, extracting key-value-to-database operation statements, and identifying the target database object based on these statements, performing database operation processing, thereby migrating the access logic of key-to-database to relational databases, avoiding additional Development.
It improves the development efficiency of the privatized deployment process, realizes compatibility with relational databases, and reduces the need for code modification.
Smart Images

Figure CN118897867A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a database operation method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] With the development of computer technology and storage technology, Software as a Service (SaaS) has emerged. It refers to a new form of software service for users. It does not require users to install software products on their own computers or servers. Software operation services can generally ensure strong consistency and high availability of data through databases, such as key-value databases, and support horizontal scaling well, stably supporting the development of software operation service business.
[0003] However, when the business code of the software operation service is strongly coupled with the access logic of the key-value database, when the private version of the software operation service is deployed in the relational database, it is necessary to modify the business code of this part that is strongly coupled with the key-value database, which affects the development efficiency of the SaaS private deployment. Summary of the invention
[0004] Based on this, it is necessary to provide a database operation method, apparatus, computer equipment, computer-readable storage medium and computer program product that can effectively improve development efficiency in response to the above technical problems.
[0005] In a first aspect, the present application provides a database operation method. The method comprises:
[0006] Obtaining an access request for a privatized relational database, wherein the relational database is compatible with a key-value pair data format in a key-value pair database;
[0007] Extracting a key-value pair database operation statement in the access request;
[0008] Based on the key-value database operation statement, identifying a target database object in the key-value data in the privatized relational database;
[0009] Database operation processing is performed based on the target database object.
[0010] In a second aspect, the present application also provides a database operation device. The device comprises:
[0011] A request acquisition module, used to acquire an access request for a privatized relational database, wherein the relational database is compatible with a key-value pair data format in a key-value pair database;
[0012] A statement extraction module, used to extract key-value pair database operation statements in the access request;
[0013] An object identification module, used to identify a target database object in the key-value pair data in the privatized relational database based on the key-value pair database operation statement;
[0014] The database operation module is used to perform database operation processing based on the target database object.
[0015] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0016] Obtaining an access request for a privatized relational database, wherein the relational database is compatible with a key-value pair data format in a key-value pair database;
[0017] Extracting a key-value pair database operation statement in the access request;
[0018] Based on the key-value database operation statement, identifying a target database object in the key-value data in the privatized relational database;
[0019] Database operation processing is performed based on the target database object.
[0020] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0021] Obtaining an access request for a privatized relational database, wherein the relational database is compatible with a key-value pair data format in a key-value pair database;
[0022] Extracting a key-value pair database operation statement in the access request;
[0023] Based on the key-value database operation statement, identifying a target database object in the key-value data in the privatized relational database;
[0024] Database operation processing is performed based on the target database object.
[0025] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0026] Obtaining an access request for a privatized relational database, wherein the relational database is compatible with a key-value pair data format in a key-value pair database;
[0027] Extracting a key-value pair database operation statement in the access request;
[0028] Based on the key-value database operation statement, identifying a target database object in the key-value data in the privatized relational database;
[0029] Database operation processing is performed based on the target database object.
[0030] The above-mentioned database operation method, apparatus, computer equipment, storage medium and computer program product directly extract the key-value database operation statement in the access request after obtaining the access request for the privatized relational database, and then identify the target database object in the key-value pair data compatible with the stored storage in the relational database based on the key-value database operation statement, so as to perform database operation processing based on the identified target database object. That is, the present application can use the key-value database operation statement to operate the privatized relational database, thereby directly migrating the access logic strongly coupled with the key-value database to the privatized version without the need for additional development, thereby effectively improving the development efficiency of the privatization process. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 An application environment diagram of a database operation method in an embodiment;
[0032] Figure 2 A schematic diagram of a flow chart of a database operation method in one embodiment;
[0033] Figure 3 A schematic diagram of the architecture of a software operation service in one embodiment;
[0034] Figure 4 A schematic diagram of a specific structure of a software operation service in an embodiment;
[0035] Figure 5 A schematic diagram of a data storage format in one embodiment;
[0036] Figure 6 A schematic diagram of a library and table partitioning process in an embodiment;
[0037] Figure 7 A schematic diagram of access logic for software operation services and private deployment in one embodiment;
[0038] Figure 8 A schematic diagram of a flow chart of a database operation method in another embodiment;
[0039] Fig. 9 is a structural block diagram of a database operation device in one embodiment;
[0040] Fig.10 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0041] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0042] In this article, it is important to understand that the terms involved are:
[0043] Software operation service: It refers to a new form of software service for users. It does not require users to install software products on their own computers or servers.
[0044] Private deployment: It is equivalent to building a server, database and other infrastructure for a specific customer, and then deploying mature software in an independent environment. The core attribute of privatization is customer-specific resources.
[0045] The database operation method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the privately deployed server 104 through the network. The private data storage system can store the data that the server 104 needs to process, and the data storage system is implemented in the form of a relational database. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other servers. When the user of the terminal 102 needs to operate the data stored in the data storage system, an access request for the operation data can be sent to the server 104, and the server 104 obtains the access request for the private relational database, and the relational database is compatible with the key-value pair data format in the key-value pair database; extracts the key-value pair database operation statement in the access request; based on the key-value pair database operation statement, identifies the target database object in the key-value pair data in the private relational database; performs database operation processing based on the target database object. Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices, and the Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0046] In one embodiment, Figure 2 As shown, a database operation method is provided, which is applied to Figure 1Taking the server 104 in the example as an example, the following steps are included:
[0047] Step 201 : obtaining an access request for a private relational database, where the relational database is compatible with a key-value pair data format in a key-value pair database.
[0048] Among them, privatization refers to the privatization of SaaS services. SaaS services are software subscription services that meet the needs of customer companies by leasing software from SaaS vendors. Through SaaS services, the company provides a set of standardized product solutions. That is, facing all customer needs, a set of products is used to solve them. In contrast to SaaS services are IaaS (Infrastructure as a service) and PaaS (Platform as a service). For IaaS, users can deploy and run any software, including operating systems and application software, on the infrastructure provided by the cloud service provider. Users do not have the authority to manage and access the underlying infrastructure, such as servers, switches, hard disks, etc., but have the right to manage operating systems, storage content, can install and manage applications, and even have the right to manage network components. As for PaaS, PaaS provides users with the ability to use programming languages, libraries, services, and development tools supported by cloud service providers to create, develop applications, and deploy them on related infrastructure. Users do not need to manage the underlying infrastructure, including networks, servers, operating systems, or storage. They can only control applications deployed on the operating system in the infrastructure and configure the configurable parameters of the environment in which the application is hosted. The relationship between the three is as follows: Figure 3As shown in the figure, IaaS is generally implemented on the basis of providing physical data centers, servers and storage, while PaaS needs to provide operating systems and database management development tools on the basis of IaaS, and SaaS needs to implement cloud applications on the basis of PaaS. The privatization of SaaS services refers to the deployment of the system provided by the SaaS service on the customer's own server. A relational database refers to a database that uses a relational model to organize data. It stores data in the form of rows and columns to facilitate user understanding. This series of rows and columns in a relational database is called a table, and a group of tables constitutes a database. Users retrieve data from the database through queries, and queries are an execution code used to limit certain areas in the database. The relational model can be simply understood as a two-dimensional table model, and a relational database is a data organization composed of two-dimensional tables and the relationships between them. For example, SQL (Structured Query Language) databases and SQL-like databases. Key-value data is a Key-value database, referred to as a KV database, which is a type of database that stores, retrieves and manages key-value sets and is a type of non-relational database. It stores data in the form of a key-value pair set. The key-value pair set, similar to a mapping or dictionary, is the most basic associative array. Each key is unique in the collection. The value (record) corresponding to the key can contain various fields or data without specific requirements.
[0049] Specifically, the solution of the present application is applicable to database operations of privatized relational databases. Regarding the privatization of software operation services, since software operation services can generally ensure strong consistency and high availability of data through key-value databases and other forms, and support horizontal scaling well, and stably support the development of software operation service business, when the software operation service related data is stored in the database of the SaaS service provider, it is generally stored in the key-value database of the SaaS service provider in the form of key-value data format. At the same time, the business code of the SaaS service will also be strongly coupled with the access logic of the key-value database. When it is necessary to privatize the deployment of the SaaS service, since the access logic for the key-value data is different from the access logic of the relational database, it is necessary to redevelop this part of the access during the privatization deployment, which affects the development efficiency. The solution of the present application is compatible with the key-value data format in the key-value database in the privatized relational database, so it can directly implement operations on the relational database based on the access logic of the original SaaS service, thereby improving development efficiency. Therefore, when the terminal 102 needs to perform a database operation, it can directly request the server 104 to access the private relational database using the access logic under the original SaaS service, and then the server 104 can perform the corresponding database operation based on the access request. Figure 4 As shown, in one of the embodiments, the privatized relational database of the present application can be implemented by a SQL-like database such as MariaDb. If the present application solution is not used, it is necessary to modify the code of a large number of strongly coupled kv components in the SaaS service and replace them with sql schema for access. In one of the embodiments, data migration can be performed after creating the corresponding table fields and sub-table keys of the key-value database in the relational database, thereby achieving compatibility processing with the relational database, so that the relational database is compatible with the key-value data format in the key-value database.
[0050] Step 203: extract the key-value pair database operation statement in the access request.
[0051] Specifically, the key-value database operation statement refers to the corresponding operation statement generated based on the access logic of the key-value database. The key-value database operation statement was originally only used for the key-value database. In the present application, the key-value data format in the key-value database is compatible with the relational database, thereby realizing the conversion between the key-value database object and the relational database object, so that the key-value database operation statement generated based on the access logic of the key-value database in the access request can also process the privatized relational database.
[0052] Step 205 : Based on the key-value database operation statement, identify the target database object in the key-value data in the privatized relational database.
[0053] Specifically, the target database object is the KV schema corresponding to the key-value database. Through the key-value database operation statement, the target database object that is compatible with the key-value data format in the key-value database, that is, the KV schema, can be directly searched in the privatized relational database, and then the corresponding data processing can be performed on the basis of the KV schema. When processing, for the key-value database operation statement in the access request, the key-value database operation statement can first be converted to a protocol, for example, through the protobuf schema protocol or the KV schema protocol, etc., first decode it and perform other protocol conversion processing, and then process the decoded key-value database operation statement through object relational mapping (ORM) or KV access SDK, etc., identify the target database object pointed to by the input key-value database operation statement, and then perform corresponding database operation processing.
[0054] Step 207: Perform database operation processing based on the target database object.
[0055] Specifically, after obtaining the target database object, the specific data required for the access request can be determined based on the key-value pair database operation statement, thereby realizing database operation processing. For example, for an access request for newly added data, corresponding data records can be added to a specified data table of a relational database based on the target database object. For database operation processing such as modification, query or deletion, the corresponding data records can be directly modified, queried or deleted after finding the corresponding data records based on the target database object. In one embodiment, after performing database operation processing based on the target database object, it also includes: generating a data operation processing result corresponding to the target database object; and feeding back the data operation result to the request end of the access request. That is, after the database operation is completed, the database operation result after the access is fed back to the terminal 102, thereby informing the terminal 102 that the operation on the privatized relational database has been completed, and reminding the user of the terminal 102 that other subsequent processing can be performed.
[0056] The above-mentioned database operation method directly extracts the key-value pair database operation statement in the access request after obtaining the access request for the privatized relational database, and then identifies the target database object in the key-value pair data compatible with the storage in the relational database based on the key-value pair database operation statement, so as to perform database operation processing based on the identified target database object. That is, the present application can use the key-value pair database operation statement to operate the privatized relational database, thereby directly migrating the access logic strongly coupled with the key-value pair database to the privatized version without the need for additional development, thereby effectively improving the development efficiency of the privatization process.
[0057] In one embodiment, the method also includes: obtaining a privatization deployment request for a software operation service; searching a key-value pair database of the software operation service based on the privatization deployment request; performing privatization deployment processing on the privatized target relational database in a compatible manner; and migrating the key-value pair data in the key-value pair database to the privatized target relational database in a compatible manner.
[0058] Among them, the privatization deployment request specifically refers to the request for privatization deployment of the database during the privatization process of the SaaS software operation service. Compatible privatization deployment processing refers to specifying the storage format of the target relational database when privatizing the target relational database, so that it can be compatible with the storage methods of various key-value databases, such as specifying the storage format of the target relational database by setting table fields or dividing key values. After migrating the key-value data in the key-value database to the privatized relational database in a compatible manner, the storage method of the key-value data format can still be maintained.
[0059] Specifically, the public version of the software operation service generally provides a corresponding online storage system service. When the software operation service is privatized, not only the privatized target relational database is processed for privatization in a compatible manner, but also the data related to the privatized deployment users stored in the online storage system needs to be migrated to the privatized database, that is, the data that needs to be privatized in the online storage system can also be saved in the privatized database according to compatible standards. The key-value database of the software operation service is the online storage system provided by the software operation service. After receiving a privatization deployment request for the software operation service, if the privatization deployment request is received, the key-value database of the software operation service is searched to determine whether there is relevant storage data for the privatization deployment in the key-value database of the software operation service. Then, after the privatized target relational database is processed for privatization deployment in a compatible manner, if the key-value database already has data that needs to be privatized, the key-value database can be processed for privatization deployment, and the key-value data in the key-value database can be migrated to the privatized target relational database in a compatible manner during the migration process. Otherwise, the storage format of the target relational database can be processed for compatibility, and the key-value data formats in various key-value databases can be compatible by specifying the storage format of the target relational database. In this embodiment, by processing the key-value database for privatization deployment, the key-value data format in the key-value database can be effectively compatible with the relational database, so that there is no need to rewrite the code when implementing privatization deployment in the relational database, thereby improving the development efficiency of privatization deployment.
[0060] In one embodiment, migrating key-value pair data in a key-value pair database to a privatized target relational database in a compatible manner includes: determining a key field value, a value field value, and a default sub-table key value for each storage data in the key-value pair database; migrating the storage data in the key-value pair database to the privatized target relational database, and determining the key field of the storage data migrated to the target relational database based on the key field value, determining the value field of the storage data migrated to the target relational database based on the value field value, and adding a sub-table key field value to the storage data migrated to the target relational database based on the default sub-table key.
[0061] The key field value is the key data of the key-value pair, and the value field value is the value data of the key-value pair. The shard key (shard_key) is a field used to record which table the data is assigned to. When reading and writing data, routing can be implemented based on the shard key. For the storage data format of adding a shard key, refer to Figure 5 shown.
[0062] Specifically, the online storage system of the software operation service of the present application can be a key-value pair database implemented based on leveldb. At this time, the key-value pair data stored in the key-value pair database specifically includes the key field value, the value field value and the default sub-table key value. When the data is stored in the key-value pair database, each data record will be assigned a corresponding sub-table key value. Therefore, when migrating data, it is necessary to determine that each key-value pair data specifically includes the key field value, the value field value and the default sub-table key value. Then, since the privatized target relational database has been processed for privatization deployment in a compatible manner, the data table in the target relational database already includes key fields, value fields and sub-table fields, so the storage data in the key-value pair database can be directly migrated to the privatized target relational database. For each data record that needs to be migrated, the key field of the storage data migrated to the target relational database is determined based on the key field value, the value field of the storage data migrated to the target relational database is determined based on the value field value, and the sub-table key field value is added to the storage data migrated to the target relational database based on the default sub-table key. In this embodiment, data migration processing is achieved by determining the method of storing data field values, so that the key-value pair data in the key-value pair database under the software operation service can be effectively migrated to the privatized target relational database in a compatible manner, thereby ensuring the effectiveness of data migration and thus ensuring the efficiency and accuracy of privatization deployment.
[0063] In one embodiment, migrating key-value pair data in a key-value pair database to a privatized target relational database in a compatible manner includes: identifying a timeout-type key-value pair database in the key-value pair database; determining a key field value, a value field value, a timeout-type field value, and a default sharding key value for each storage data in the timeout-type key-value pair database; migrating the storage data in the timeout-type key-value pair database to the privatized target relational database, and determining the key field of the storage data migrated to the target relational database based on the key field value, determining the value field of the storage data migrated to the target relational database based on the value field value, determining the timeout-type field of the storage data migrated to the target relational database based on the timeout-type field value, and adding a sharding key field value to the storage data migrated to the target relational database based on the default sharding key.
[0064] Specifically, the online storage system of the software operation service of the present application can be a key-value pair database with a timeout elimination function. At this time, the key-value pair data stored in the key-value pair database specifically includes a key field value, a value field value, a timeout elimination field value, and a default sub-table key value, wherein the timeout elimination field value is used to specify the effective time of the data. When data is stored in the key-value pair database, each data record will be assigned a corresponding sub-table key value. Therefore, when migrating data, it is necessary to determine that each key-value pair data specifically includes a key field value, a value field value, a timeout elimination field value, and a default sub-table key value. Then, since the privatized target relational database has been processed for privatization deployment in a compatible manner, the data table in the target relational database already contains key fields, value fields, timeout elimination fields, and sub-table fields, so the stored data in the key-value pair database can be directly migrated to the privatized target relational database. For each data record that needs to be migrated, when migrating the stored data in the timeout elimination key-value pair database to the privatized target relational database, the key field of the stored data migrated to the target relational database can be determined based on the key field value, the value field of the stored data migrated to the target relational database can be determined based on the value field value, the timeout elimination field of the stored data migrated to the target relational database can be determined based on the timeout elimination field value, and the sub-table key field value can be added to the stored data migrated to the target relational database based on the default sub-table key. In this embodiment, the data migration process is realized by determining the storage data field value, and the key-value pair data in the key-value pair database under the software operation service can be effectively migrated to the privatized target relational database in a compatible manner, ensuring the effectiveness of data migration, thereby ensuring the efficiency and accuracy of privatization deployment.
[0065] In one embodiment, migrating key-value data in a key-value database to a privatized target relational database in a compatible manner includes: identifying a quasi-relational table storage database in the key-value database; determining a default sub-table key for each piece of storage data in the quasi-relational table storage database; migrating the storage data in the quasi-relational table storage database to the privatized target relational database, and adding a sub-table key field value to the storage data migrated to the target relational database based on the default sub-table key.
[0066] Specifically, the online storage system of the software operation service of the present application can be a key-value database based on leveldb implementation, which is stored in a table storage format of a quasi-relational type. At this time, the key-value pair data stored in the key-value pair database is stored in the storage format of the table and contains the default sub-table key value. When the data is stored in the key-value pair database, each data record will be assigned a corresponding sub-table key value, so when migrating the data, it is necessary to determine that each key-value pair data specifically contains the default sub-table key value. Then, since the privatized target relational database has been processed for privatization deployment in a compatible manner, the data table in the target relational database already contains the sub-table field, so the storage data in the quasi-relational table storage database can be directly migrated to the privatized target relational database, and the sub-table key field value is added to the storage data migrated to the target relational database based on the default sub-table key. In this embodiment, the data migration process is realized by determining the storage data field value, and the key-value pair data in the key-value pair database under the software operation service can be effectively migrated to the privatized target relational database in a compatible manner, ensuring the effectiveness of data migration, thereby ensuring the efficiency and accuracy of privatization deployment.
[0067] In one embodiment, the method further includes: when the data volume of a single table in the target relational database reaches a data volume threshold; performing database and table sharding processing on the target relational database based on the table sharding key field value.
[0068] The data volume threshold can be set according to the processing performance of the target relational database. The better the performance, the higher the data volume threshold can be set. Sub-database and sub-table refers to alleviating the performance problem of a single database by distributing the data of the original database to different databases, making the data volume of a single database smaller, thereby achieving the purpose of improving database performance. It usually includes four methods: vertical sub-database, vertical sub-table, horizontal sub-database and horizontal sub-table.
[0069] Specifically, as the amount of data in the privatized relational database increases, the access performance of the database will also decrease. Therefore, it is necessary to process the privatized relational database into sub-libraries and sub-tables. The problem of reduced database performance due to excessive data volume can be solved by sub-libraries and sub-tables. The original independent database can be split into several database components, and the large data table can be split into several data tables, so that the amount of data in a single database and a single data table becomes smaller, thereby achieving the purpose of improving database performance. In the scheme of the present application, the relational database is compatible with the key-value pair data format in the key-value pair database. Therefore, each stored data stored in the relational database contains a sub-table key field. In the process of sub-table, the sub-library and sub-table can be realized based on the sub-table key field to ensure the accuracy of the sub-library and sub-table processing. In this embodiment, the privatized relational database can be split into multiple databases by sub-libraries and sub-tables to ensure the access performance of the database.
[0070] In one embodiment, sharding the target relational database based on sharding key field values includes: determining the data tables to be migrated in the target relational database; creating a sharding database corresponding to the target relational database; migrating the data tables to be migrated in the target relational database to the sharding database; and horizontally sharding the data tables in the target relational database and the sharding database based on the sharding key field values.
[0071] The data tables to be migrated refer to the data tables that are migrated to other databases during the process of database and table sharding. The sub-database is a new database relative to the original target relational database. The amount of data stored in the sub-database is far less than that of the original target relational database.
[0072] Specifically, the solution of the present application can perform database and table sharding when the amount of data in the target relational database reaches a threshold value. When sharding, it is first necessary to determine the data tables to be migrated in the target relational database. A sub-database corresponding to the target relational database is created to accommodate these migrated data tables; then the data tables to be migrated in the target relational database are migrated to the sub-database; and the target relational database and the data tables in the sub-database are horizontally sharded based on the sub-table key field values to complete the database and table sharding process. In one of the embodiments, for the specific process of horizontally sharding the target relational database and the data tables in the sub-database based on the sub-table key field values, the target sub-table for the key-value pair data in the data table can be determined based on the sub-table key field values; the key-value pair data in the data table is horizontally split, so as to split the key-value pair data in the target relational database into the target sub-table corresponding to the key-value pair data. In one of the embodiments, the process of database and table sharding can be specifically referred to. Figure 6As shown, first, the access logic for the privatized relational database points to the database DB0, which contains 4 data tables, namely table0, table1, table2 and table3. After the need for sub-library and table division, the data tables that need to be migrated are identified as table1 and table3. At this time, a sub-database DB1 can be created first, and then based on the logical service of the relational database, table1 and table3 are migrated to the sub-database DB1 through slice routing, and then horizontal table division is performed on DB0 and DB1 based on the sub-table key field value. Table4 is split from table0, table5 is split from table1, table6 is split from table2, and table7 is split from table3. In this way, one database is divided into two databases, and the data tables therein are also divided into two parts, so the amount of data that can be accommodated can also be improved, while ensuring the processing performance of the database. In this embodiment, the privatized relational database can be split into multiple databases by sub-library and table division to ensure the access performance of the database.
[0073] In one embodiment, step 207 includes: determining the sub-table key field of the target data in the target database object based on the key-value pair database operation statement; performing routing processing based on the sub-table key field to obtain routing information of the target data; and performing database operation processing on the target data based on the database operation statement and the routing information.
[0074] Specifically, since the data stored in the relational database all contain the field content of the sub-table key, and the sub-table key can be used to determine which table the current stored data is placed in, when performing operations such as reading and writing to the database, it is possible to directly find which database needs to be routed to perform database operation processing according to the shard_key. Therefore, when performing data processing, the sub-table key field of the target data in the target database object can be determined based on the key-value pair database operation statement, and then routing processing is performed based on the sub-table key field to obtain the routing information of the target data. After obtaining the routing information, the corresponding database operation processing can be performed on the target data based on the database operation statement and the routing information, such as reading data, adding data, modifying data or deleting data, so as to complete the processing logic of the access request and achieve the purpose of data operation. In the present embodiment, routing processing is performed through the sub-table key field, and the routing information of the target data can be effectively obtained, so that various processing of database operation is performed for the target data, and the efficiency and accuracy of the database operation are guaranteed.
[0075] In one embodiment, extracting the key-value pair database operation statement in the access request includes: extracting the original key-value pair database operation statement in the access request; encoding the original key-value pair database operation statement through a database communication protocol to obtain protocol encoded data; performing object relation mapping on the protocol encoded data to obtain the key-value pair database operation statement.
[0076] Among them, the database communication protocol refers to the network protocol used in the database communication process, and the network protocol is a set of agreements that both communicating computers must follow. Such as how to establish a connection, how to identify each other, etc. Only by complying with this agreement can computers communicate with each other. Its three elements are: syntax, semantics, and timing. In the scheme of this application, the database communication protocol can be specifically implemented through the protobuf schema protocol or the KV schema protocol. Among them, protobuf is Protocol Buffers, which is a lightweight and efficient structured data storage format that can be used for structured data serialization and is very suitable for data storage or RPC data exchange format. It can be used in language-independent, platform-independent, and extensible serialized structured data formats in the fields of communication protocols and data storage.
[0077] Specifically, when obtaining an access request, it is necessary to extract the key-value database operation statement in the access request. For the private storage access mode, the business layer encodes the original key-value database operation statement input through the access request through the database communication protocol to obtain protocol encoding data; and then performs object relation mapping on the protocol encoding data to obtain the key-value database operation statement. In one embodiment, Figure 7 As shown, the storage access logic for SaaS can refer to Figure 7 As shown in the left figure, the protobuf schema protocol or KV schema protocol is used to convert the protocol operation statement, and then enter the ORM or KV access toolkit, and then access various KV databases including tableKV, stringKV and ttlKV in the form of key-value database objects (KV schema). The original storage access logic for privatization can refer to Figure 7As shown in the left figure, the protocol operation statements are converted through the protobufschema protocol or the KV schema protocol, and then into the ORM or KV access toolkit, and then the MariaDB database including SQL-like is accessed in the form of SQL database objects (SQL schema). That is, according to the requirements of MariaDB, it is necessary to convert the operation statements for the SQL schema. Since the solution of this application is compatible with the storage method of the KV database based on MariaDB, it can directly access the storage content of MariaDB through the operation statements of the key-value database objects in accordance with the SaaS storage access method. In this embodiment, by performing protocol encoding and object-relationship mapping on the original key-value database operation statements, it is possible to migrate the access logic of the key-value database to the process of private deployment on the basis of the software operation service, thereby ensuring the efficiency of private deployment.
[0078] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0079] The present application also provides an application scenario, and the application scenario applies the above database operation method. Specifically, the application of the database operation method in the application scenario is as follows:
[0080] When a user purchases a software operation service from a service provider, after a period of operation, the user hopes to perform a private deployment of the software operation service. At this time, this solution can be used to realize the privatization of the online storage system during the private deployment process, and to perform access operations on the private relational database. First of all, the online storage system includes three key-value databases: key-value database, timeout-type key-value database, and relational table storage database. During privatization, these three need to be privatized separately, and the data stored in the online database should be migrated to a local relational database such as MariaDB. That is, after obtaining a private deployment request for the software operation service; the key-value database of the software operation service can be searched based on the private deployment request; the private deployment processing of the privatized target relational database is performed in a compatible manner; and the key-value data in the key-value database is migrated to the privatized target relational database in a compatible manner. For a key-value pair database, the key field value, value field value, and default sub-table key value of each storage data in the key-value pair database can be determined; the storage data in the key-value pair database is migrated to the privatized target relational database, and the key field of the storage data migrated to the target relational database is determined based on the key field value, the value field of the storage data migrated to the target relational database is determined based on the value field value, and the sub-table key field value is added to the storage data migrated to the target relational database based on the default sub-table key. For a timeout-type key-value pair database, the key field value, the timeout-elimination field value of the value field value, and the default sub-table key value of each storage data in the timeout-type key-value pair database are determined; the storage data in the timeout-type key-value pair database is migrated to the privatized target relational database, and the key field of the storage data migrated to the target relational database is determined based on the key field value, the value field of the storage data migrated to the target relational database is determined based on the value field value, the timeout-elimination field of the storage data migrated to the target relational database is determined based on the timeout-elimination field value, and the sub-table key field value is added to the storage data migrated to the target relational database based on the default sub-table key. For a quasi-relational table storage database, a default sharding key for each piece of stored data in the quasi-relational table storage database is determined; the stored data in the quasi-relational table storage database is migrated to a privatized target relational database, and a sharding key field value is added to the stored data migrated to the target relational database based on the default sharding key.At the same time, if the data volume of a single table in a privatized relational database reaches a data volume threshold, the target relational database can be partitioned based on the partition key field value. When partitioning, the data table to be migrated in the target relational database is first determined; and a partition database corresponding to the target relational database is created; the data table to be migrated in the target relational database is migrated to the partition database; and then the target partition table of the key-value pair data in the data table is determined based on the partition key field value; the key-value pair data in the data table is horizontally split to split the key-value pair data in the target relational database into the target partition table corresponding to the key-value pair data. When processing database operations, after obtaining an access request for the privatized relational database, the key-value pair database operation statement in the access request can be extracted; based on the key-value pair database operation statement, the target database object in the key-value pair data in the privatized relational database is identified; based on the key-value pair database operation statement, the partition key field of the target data in the target database object is determined; routing processing is performed based on the partition key field to obtain routing information for the target data; and database operation processing is performed on the target data based on the database operation statement and the routing information. As for the operation statement extraction process, since the present application is already compatible with the storage format of key-value data in the relational database, the original key-value database operation statement in the access request can be extracted; the original key-value database operation statement is encoded through the database communication protocol to obtain the protocol encoding data; the protocol encoding data is subjected to object-relation mapping to obtain the key-value database operation statement. After the database operation is completed, the data operation processing result corresponding to the target database object can be generated; and the data operation result is fed back to the request end of the access request.
[0081] In one embodiment, the complete process of the database operation method of the present application can be referred to Figure 8As shown, it includes: step 801, obtaining a privatization deployment request for a software operation service. Step 803, searching a key-value pair database of a software operation service based on the privatization deployment request. Step 805, performing privatization deployment processing on the privatized target relational database in a compatible manner. Step 807, migrating the key-value pair data in the key-value pair database to the privatized target relational database in a compatible manner. Step 809, when the data volume of a single table data in the target relational database reaches a data volume threshold, performing database and table sharding processing on the target relational database based on the sharding key field value. Step 811, obtaining an access request for the privatized relational database. Step 813, identifying a target database object in the key-value pair data in the privatized relational database based on a key-value pair database operation statement. Step 815, determining a sharding key field of the target data in the target database object based on the key-value pair database operation statement. Step 817, performing routing processing based on the sharding key field to obtain routing information for the target data. Step 819: Perform database operation processing on the operation target data based on the database operation statement and routing information.
[0082] Based on the same inventive concept, the embodiment of the present application also provides a database operation device for implementing the database operation method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more database operation device embodiments provided below can refer to the limitations on the database operation method above, and will not be repeated here.
[0083] In one embodiment, Fig. 9 As shown, a database operation device is provided, comprising:
[0084] The request acquisition module 902 is used to acquire an access request for a private relational database, where the relational database is compatible with the key-value pair data format in the key-value pair database.
[0085] The statement extraction module 904 is used to extract the key-value pair database operation statement in the access request.
[0086] The object identification module 906 is used to identify the target database object in the key-value pair data in the private relational database based on the key-value pair database operation statement.
[0087] The database operation module 908 is used to perform database operation processing based on the target database object.
[0088] In one embodiment, it also includes a privatization deployment module, which is used to: obtain a privatization deployment request for a software operation service; search a key-value pair database of the software operation service based on the privatization deployment request; perform privatization deployment processing on the privatized target relational database in a compatible manner; and migrate the key-value pair data in the key-value pair database to the privatized target relational database in a compatible manner.
[0089] In one embodiment, the privatization deployment module is also used to: determine the key field value, value field value and default sub-table key value of each storage data in the key-value pair database; migrate the storage data in the key-value pair database to the privatized target relational database, and determine the key field of the storage data migrated to the target relational database based on the key field value, determine the value field of the storage data migrated to the target relational database based on the value field value, and add the sub-table key field value to the storage data migrated to the target relational database based on the default sub-table key.
[0090] In one embodiment, the privatization deployment module is also used to: identify a timeout-type key-value pair database in a key-value pair database; determine the key field value, the value field value, the timeout-type field value, and the default sub-table key value of each storage data in the timeout-type key-value pair database; migrate the storage data in the timeout-type key-value pair database to a privatized target relational database, and determine the key field of the storage data migrated to the target relational database based on the key field value, determine the value field of the storage data migrated to the target relational database based on the value field value, determine the timeout-type field of the storage data migrated to the target relational database based on the timeout-type field value, and add the sub-table key field value to the storage data migrated to the target relational database based on the default sub-table key.
[0091] In one embodiment, the privatization deployment module is also used to: identify a quasi-relational table storage database in a key-value pair database; determine a default sub-table key for each stored data in the quasi-relational table storage database; migrate the stored data in the quasi-relational table storage database to a privatized target relational database, and add a sub-table key field value to the stored data migrated to the target relational database based on the default sub-table key.
[0092] In one embodiment, it also includes a library and table sharding module, which is used to: when the data volume of a single table in the target relational database reaches a data volume threshold; perform library and table sharding on the target relational database based on the sharding table key field value.
[0093] In one embodiment, the database and table sharding module is also used to: determine the data tables to be migrated in the target relational database; create a sub-database corresponding to the target relational database; migrate the data tables to be migrated in the target relational database to the sub-database; and perform horizontal table sharding on the data tables in the target relational database and the sub-database based on the sub-table key field values.
[0094] In one embodiment, the sub-library and sub-table module is also used to: determine the target sub-table of the key-value pair data in the data table based on the sub-table key field value; horizontally split the key-value pair data in the data table to split the key-value pair data in the target relational database into the target sub-table corresponding to the key-value pair data.
[0095] In one embodiment, the database operation module 908 is specifically used to: determine the sub-table key field of the operation target data in the target database object based on the key-value pair database operation statement; perform routing processing based on the sub-table key field to obtain routing information of the operation target data; and perform database operation processing on the operation target data based on the database operation statement and the routing information.
[0096] In one embodiment, the statement extraction module 904 is specifically used to: extract the original key-value pair database operation statement in the access request; encode the original key-value pair database operation statement through the database communication protocol to obtain protocol encoded data; perform object-relational mapping on the protocol encoded data to obtain the key-value pair database operation statement.
[0097] In one embodiment, it also includes a result feedback module, which is used to: generate a data operation processing result corresponding to the target database object; and feed back the data operation result to the request end of the access request.
[0098] Each module in the above database operation device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module.
[0099] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.10As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store privatized data after privatization deployment. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a database operation method is implemented.
[0100] Those skilled in the art will understand that Fig.10 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0101] In one embodiment, a computer device is further provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above method embodiments when executing the computer program.
[0102] In one embodiment, a computer-readable storage medium is provided, storing a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0103] In one embodiment, a computer program product or computer program is provided, the computer program product or computer program includes computer instructions, the computer instructions are stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device performs the steps in the above-mentioned method embodiments.
[0104] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0105] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0106] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0107] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A database operation method, It is characterized in that The method comprises: Obtaining an access request for a privatized relational database, wherein the relational database is compatible with a key-value pair data format in a key-value pair database; Extracting a key-value pair database operation statement in the access request; Based on the key-value database operation statement, identifying a target database object in the key-value data in the privatized relational database; Database operation processing is performed based on the target database object.
2. The method according to claim 1, It is characterized in that The method further comprises: Obtain privatization deployment requests for software operation services; Searching a key-value pair database of the software operation service based on the privatization deployment request; Performing privatization deployment processing on the privatized target relational database in a compatible manner; The key-value pair data in the key-value pair database is migrated to the privatized target relational database in a compatible manner.
3. The method according to claim 2, It is characterized in that The step of migrating the key-value pair data in the key-value pair database to the privatized target relational database in a compatible manner includes: Determine the key field value, value field value and default sub-table key value of each stored data in the key-value pair database; The storage data in the key-value pair database is migrated to the privatized target relational database, and the key field of the storage data migrated to the target relational database is determined based on the key field value, the value field of the storage data migrated to the target relational database is determined based on the value field value, and a sub-table key field value is added to the storage data migrated to the target relational database based on the default sub-table key.
4. The method according to claim 2, It is characterized in that The step of migrating the key-value pair data in the key-value pair database to the privatized target relational database in a compatible manner includes: Identifying a timed-out key-value pair database in the key-value pair database; Determine the key field value, the timeout elimination field value, and the default sub-table key value of each stored data in the timeout elimination type key-value pair database; The storage data in the timeout-elimination key-value pair database is migrated to the privatized target relational database, and the key field of the storage data migrated to the target relational database is determined based on the key field value, the value field of the storage data migrated to the target relational database is determined based on the value field value, the timeout-elimination field of the storage data migrated to the target relational database is determined based on the timeout-elimination field value, and a shard table key field value is added to the storage data migrated to the target relational database based on the default shard table key.
5. The method according to claim 2, It is characterized in that The step of migrating the key-value pair data in the key-value pair database to the privatized target relational database in a compatible manner includes: Identify a relational table storage database in the key-value pair database; Determine a default sub-table key for each piece of stored data in the relational table storage database; The stored data in the quasi-relational table storage database is migrated to the privatized target relational database, and a sub-table key field value is added to the stored data migrated to the target relational database based on the default sub-table key.
6. The method according to claim 5, It is characterized in that The method further comprises: When the data volume of a single table in the target relational database reaches a data volume threshold, the target relational database is subjected to database and table sharding processing based on the sharding key field value.
7. The method according to claim 6, It is characterized in that The processing of performing database and table sharding on the target relational database based on the table sharding key field value includes: Determining a data table to be migrated in the target relational database; Creating a sub-database corresponding to the target relational database; Migrating the to-be-migrated data table in the target relational database to the sub-database; Horizontal table splitting is performed on the target relational database and the data tables in the sub-database based on the sub-table key field value.
8. The method according to claim 7, It is characterized in that The horizontal table splitting processing of the target relational database and the data tables in the sub-database based on the sub-table key field value includes: Determine a target sub-table for the key-value pair data in the data table based on the sub-table key field value; The key-value pair data in the data table are horizontally split to split the key-value pair data in the target relational database into target sub-tables corresponding to the key-value pair data.
9. The method according to claim 7, It is characterized in that The database operation processing based on the target database object includes: Determine the sub-table key field of the target data to be operated in the target database object based on the key-value pair database operation statement; Perform routing processing based on the sub-table key field to obtain routing information of the operation target data; Based on the database operation statement and the routing information, database operation processing is performed on the operation target data.
10. The method according to claim 1, It is characterized in that The extracting of the key-value pair database operation statement in the access request comprises: Extracting the original key-value pair database operation statement in the access request; Encoding the original key-value pair database operation statement through a database communication protocol to obtain protocol encoded data; Object relational mapping is performed on the protocol encoded data to obtain key-value pair database operation statements.
11. The method according to any one of claims 1 to 10, It is characterized in that After performing database operation processing based on the target database object, the method further includes: Generate a data operation processing result corresponding to the target database object; Feedback the data operation result to the request end of the access request.
12. A database operation device, It is characterized in that The device comprises: A request acquisition module, used to acquire an access request for a privatized relational database, wherein the relational database is compatible with a key-value pair data format in a key-value pair database; A statement extraction module, used to extract key-value pair database operation statements in the access request; An object identification module, used to identify a target database object in the key-value pair data in the privatized relational database based on the key-value pair database operation statement; The database operation module is used to perform database operation processing based on the target database object.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program. It is characterized in that When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.
14. A computer-readable storage medium having a computer program stored thereon, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer program product comprising a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
