Data writing method, system, electronic device, readable storage medium and product

By setting up a multi-thread pool and corresponding databases for the participants on the central side, the problem of low writing efficiency of multiple participants in centralized trusted computing scenarios is solved, and the parallel processing of multiple writing tasks is realized, thereby improving writing efficiency.

CN114064267BActive Publication Date: 2025-09-19CLUSTAR TECH LO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111224800.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-21
Publication Date
2025-09-19
Estimated Expiration
2041-10-21

AI Technical Summary

Technical Problem

In a centralized trusted computing scenario, when multiple parties write data to an embedded database simultaneously, the write efficiency is low. Existing technologies such as SQLite only allow single-threaded writing, resulting in an efficiency bottleneck.

Method used

By setting up a thread pool of multiple write threads on the central side, the corresponding database and write thread are allocated according to the participant ID, so as to achieve parallel execution of multiple write tasks and avoid writing to the same database at the same time.

Benefits of technology

It improves the efficiency of multiple parties writing to the database, solves the writing bottleneck problem under the single-threaded writing limitation, and realizes the parallel processing of multiple writing tasks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114064267B_ABST
    Figure CN114064267B_ABST
Patent Text Reader

Abstract

The present invention discloses a data writing method, system, electronic device, and readable storage medium. The data writing method is applied to a central party in a centralized trusted computing scenario. The central party is in communication with at least one participant, and the central party provides a one-to-one database for each participant. For any first participant among the participants, the data writing method includes: receiving a write request from the first participant, parsing the first participant ID from the write request; obtaining the name of the first database corresponding to the first participant based on the first participant ID, and determining the first write thread from multiple write threads in a thread pool based on the first participant ID; and calling the first write thread to write the first participant's to-be-written data into the first database. The present invention solves the technical problem of low write efficiency when multiple participants write to the database because the database only allows a single process to write at the same time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of database technology, and in particular to a data writing method, system, electronic device, readable storage medium and product. Background Art

[0002] Currently, to protect user data privacy, centralized trusted computing scenarios based on SGX (software guard extensions) have been introduced. The trusted execution environment provided by SGX prevents user privacy data from being leaked. Because SGX relies on hardware instructions for security, relatively few software can run in the SGX environment. Common relational databases currently do not support the SGX environment, and only embedded databases, such as SQLite, can be used. However, SQLite only allows a single thread to write to the database at a time. When any process wants to write data to the database, the database engine will lock the entire database file while the process writes data. This leads to low write efficiency when multiple participants write data to the embedded database simultaneously in centralized trusted computing scenarios. Summary of the Invention

[0003] The main purpose of the present invention is to provide a data writing method, system, electronic device, readable storage medium and product, aiming to solve the technical problem of low writing efficiency when multiple participants write data to an embedded database at the same time in a centralized trusted computing scenario.

[0004] To achieve the above objectives, the present invention provides a data writing method, which is applied to a central party in a centralized trusted computing scenario. The central party is in communication with at least one participant, and the central party provides a one-to-one database for each participant. For any first participant among the participants, the data writing method includes:

[0005] receiving a write request from the first participant, and parsing the first participant ID from the write request;

[0006] Obtaining a name of a first database corresponding to the first participant based on the first participant ID, and determining a first write thread from a plurality of write threads in a thread pool based on the first participant ID;

[0007] The first writing thread is called to write the to-be-written data of the first participant into the first database.

[0008] Optionally, the step of obtaining the name of the first database corresponding to the first participant based on the first participant ID includes:

[0009] Searching whether there is a database corresponding to the first participant ID;

[0010] If it exists, use the database corresponding to the first participant ID as the first database, and obtain the name of the first database;

[0011] If it does not exist, a new database is created and used as the first database, and the name of the first database is obtained.

[0012] Optionally, when the ID of each participant is an incremental ID, the step of determining the first writing thread from multiple writing threads in the thread pool based on the first participant ID includes:

[0013] Taking the remainder of the first participant ID and the total number of write threads in the thread pool to obtain a remainder result;

[0014] The thread numbered as the write thread of the remainder result in the thread pool is used as the first write thread.

[0015] Optionally, the step of determining the first writing thread from multiple writing threads in the thread pool based on the first participant ID includes:

[0016] Finding a first ranking corresponding to the first participant ID, wherein the first ranking is the ranking of the first visit time of the first participant among the first visit times of the participants;

[0017] Taking the remainder of the total number of write threads in the thread pool after performing the first sorting operation, and obtaining a remainder result;

[0018] The thread numbered as the write thread of the remainder result in the thread pool is used as the first write thread.

[0019] Optionally, the step of calling the first writing thread to write the to-be-written data of the first participant into the first database includes:

[0020] The name of the first database is sent to the first writing thread, and the data to be written by the first participant is scheduled to the first writing thread, so as to call the first writing thread to execute the writing task of writing the data to be written into the first database according to the name of the first database.

[0021] Optionally, the step of calling the first writing thread to write the to-be-written data of the first participant into the first database further includes:

[0022] The first writing thread is called to create a new first data table in the first database, and execute a writing task of writing the to-be-written data of the first participant into the first data table.

[0023] Optionally, after the step of calling the first writing thread to create a new first data table in the first database and executing the writing task of writing the to-be-written data of the first participant into the first data table, the data writing method further includes:

[0024] detecting whether the first data table is a replacement data table of the second data table in the first database;

[0025] If yes, delete the second data table.

[0026] Optionally, before the step of calling the first writing thread to create a first data table in the first database and executing the writing task of writing the first party's to-be-written data into the first data table, the data writing method further includes:

[0027] Determining whether the data to be written by the first participant is update data of part of the data in the third data table in the first database;

[0028] If so, calling the first writing thread to execute the writing task of updating the third data table with the data to be written;

[0029] If not, the step of calling the first writing thread to create a new first data table in the first database and executing the writing task of writing the to-be-written data of the first participant into the first data table is executed.

[0030] The present invention also provides a data writing system, which is deployed as a central party in a centralized trusted computing scenario. The central party is in communication with at least one participant, and the central party provides a one-to-one database for each participant. For any first participant among the participants, the data writing system includes:

[0031] a receiving module, configured to receive a write request from the first participant and parse the write request to obtain the first participant ID;

[0032] an acquisition module, configured to acquire a name of a first database corresponding to the first participant based on the first participant ID, and determine a first write thread from a plurality of write threads in a thread pool based on the first participant ID;

[0033] A writing module is used to call the first writing thread to write the data to be written by the first participant into the first database.

[0034] The present invention also provides an electronic device, which is a physical device and includes: a memory, a processor, and a program of the data writing method stored in the memory and runnable on the processor. When the program of the data writing method is executed by the processor, the steps of the data writing method as described above can be implemented.

[0035] The present invention also provides a readable storage medium, which is a computer-readable storage medium. The computer-readable storage medium stores a program for implementing the data writing method. When the program of the data writing method is executed by a processor, the steps of the data writing method as described above are implemented.

[0036] The present invention also provides a product, which is a computer program product, including a computer program, and when the computer program is executed by a processor, the steps of the data writing method as described above are implemented.

[0037] The present invention provides a data writing method, system, electronic device and readable storage medium. The present invention sets a thread pool including multiple writing threads. The central party receives the write request of the first participant, parses the first participant ID from the write request, obtains the name of the first database corresponding to the first participant based on the first participant ID, and determines the first writing thread from the multiple writing threads in the thread pool based on the first participant ID. The first writing thread is called to write the to-be-written data of the first participant into the first database. The method can realize that multiple writing threads respectively execute the writing tasks of different participants. By setting the central party to provide a one-to-one corresponding database for each participant, when multiple writing threads respectively execute the writing tasks of different participants, there will be no situation of writing to the same database at the same time, thereby realizing that multiple writing threads simultaneously execute the writing tasks of different participants, and further, when the database has a restriction that only a single process is allowed to write at the same time, the writing efficiency of multiple participants when writing to the database can be improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0038] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0040] Figure 1 This is a flow chart of a first embodiment of a data writing method according to the present invention;

[0041] Figure 2 This is a schematic diagram of the data uploading process involved in an embodiment of the data writing method of the present invention;

[0042] Figure 3 Schematic diagram of the device structure of the hardware operating environment involved in the data writing method in an embodiment of the present invention.

[0043] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION

[0044] To make the above-mentioned objects, features, and advantages of the present invention more clearly understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some of the embodiments of the present invention, not all of them. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making any creative efforts shall fall within the scope of protection of the present invention.

[0045] Example 1

[0046] See also Figure 1 , an embodiment of the present invention provides a data writing method, comprising:

[0047] Step S10: receiving a write request from the first participant, and parsing the first participant ID from the write request;

[0048] In this embodiment, the data writing method can be applied to a device deployed with a database engine; in one embodiment, the data writing method can be applied to a central party in a centralized feasible computing scenario, where the central party is deployed with a database engine. The database can be a database that has a restriction that only allows a single process to write at the same time, such as an SQLite database, which is not specifically limited in this embodiment. In a centralized trusted computing scenario, the central party is in communication with at least one participant, and each participant acts as a writer and writes data to the central party's database. In order to solve the problem of low writing efficiency caused by the existence of write restrictions in the database, in this embodiment, the central party provides a one-to-one corresponding database for each participant. Any participant can write data to the central party's database. For the sake of convenience of description, the participant who needs to write data to the central party's database will be referred to as the first participant below.

[0049] The first participant can call the central party to complete the write task of writing data to the database by sending a data write request or instruction. After receiving the write request or instruction from the first participant, the central party parses the write request to extract the first participant's ID. Each participant has a unique ID, and the first participant includes its own ID in the write request sent to the central party.

[0050] Step S20: obtaining a name of a first database corresponding to the first participant based on the first participant ID, and determining a first write thread from a plurality of write threads in a thread pool based on the first participant ID;

[0051] After the central party obtains the first participant ID through parsing, it can obtain the name of the database corresponding to the first participant (hereinafter referred to as the first database for distinction) based on the first participant ID. In the central party, each participant can be pre-set with a corresponding database. One participant can correspond to one or more databases, but it is necessary to ensure that different participants correspond to different databases. Specifically, in one embodiment, the correspondence between the participant and the database can be recorded in the form of a mapping table, and the participant ID and the name of the corresponding database are recorded as a record in the mapping table; the central party determines the name of the first database corresponding to the first participant by looking up the table.

[0052] The central party determines a write thread (hereinafter referred to as the first write thread for distinction) from multiple write threads in the thread pool based on the first participant ID, which is used to execute the write task of the first participant. The thread pool includes multiple write threads, and each write thread is used to execute the write task of writing data into the database. It should be noted that the number of write threads in the thread pool can be set as needed. In order to improve the writing efficiency, more than one write thread needs to be set; in some embodiments, the number of write threads can also be constrained to avoid waste of resources caused by too many write threads. For example, the number of write threads can be set to be less than the number of participants. The thread pool can be started when the central party starts, and the number of write threads in the thread pool can be changed or fixed subsequently.

[0053] There are many ways for the central party to determine the first writing thread from the thread pool. For example, a writing thread can be randomly selected from the thread pool as the first writing thread, or a writing thread that currently has no writing task in the thread pool can be randomly selected as the first writing thread.

[0054] Furthermore, in one embodiment, a scheduling method for each write thread in a scheduling thread pool can be pre-set as needed. The scheduling method is not specifically limited in this embodiment, but in order to further improve the writing efficiency of multiple participants, the scheduling method needs to meet a condition, that is, when scheduling according to the scheduling method, multiple write tasks of the same participant will not be executed by different write threads at the same time. For example, the scheduling method can be set to: detect whether each write thread in the thread pool currently has an unfinished write task for the first participant. If so, the write thread with the unfinished write task of the first participant will be used as the first write thread. If not, a write thread can be randomly selected from the thread pool as the first write thread, or a write thread that currently has no write task in the thread pool can be randomly selected as the first write thread. It can be understood that there are many scheduling methods that can meet this condition, and they are not listed here one by one. When multiple write tasks for a participant are executed by multiple write threads at the same time, the database only allows one write thread to write at a time. Therefore, while one write thread is executing its write task, the other write threads are waiting. This means that the participant has occupied multiple write threads, causing other participants' write tasks to be assigned to these occupied write threads to also waste time waiting for execution. This problem can be avoided by setting a scheduling method to ensure that multiple write tasks for the same participant are not executed by different write threads at the same time, thereby further improving the efficiency of multi-party database writing.

[0055] Step S30: Call the first writing thread to write the data to be written by the first participant into the first database.

[0056] After determining the first writing thread, the central party can call the first writing thread to execute this writing task, that is, to write the data to be written by the first participant into the first database. The first participant can carry the data to be written in the writing request sent to the central party, and the central party parses the data to be written from the writing request; or the central party can respond to the first participant after receiving the writing request from the first participant, and the first participant sends the data to be written to the central party after receiving the response. The central party calls the first writing thread to write the data to be written into the first database, specifically by indexing the first database according to the name of the first database, and then executing the writing of the data to be written into the first database.

[0057] It should be noted that each write thread will start executing the next write task only after completing a write task, that is, a write thread will not execute two write tasks at the same time. In one embodiment, when the first write thread has a write task that is being executed or queued, the central party can call the first write thread to queue the current write task for execution after the write task that is being executed or queued. In other embodiments, the write tasks submitted by each participant can also have priorities. The central party calls the first write thread to execute each write task according to the priority of each write task, with the higher priority task being executed first and the lower priority task being executed later.

[0058] In this embodiment, by setting up a thread pool including multiple write threads, the central party receives the write request of the first participant, parses the first participant ID from the write request, obtains the name of the first database corresponding to the first participant based on the first participant ID, and determines the first write thread from the multiple write threads in the thread pool based on the first participant ID, and calls the first write thread to write the first participant's to-be-written data into the first database. This enables multiple write threads to respectively execute the write tasks of different participants, and by setting up the central party to provide a one-to-one corresponding database for each participant, when multiple write threads respectively execute the write tasks of different participants, there will be no situation of writing to a database at the same time, thereby enabling multiple write threads to simultaneously execute the write tasks of different participants, and further, when the database has a restriction that only allows a single process to write at the same time, the write efficiency of multiple participants when writing to the database can be improved.

[0059] Furthermore, in one embodiment, the step of obtaining the name of the first database corresponding to the first participant based on the first participant ID in step S20 includes:

[0060] Step S201, searching whether there is a database corresponding to the first participant ID;

[0061] Step S202: If it exists, use the database corresponding to the first participant ID as the first database, and obtain the name of the first database;

[0062] Step S203: If the database does not exist, a new database is created, and the newly created database is used as the first database, and the name of the first database is obtained.

[0063] When the central party newly connects to a participant, the database corresponding to the participant may not have been established yet. In this regard, after parsing the first participant ID, the central party can first search whether there is a database corresponding to the first participant ID, specifically, whether there is a database name corresponding to the first participant ID. If it exists, the central party can directly use the database corresponding to the first participant ID as the first database and obtain the name of the first database. If it does not exist, the central party can create a new database, associate the database with the first participant, and use the database as the first database to obtain the name of the first database. Among them, the central party pre-sets the correspondence between the ID of each participant and the database name. One participant ID corresponds to one or more database names, and different participant IDs correspond to different database names; when one participant ID corresponds to multiple database names, one can choose one from them. It should be noted that the names of the various databases are different to avoid confusion.

[0064] Further, in one embodiment, referring to Figure 2 The data writing method can be applied to a central party in an SGX centralized trusted computing scenario, where the central party communicates with all participating parties. SGX uses a new set of instruction set extensions and access control mechanisms to achieve isolated execution between different programs, protecting the confidentiality and integrity of user-critical code and data from malware. It aims to provide a trusted execution environment in user space, relying on hardware security as a mandatory guarantee, independent of the security state of firmware and software. An SGX centralized trusted computing scenario involves multiple participants and a central party. Participants are task initiators, while the central party is the task executor. Participants need to upload data for joint computations (such as joint query, joint modeling, and joint prediction) to the central party before performing the joint computation task. A first participant sends a data upload request (also known as a write request) to the central party. For example, when performing a joint query task, a participant needs to write data to the central party's SQLite database in advance to facilitate user execution of SQL (Structured Query Language) statements. In this case, a data upload request can be sent to the central party. The data upload request can include the first participant's ID and the data to be written to the database. After receiving the data upload request sent by the first participant, the center party extracts the data that needs to be written into the database as the data to be written from the data upload request, and extracts the ID of the first participant from the data upload request.

[0065] In one embodiment, the central party can provide a data upload interface to each participant, and the participant can send a data upload request to the central party by calling the data upload interface. Furthermore, the central party can pre-start a data upload module, which includes a data upload service and a thread pool. The data upload service is used to provide a data upload interface and a scheduling thread. Each write thread in the thread pool is responsible for writing data to the database, and the scheduling thread is responsible for scheduling the write task to the corresponding write thread. The participant executes the data upload task and sends a data upload request to the central party by calling the data upload interface to invoke the central party's data upload service. The central party parses the participant information in the data upload request and the data to be uploaded to the database based on the data upload service.

[0066] Since there are few software that can adapt to run in the SGX environment, common database engines such as PostgreSQL, MySQL and Oracle currently do not support the SGX environment. Therefore, the embedded database engine SQLite is used in the SGX centralized trusted computing scenario. However, SQLite only allows a single thread to write to the database at the same time, resulting in low write efficiency when multiple participants write to the database. In this embodiment, a thread pool including multiple write threads is set in the central party of the SGX centralized trusted computing scenario. When a data upload request from a participant is received, the participant ID in the data upload request is extracted, and the first write thread is determined from the thread pool according to the participant ID. The first write thread is called to execute the writing of the data to be written by the first participant into the first database, so that multiple write threads can respectively execute the write tasks of different participants; and by setting different participants to correspond to different databases, the name of the first database corresponding to the participant ID is found, and the first write thread is called to execute the writing task of writing the data to be written into the first database, so that when multiple write threads respectively execute the write tasks of different participants, there will be no situation of writing to the same database at the same time, thereby enabling multiple write threads to execute the write tasks of different participants at the same time; thereby achieving the goal of improving the writing efficiency of multiple participants when writing to the database when the database used in the SGX centralized trusted computing scenario has the restriction that only a single process is allowed to write at the same time.

[0067] Example 2

[0068] Based on the above-mentioned embodiment 1, the step of determining the first writing thread from multiple writing threads in the thread pool based on the first participant ID in step S20 of the data writing method in the above-mentioned embodiment may include steps S204 and S205. This situation is described below. In this embodiment, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above description and will not be described in detail. In step S204, the first participant ID is modulo the total number of writing threads in the thread pool to obtain a modulo result;

[0069] Step S205: Use the write thread with the thread number of the remainder result in the thread pool as the first write thread.

[0070] The IDs of each participant can be incremental, that is, the IDs of each participant are arranged in an ascending manner. For example, the IDs of the three participants are 9997, 9998, and 9999. The IDs of each participant can be pre-arranged in an ascending manner and built into each participant. When a participant sends a write request to the central party, it can also send its own ID to the central party so that the central party can obtain the participant's ID.

[0071] After the central party resolves and obtains the first participant ID, it can take the remainder of the first participant ID and the total number of write threads in the thread pool to obtain the remainder result, and use the write thread in the thread pool whose thread number is the remainder result as the first write thread. Since the total number of write threads in the thread pool is fixed, the remainder result calculated based on the same ID is the same, and thus the write tasks of the same participant will all be scheduled to the same write thread, so that multiple write tasks of the same participant will not be executed by different write threads at the same time.

[0072] In this embodiment, the scheduling method of obtaining the number of the first writing thread by taking the modulus of the total number of writing threads according to the incremental first participant ID is a scheduling method that can meet the condition that multiple writing tasks of the same participant will not be executed by different writing threads at the same time. This scheduling method can avoid the situation where when multiple writing tasks of the same participant are executed by different writing threads at the same time, the database only allows one writing thread to write at the same time, causing other writing threads to spend time waiting for execution, thereby further improving the writing efficiency of multiple parties writing to the database.

[0073] Furthermore, in one embodiment, determining the first writing thread from multiple writing threads in the thread pool based on the first participant ID in step S20 may include:

[0074] Step S206: Find a first ranking corresponding to the first participant ID, wherein the first ranking is the ranking of the first visit time of the first participant among the first visit times of the participants;

[0075] Step S207, taking the remainder of the total number of write threads in the thread pool based on the first sorting, to obtain a remainder result;

[0076] Step S208: Use the write thread with the thread number of the remainder result in the thread pool as the first write thread.

[0077] When the IDs of the participants are not arranged in an ascending order, for example, the IDs of the three participants are 4444, 5555, and 6666, respectively, the central party can record the time when each participant first calls the data write service provided by the central party to access the database, record it as the first access time, sort the participants according to the order of their first access time, and correspond the participant's order to the participant's ID one by one. Furthermore, in one embodiment, the central party can use a dictionary data structure to record the order of each participant's ID and first access time in the first access time of each participant, using the participant's ID as the key and the order as the value. For example, the value starts increasing from 0. Assuming that the IDs of the three participants are 4444, 5555, and 6666, respectively, and they are sorted according to the order of their first access time, with the sorting numbers being 0, 1, and 2, respectively, then the dictionary data structure at this time is {"4444":"0","5555":"1","6666":"2"}). After the central party resolves and obtains the first participant ID, it searches the dictionary data structure for the order corresponding to the ID (called the first order for distinction) based on the first participant ID.

[0078] Once the central party obtains the first ranking corresponding to the first participant ID, it can take the remainder of the first ranking and the total number of write threads in the thread pool to obtain the remainder result. The write thread in the thread pool whose thread number is the remainder result is used as the first write thread. Since the total number of write threads in the thread pool is fixed, the remainder results calculated based on the same ranking are the same, and thus, the write tasks of the same participant will all be scheduled to the same write thread, thus preventing multiple write tasks of the same participant from being executed by different write threads at the same time.

[0079] In this embodiment, when the ID of each participant is not an incremental ID, by sorting the participants according to their first access time, taking the modulus of the sorting number and the total number of write threads, and using the write thread in the thread pool with the thread number of the modulus result as the first write thread, it is possible to avoid multiple write tasks of the same participant being executed by different write threads at the same time, thereby further improving the write efficiency of multiple participants writing to the database.

[0080] Example 3

[0081] Based on the above-mentioned embodiment 1 and / or embodiment 2, the data writing method step S30 in the above-mentioned embodiment may further include step S301, and this case is described below. In this embodiment, the same or similar contents as those in the above-mentioned embodiment 1 can be referred to the above description and will not be repeated hereafter.

[0082] Step S301: Send the name of the first database to the first writing thread, and schedule the data to be written by the first participant to the first writing thread, so as to call the first writing thread to execute the writing task of writing the data to be written into the first database according to the name of the first database.

[0083] The central party invokes the first write thread to write the data to be written into the first database. Specifically, the central party may send the name of the first database to the first write thread and schedule the data to be written by the first participant to the first write thread, thereby invoking the first write thread to execute the write task of writing the data to be written into the first database according to the name of the first database. After receiving the name of the first database and the data to be written, the first write thread, after completing other priority write tasks, writes the data to be written into the database corresponding to the name of the first database, that is, into the first database.

[0084] Furthermore, in one embodiment, step S30 may further include:

[0085] Step S302: Call the first writing thread to create a new first data table in the first database, and execute a writing task of writing the to-be-written data of the first participant into the first data table.

[0086] After the central party determines the first database and the first writing thread, it can call the first writing thread to create a new data table in the first database (hereinafter referred to as the first data table for distinction), and call the first writing thread to execute the writing task of writing the data to be written by the first participant into the first data table. Specifically, in one embodiment, the central party can create a new data table in the database each time it calls the writing thread to write data to the database, so as to write the data to be written into the newly created data table, thereby increasing the speed at which the writing thread executes the writing task. In other embodiments, it can also be determined whether to create a new data table or to update the existing data table based on the specific circumstances of the data to be written.

[0087] Furthermore, in one embodiment, after step S302, the data writing method further includes:

[0088] Step S303, detecting whether the first data table is a replacement data table of the second data table in the first database;

[0089] Step S304: If yes, delete the second data table.

[0090] In this embodiment, when a participant wants to update all or part of the data in a data table in the database corresponding to the participant, it can first locally update all or part of the data in the data table stored locally by the participant (hereinafter referred to as the local data table data), use the updated local data table as a replacement data table for the data table in the database, and send the replacement data table as the data to be written to the database to the central party. When the central party determines that the data to be written is a replacement data table for a data table in the database corresponding to the first participant (hereinafter referred to as the second data table), it calls the first write thread to write the data to be written to the newly created first data table, and then deletes the second data table to update the data in the second data table in the database. It can be understood that in this embodiment, if the data to be written is not a replacement data table for any data table in the database corresponding to the first participant, then the central party calls the first write thread to write the data to be written to the first data table, and there is no need to perform the data table deletion operation. Furthermore, when the participant sends the data to be written to the central party, it can inform the central party that the data to be written is a replacement data table for the second data table by means of an indicator or the like.

[0091] In this embodiment, when the data to be written is a replacement data table for the second data table in the database corresponding to the first participant, the first writing thread is called to write the data to be written into the newly created first data table, and then the second data table is deleted. Therefore, when the first participant wants to update the data in a certain data table in the database, the updated data table can be sent to the central party as a replacement data table, so that the central party can quickly complete the data writing task by writing the new data table and deleting the old data table, thereby further improving the data writing efficiency.

[0092] Furthermore, in one embodiment, before step S302, the data writing method further includes:

[0093] Step S305, determining whether the data to be written by the first participant is update data of part of the data in the third data table in the first database;

[0094] In this embodiment, when a participant wants to update part of the data in a data table in the database corresponding to the participant, only the data to be updated can be sent to the central party as the data to be written.

[0095] The central party may first determine whether the data to be written is an update of part of the data in any data table (hereinafter referred to as the third data table for distinction) in the first database corresponding to the first participant. Furthermore, when the participant sends the data to be written to the central party, it may inform the central party, for example, by means of an indicator, that the data to be written is an update of a particular data table.

[0096] Step S306: If yes, calling the first writing thread to execute the writing task of updating the third data table with the data to be written;

[0097] If not, execute step S302.

[0098] If it is determined that the data to be written is an update of part of the data in the third data table in the first database corresponding to the first participant, the central party may call the first write thread to execute the write task of updating the third data table with the data to be written. If it is determined that the data to be written is not an update of any data table in the first database corresponding to the first participant, the central party may call the first write thread to create a new first data table in the database corresponding to the first participant, and call the first write thread to execute the write task of writing the data to be written into the first data table.

[0099] In this embodiment, when the data to be written is update data of part of the data in the target data table in the corresponding database of the first participant, the first write thread is called to execute the write task of updating the target data table using the data to be written, so that the participant can only update part of the data in the data table in the corresponding database. When the amount of data to be updated is small, the data writing efficiency of the participant in writing to the database can be further improved.

[0100] Example 4

[0101] Corresponding to the above-mentioned embodiments 1, 2, and 3, an embodiment of the present invention further provides a data writing system, which is deployed in a central party in a centralized trusted computing scenario. The central party is in communication with at least one participant, and the central party provides a one-to-one corresponding database for each participant. For any first participant among the participants, the data writing system includes:

[0102] a receiving module, configured to receive a write request from the first participant and parse the write request to obtain the first participant ID;

[0103] an acquisition module, configured to acquire a name of a first database corresponding to the first participant based on the first participant ID, and determine a first write thread from a plurality of write threads in a thread pool based on the first participant ID;

[0104] A writing module is used to call the first writing thread to write the data to be written by the first participant into the first database.

[0105] Furthermore, the acquisition module includes:

[0106] A first search unit, configured to search for a database corresponding to the first participant ID;

[0107] a first acquiring unit, configured to use the database corresponding to the first participant ID as the first database, if any, and acquire a name of the first database;

[0108] The second acquiring unit is configured to create a new database if the first database does not exist, use the newly created database as the first database, and acquire the name of the first database.

[0109] Furthermore, when the ID of each participant is an incremental ID, the acquisition module includes:

[0110] A first calculation unit is configured to obtain a remainder result by taking the modulus of the first participant ID and the total number of write threads in the thread pool;

[0111] The first determining unit is configured to select a writing thread in the thread pool whose thread number is the modulo result as a first writing thread.

[0112] Furthermore, the acquisition module includes:

[0113] a second searching unit, configured to search for a first ranking corresponding to the first participant ID, wherein the first ranking is the ranking of the first visit time of the first participant among the first visit times of the participants;

[0114] A second calculation unit is configured to obtain a remainder result by taking the modulo of the total number of write threads in the thread pool according to the first sorting operation;

[0115] The second determining unit is configured to select a writing thread in the thread pool whose thread number is the modulo result as a first writing thread.

[0116] Furthermore, the writing module is further configured to:

[0117] The name of the first database is sent to the first writing thread, and the data to be written by the first participant is scheduled to the first writing thread, so as to call the first writing thread to execute the writing task of writing the data to be written into the first database according to the name of the first database.

[0118] Furthermore, the writing module is further configured to:

[0119] The first writing thread is called to create a new first data table in the first database, and execute a writing task of writing the to-be-written data of the first participant into the first data table.

[0120] Furthermore, the data writing system further includes:

[0121] a detection module, configured to detect whether the first data table is a replacement data table of the second data table in the first database;

[0122] A deleting module is configured to delete the second data table if yes.

[0123] Furthermore, the data writing system further includes:

[0124] A judgment module, configured to judge whether the data to be written by the first participant is update data of part of the data in the third data table in the first database;

[0125] The writing module is also used to call the first writing thread to execute the writing task of updating the third data table with the data to be written if yes; if not, call the first writing thread to create a new first data table in the first database, and execute the writing task of writing the data to be written of the first participant into the first data table.

[0126] Among them, in the embodiments of the present invention, for the contents that are the same as or corresponding to the first, second or third embodiments, please refer to the above introduction and will not be repeated later.

[0127] The data writing system of the present invention utilizes the data writing method provided in the first embodiment above, resolving the technical issue of low write efficiency when multiple parties write to a database, caused by the database only allowing a single process to write at a time. Compared to the prior art, the data writing system provided in this embodiment of the present invention achieves the same beneficial effects as the data writing method provided in the first embodiment above. Other technical features of this system are the same as those disclosed in the method of the previous embodiment and are not further elaborated here.

[0128] Example 5

[0129] An embodiment of the present invention provides an electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the data writing method in the above-mentioned embodiment 1.

[0130] Reference below Figure 3 , which shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present disclosure. The electronic devices in the embodiments of the present disclosure may include, but are not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 3 The electronic device shown is only an example and should not limit the functions and scope of use of the embodiments of the present disclosure.

[0131] like Figure 3 As shown, the electronic device may include a processing device (such as a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) or a program loaded from a storage device into a random access memory (RAM). In the RAM, various programs and data required for the operation of the electronic device are also stored. The processing device, ROM, and RAM are connected to each other via a bus. An input / output (I / O) interface is also connected to the bus.

[0132] Typically, the following systems can be connected to the I / O interface: input devices such as a touch screen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; output devices such as a liquid crystal display (LCD), speaker, vibrator, etc.; storage devices such as a magnetic tape, hard disk, etc.; and communication devices. The communication device can allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although the figures show electronic devices with various systems, it should be understood that it is not required to implement or have all of the systems shown. More or fewer systems may be implemented or have instead.

[0133] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device, or installed from a ROM. When the computer program is executed by a processing device, the above-mentioned functions defined in the method of the embodiment of the present disclosure are performed.

[0134] The electronic device provided by the present invention adopts the data writing method of the above-mentioned embodiment 1, embodiment 2 or embodiment 3 to solve the technical problem of low writing efficiency when multiple parties write to the database because the database only allows a single process to write at the same time.

[0135] Compared with the prior art, the beneficial effects of the electronic device provided by the embodiment of the present invention are the same as the beneficial effects of the data writing method provided by the above-mentioned embodiment 1, and the other technical features in the electronic device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0136] It should be understood that various parts of the present disclosure can be implemented with hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in an appropriate manner.

[0137] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in the present invention should be included in the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be based on the scope of protection of the claims.

[0138] Example 6

[0139] This embodiment provides a computer-readable storage medium having computer-readable program instructions stored thereon, and the computer-readable program instructions are used to execute the data writing method in the above-mentioned embodiment 1.

[0140] The computer-readable storage medium provided in the embodiment of the present invention can be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination thereof. More specific examples of computer-readable storage media can include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in combination with an instruction execution system, system or device. The program code contained on the computer-readable storage medium can be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination thereof.

[0141] The computer-readable storage medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.

[0142] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by an electronic device, the electronic device: obtains at least two Internet Protocol addresses; sends a node evaluation request including the at least two Internet Protocol addresses to a node evaluation device, wherein the node evaluation device selects an Internet Protocol address from the at least two Internet Protocol addresses and returns it; receives the Internet Protocol address returned by the node evaluation device; wherein the obtained Internet Protocol address indicates an edge node in a content distribution network.

[0143] Alternatively, the computer-readable storage medium carries one or more programs, which, when executed by an electronic device, causes the electronic device to: receive a node evaluation request including at least two Internet Protocol addresses; select an Internet Protocol address from the at least two Internet Protocol addresses; and return the selected Internet Protocol address; wherein the received Internet Protocol address indicates an edge node in a content distribution network.

[0144] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0145] The flow charts and block diagrams in the accompanying drawings illustrate the possible implementation architecture, functions and operations of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, program segment, or a part of code, and the module, program segment, or a part of code contains one or more executable instructions for realizing 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 than that marked in the accompanying drawings. For example, two boxes represented in succession 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 flow chart, and the combination of the boxes in the block diagram and / or flow chart, can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0146] The modules involved in the embodiments described in this disclosure may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.

[0147] The computer-readable storage medium provided by the present invention stores computer-readable program instructions for executing the aforementioned data writing method, resolving the technical issue of low write efficiency when multiple parties write to a database because the database only allows a single process to write at a time. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided by the embodiments of the present invention are similar to those of the data writing methods provided by the aforementioned first, second, or third embodiments, and are not further elaborated here.

[0148] The present invention also provides a product, which is a computer program product, including a computer program, and when the computer program is executed by a processor, the steps of the data writing method as described above are implemented.

[0149] The computer program product provided by the present invention solves the technical problem of low write efficiency when multiple parties write to a database because only a single process is allowed to write to the database at the same time. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in the embodiments of the present invention are the same as the beneficial effects of the data writing methods provided in the first, second, or third embodiments above, and are not further described here.

[0150] The above are only preferred embodiments of the present invention and are not intended to limit the patent scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention description and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent scope of the present invention.

Claims

1. A data writing method, characterized in that: A central party is applied to a centralized trusted computing scenario, wherein the central party is in communication with at least one participant, each of the participants serves as a writer, and the central party provides a one-to-one database for each participant. For any first participant among the participants, the data writing method includes: receiving a write request from the first participant, and parsing the first participant ID from the write request; Obtaining a name of a first database corresponding to the first participant based on the first participant ID, and determining a first write thread from a plurality of write threads in a thread pool based on the first participant ID; Calling the first writing thread to write the to-be-written data of the first participant into the first database; The step of determining the first writing thread from multiple writing threads in the thread pool based on the first participant ID includes: If each writing thread in the thread pool currently has an unfinished writing task of the first participant, the writing thread with the unfinished writing task of the first participant is used as the first writing thread; If none of the write threads in the thread pool currently has any unfinished write tasks of the first participant, then a write thread is randomly selected from the thread pool as the first write thread, or, a write thread that currently has no write tasks in the thread pool is randomly selected as the first write thread.

2. The data writing method according to claim 1, wherein: The step of obtaining the name of the first database corresponding to the first participant based on the first participant ID includes: Searching whether there is a database corresponding to the first participant ID; If it exists, use the database corresponding to the first participant ID as the first database, and obtain the name of the first database; If it does not exist, a new database is created and used as the first database, and the name of the first database is obtained.

3. The data writing method according to claim 1, wherein: When the ID of each participant is an incremental ID, the step of determining the first write thread from multiple write threads in the thread pool based on the first participant ID includes: Taking the remainder of the first participant ID and the total number of write threads in the thread pool to obtain a remainder result; The thread numbered as the write thread of the remainder result in the thread pool is used as the first write thread.

4. The data writing method according to claim 1, wherein: The step of determining the first writing thread from multiple writing threads in the thread pool based on the first participant ID includes: Finding a first ranking corresponding to the first participant ID, wherein the first ranking is the ranking of the first visit time of the first participant among the first visit times of the participants; Taking the remainder of the total number of write threads in the thread pool after performing the first sorting operation, and obtaining a remainder result; The thread numbered as the write thread of the remainder result in the thread pool is used as the first write thread.

5. The data writing method according to any one of claims 1 to 4, characterized in that: The step of calling the first writing thread to write the to-be-written data of the first participant into the first database includes: The name of the first database is sent to the first writing thread, and the data to be written by the first participant is scheduled to the first writing thread, so as to call the first writing thread to execute the writing task of writing the data to be written into the first database according to the name of the first database.

6. The data writing method according to claim 5, wherein: The step of calling the first writing thread to write the to-be-written data of the first participant into the first database further includes: The first writing thread is called to create a new first data table in the first database, and execute a writing task of writing the to-be-written data of the first participant into the first data table.

7. The data writing method according to claim 6, wherein: After the step of calling the first writing thread to create a new first data table in the first database and executing the writing task of writing the to-be-written data of the first participant into the first data table, the data writing method further includes: detecting whether the first data table is a replacement data table of the second data table in the first database; If yes, delete the second data table.

8. The data writing method according to claim 6 or 7, wherein: Before the step of calling the first writing thread to create a new first data table in the first database and executing the writing task of writing the to-be-written data of the first participant into the first data table, the data writing method further includes: Determining whether the data to be written by the first participant is update data of part of the data in the third data table in the first database; If so, calling the first writing thread to execute the writing task of updating the third data table with the data to be written; If not, the step of calling the first writing thread to create a new first data table in the first database and executing the writing task of writing the to-be-written data of the first participant into the first data table is executed.

9. A data writing system, characterized in that: A central party deployed in a centralized trusted computing scenario is in communication with at least one participant, and the central party provides a one-to-one database for each participant. For any first participant among the participants, the data writing system includes: a receiving module, configured to receive a write request from the first participant and parse the write request to obtain the first participant ID; an acquisition module, configured to acquire a name of a first database corresponding to the first participant based on the first participant ID, and determine a first write thread from a plurality of write threads in a thread pool based on the first participant ID; a writing module, configured to call the first writing thread to write the to-be-written data of the first participant into the first database; The acquisition module is further used for: If each writing thread in the thread pool currently has an unfinished writing task of the first participant, the writing thread with the unfinished writing task of the first participant is used as the first writing thread; If none of the write threads in the thread pool currently has any unfinished write tasks of the first participant, then a write thread is randomly selected from the thread pool as the first write thread, or, a write thread that currently has no write tasks in the thread pool is randomly selected as the first write thread.

10. An electronic device, characterized in that: The electronic device comprises: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the steps of the data writing method according to any one of claims 1 to 8.

11. A readable storage medium, characterized in that: The readable storage medium stores a program for implementing the data writing method, and the program for implementing the data writing method is executed by a processor to implement the steps of the data writing method according to any one of claims 1 to 8.

12. A product, said product being a computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the data writing method according to any one of claims 1 to 8 are implemented.

Citation Information

Patent Citations

  • Message processing method and system

    CN105930397A

  • Generation method and system for three-layer associated information, electronic equipment and storage medium

    CN110990168A