Data storage method and device of distributed system, electronic equipment and storage medium
By creating serial number microservices in a distributed system, dynamically generate the working serial number of the application microservices and combining the snowflake algorithm to generate primary keys, the problem of difficult to obtain working serial numbers in the distributed microservice architecture is solved, and the global uniqueness of the primary key and data processing efficiency are improved.
Patent Information
- Application Number
- CN202411603384.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-11
- Publication Date
- 2025-03-04
AI Technical Summary
In a distributed microservice architecture, it is difficult for microservice instances on multiple nodes to obtain unique working sequence numbers, resulting in a complex process of generating global unique identification.
通过创建一个序号微服务,动态生成所有应用微服务的工作序号,并基于雪花算法生成目标数据的主键,进而存储到数据库中。
It reduces the difficulty of obtaining work sequence numbers for application microservices, ensures the uniqueness of work sequence numbers, thereby ensuring the global uniqueness of primary keys, and improving the data primary key generation efficiency and the data processing efficiency of distributed systems.
Smart Images

Figure CN119557374A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed technology, and in particular to a data storage method, device, electronic device and storage medium for a distributed system. Background Art
[0002] With the development of economy, the transaction volume and data volume of industries including finance are also growing rapidly. Traditional centralized databases face severe challenges in processing massive data and high concurrent access. Therefore, distributed architectures using unitized deployment or sharding of databases and tables have emerged to cope with the growth of transaction volume and data volume.
[0003] Based on the distributed architecture, the database auto-increment sequence as the database primary key cannot meet the global uniqueness requirements, so in a distributed database, generating a globally unique identifier (such as ID) is a challenge. Common solutions include database UUID, Redis generated ID, snowflake algorithm, etc. Among them, the snowflake algorithm (Snowflake) can generate a long integer with a length of 17-19 digits, and a single node supports 4096 concurrent connections. Based on time increment and overall order of primary keys, it can ensure storage and query efficiency, so the snowflake algorithm is widely used.
[0004] However, when using the snowflake algorithm to generate a globally unique identifier, different work numbers need to be configured for different microservice instances to ensure the uniqueness of the numbers. In a distributed microservice architecture, it is difficult to obtain unique work numbers for microservice instances on multiple nodes, making the generation process of a globally unique identifier complicated. Summary of the invention
[0005] The embodiments of the present application provide a data storage method, device, electronic device and storage medium for a distributed system, so as to reduce the difficulty of obtaining the work sequence number of each application microservice, ensure the uniqueness of each work sequence number, and achieve the effect of improving data processing efficiency.
[0006] In a first aspect, an embodiment of the present application provides a data processing method for a distributed system, comprising:
[0007] In response to a storage instruction of the target data, determining a target application microservice where a database where the target data is stored is located;
[0008] Obtaining the working sequence number of the target application microservice based on the sequence number microservice;
[0009] Generate a primary key of the target data based on a primary key generation component and the work sequence number;
[0010] The target data is stored in the database according to the target data and a primary key of the target data.
[0011] In a possible implementation, the obtaining the working sequence number of the target application microservice based on the sequence number microservice includes:
[0012] Based on the work sequence number table generated by the sequence number microservice, the work sequence number of the target application microservice is obtained, and the work sequence number table is used to record the work sequence numbers of all application microservices.
[0013] In a possible implementation manner, before determining, in response to the storage instruction of the target data, the target application microservice where the database where the target data is stored is located, further includes:
[0014] In response to a start instruction of a target application microservice, calling a sequence number microservice to generate a working sequence number of the target application microservice;
[0015] Check whether there is a corresponding work number from the work number table;
[0016] If not, saving the work sequence number of the target application microservice into the work sequence number table;
[0017] If so, the sequence number microservice is called to regenerate the working sequence number of the target application microservice.
[0018] In a possible implementation, the sequence number microservice generates a working sequence number for the target application microservice, including:
[0019] Obtain application parameters of the target application microservice, where the application parameters include at least one of the target application microservice name, IP address, and port;
[0020] A work sequence number of the target application microservice is generated based on the application parameters.
[0021] In a possible implementation, generating the work sequence number of the target application microservice based on the application parameter includes:
[0022] A hash calculation is performed on the application parameter, and the obtained hash value is determined as the working sequence number of the target application microservice.
[0023] In a possible implementation manner, before determining, in response to the storage instruction of the target data, the target application microservice where the database where the target data is stored is located, further includes:
[0024] Build a serial number microservice to obtain the registration center information of each application microservice;
[0025] Based on the registration center information, the sequence number microservice is registered so that the sequence number microservice is associated with each application microservice in the same system.
[0026] In a second aspect, an embodiment of the present application provides a data processing device for a distributed system, comprising:
[0027] A determination module, configured to determine, in response to a storage instruction of the target data, a target application microservice where a database in which the target data is stored is located;
[0028] An acquisition module, used to obtain the working sequence number of the target application microservice based on the sequence number microservice;
[0029] A primary key generation module, which generates a primary key of the target data based on a primary key generation component and the work sequence number;
[0030] A data processing module is used to store the target data in the database according to the target data and the primary key of the target data.
[0031] In a third aspect, an embodiment of the present application provides an electronic device, including: a memory, a processor;
[0032] The memory stores computer-executable instructions;
[0033] The processor executes the computer-executable instructions stored in the memory, so that the processor executes the above first aspect and / or various possible implementations of the first aspect.
[0034] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement various possible implementation methods of the first aspect above.
[0035] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program, which, when executed by a processor, implements various possible implementation methods of the first aspect above.
[0036] The data storage method, device, electronic device and storage medium of the distributed system provided by the embodiments of the present application generate the working sequence number of the application microservice through the sequence number microservice. When the application microservice stores and processes the target data, the working sequence number can be directly obtained, and the primary key of the target data is generated based on the snowflake algorithm, and then the target data is stored in the database based on the primary key. Among them, the sequence number microservice generates the working sequence number of the application microservice, and there is no need to obtain the working sequence number of each application microservice through parameter configuration, which reduces the difficulty of obtaining the working sequence number of each application microservice. Moreover, the working sequence number of each application microservice is uniformly generated based on the sequence number microservice, which can ensure the uniqueness of the working sequence number, and then ensure the global uniqueness of the primary key, so as to improve the generation efficiency of the data primary key while ensuring the global uniqueness of the primary key, thereby improving the data processing efficiency of the distributed system. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0038] Figure 1 A schematic diagram of a distributed system data processing method provided in this application;
[0039] Figure 2 Schematic diagram of the data processing method of the distributed system provided in this application Figure 1 ;
[0040] Figure 3 Schematic diagram of the data processing method of the distributed system provided in this application Figure 2 ;
[0041] Figure 4 A schematic diagram of the structure of a data processing device for a distributed system provided by the present application;
[0042] Figure 5 A schematic diagram of the structure of the electronic device provided in this application.
[0043] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION
[0044] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0045] First, the terms involved in this application are explained:
[0046] Distributed architecture: Divide a large system into multiple subsystems, distribute them to multiple hosts through a computer network, and multiple hosts work together to complete the work.
[0047] Unitized deployment: Units are used as the basic units of system deployment. Each unit can complete all business operations, including all services required for business processing and data assigned to this unit. The advantage of the unitized architecture is that it can limit a business transaction to one deployment unit, avoiding cross-regional and cross-data center calls. In addition, unitized deployment is easy to expand and can support a large number of users.
[0048] Database and table sharding: Split a single database or a single table into multiple databases or multiple tables to solve the performance bottleneck of massive data storage and reading and writing in distributed systems, improve distributed system performance, and enhance availability.
[0049] Database primary key: A combination of one or more columns in a database table that uniquely identifies a row of records in the table.
[0050] Snowflake algorithm: also known as SnowFlake algorithm, is Twitter's open source distributed serial number generation algorithm. The core idea of the Snowflake algorithm is to use a 64-bit long number as a globally unique serial number, which increases according to the time trend and is widely used to create globally unique serial numbers in distributed systems.
[0051] Based on the distributed architecture, globally unique identification (such as ID) is a challenge. Common solutions include database UUID, Redis generated ID, snowflake algorithm, etc. Among them, the snowflake algorithm (Snowflake) can generate a long integer with a length of 17-19 bits, and a single node supports 4096 concurrent connections. Based on time increment and overall order of primary keys, it can ensure storage and query efficiency, so the snowflake algorithm is widely used.
[0052] Snowflake is a distributed ID generation algorithm open sourced by Twitter, which is used to generate a globally unique 64-bit identifier. In the process of generating a globally unique identifier, the Snowflake algorithm first divides the 64-bit ID into four parts, including a sign bit (1 bit), a timestamp (41 bits), a work machine ID (10 bits), and a sequence number (12 bits).
[0053] Among them, the highest bit is the sign bit, which is always 0 and is used to identify that the ID is a positive number. The timestamp can be accurate to the millisecond level and can support 69 years of timestamps, which enables the snowflake algorithm to support uniqueness for decades to come. The timestamp part also provides a sorting function, which can sort the data according to the timestamp. The working machine ID is used to identify different machines or processes. In a distributed environment, each machine needs to be configured with a unique machine ID. These 10 bits can be further subdivided into a data center ID and a working machine ID, each occupying 5 bits, to support up to 32 data centers and up to 32 working nodes in each data center. The sequence number is used to identify different IDs generated in the same millisecond, supporting each node to generate 4096 unique IDs per millisecond.
[0054] After obtaining the characters of the four parts, the timestamp, machine ID and serial number are combined into a 64-bit ID through bit operations, which is a globally unique identifier.
[0055] However, when using the snowflake algorithm to generate a globally unique identifier, different work numbers need to be configured for different microservice instances to ensure the uniqueness of the numbers. In a distributed microservice architecture, it is difficult to obtain unique work numbers for microservice instances on multiple nodes, making the process of generating a globally unique identifier complicated.
[0056] Based on this, the data processing method for a distributed system provided by the present application creates a sequence number microservice to dynamically generate working sequence numbers for all application microservices. When recording data, the working sequence number is directly obtained through the sequence number microservice, and then the primary key of the record is generated based on the snowflake algorithm. This technical means solves the technical problem in related technologies that, in a distributed system, the working sequence number of an application microservice is difficult to obtain and the acquisition method is complicated.
[0057] It should be noted that the data processing method and device of the distributed system of the present application can be used in the field of distributed technology, and can also be used in any field outside the field of distributed technology. The application field of the data processing method and device of the distributed system of the present application is not limited.
[0058] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0059] Figure 1 A scenario diagram of the data processing method of the distributed system provided in the present application, wherein the distributed system includes multiple nodes or devices, each node or device includes multiple application microservices, each application microservice can independently run one or more microservice instances, and each service instance can be responsible for a specific business function. Among them, a sequence number microservice is created in the distributed system, and the sequence number microservice provides a unique working sequence number for each application microservice, so that when each application microservice stores data in the corresponding database, it can generate the primary key of the data based on the working sequence number and the snowflake algorithm, without configuring the relevant parameters in the application microservice to obtain the working sequence number, and under the distributed architecture, the uniqueness of all nodes or devices needs to be considered when configuring the parameters, and the process is relatively complicated. In the present application, the working sequence numbers of all application microservices are generated and managed based on the sequence number microservice, which can reduce the parameter configuration steps of each application microservice and ensure that the working sequence number is not repeated.
[0060] Figure 2 Schematic diagram of the data processing method of the distributed system provided in this application Figure 1 ,like Figure 2 As shown, the method includes:
[0061] S201, in response to a storage instruction of target data, determining a target application microservice where a database where the target data is stored is located;
[0062] It should be noted that the distributed system of the embodiment of the present application can be applied to the financial field, and can also be applied to other fields. In the financial field, for example, it can be applied to the processing of transaction data, including data storage and query.
[0063] In this step, the storage instruction of the target data refers to an instruction to record the target data in the database. In order to facilitate the subsequent rapid search of the target data in the database, a primary key (such as a globally unique identifier) of the target data needs to be generated when recording the target data. The primary key uniquely identifies the storage location of the target data, so the target data can be quickly found from the database through the primary key.
[0064] For databases under a distributed architecture, due to the large amount of data and the large number of distributed nodes, in order to ensure global uniqueness, the generation of primary keys needs to follow certain rules to effectively manage the primary keys.
[0065] In the embodiment of the present application, the snowflake algorithm is used to generate the primary key, and the primary key generated by the snowflake algorithm includes four parts, namely: sign bit, timestamp, work machine ID, and serial number. Among them: the machine work ID is also the work serial number. For a distributed system, each machine or each application microservice needs to be configured with a unique work serial number. Therefore, when recording the target data, it is necessary to determine which database the target data is recorded in, and determine the target application microservice corresponding to the database, and then determine the work serial number of the target application microservice.
[0066] In some embodiments, one application microservice runs and manages one database, so the target application microservice can be determined by the name or serial number of the database.
[0067] In some embodiments, multiple application microservices correspondingly run and manage one database, so the target application microservice can be determined by the name or serial number of the database, the type of target data, and the business type that the application microservice is responsible for.
[0068] S202, obtaining the working sequence number of the target application microservice based on the sequence number microservice;
[0069] In this step, the sequence number microservice is a pre-created microservice used to generate the work sequence number of each application microservice.
[0070] As an example, when recording target data, the sequence number microservice can be called to generate the working sequence number of the target application microservice in real time. Specifically, the sequence number microservice generates the working sequence number of the target application microservice based on the hash algorithm according to the application parameters of the target application microservice.
[0071] As an example, when the system starts or the application microservice starts, the sequence number microservice can be called to generate the work sequence number of each application microservice, and saved in the work sequence table. Then, when recording the target data, after determining the target application microservice for recording the target data, the corresponding work sequence number can be directly obtained from the work sequence table without calculating and generating the work sequence number.
[0072] Optionally, the work sequence number is generated based on the sequence number microservice, which can be called when the application microservice is started. After the application microservice is started, if there are multiple data recording operations, the pre-generated work sequence number can be directly used. There is no need to record and generate the work sequence number each time, thereby reducing the call of the sequence number microservice.
[0073] In this step, the application parameters include at least one of the target application microservice name, IP address and port.
[0074] S203, generating a primary key of target data based on a primary key generation component and a work sequence number;
[0075] Optionally, in this step, the primary key generation component generates the primary key based on the snowflake algorithm. The highest sign bit is 0, which is used to indicate that the ID is a positive number. The timestamp is generated by obtaining the current time, and the timestamp can be accurate to milliseconds. The serial number is used to identify different IDs generated within the same millisecond, so the serial number is randomly generated based on the current time.
[0076] After obtaining the sign bit, timestamp, work sequence number and serial number, the sign bit, timestamp, work sequence number and serial number are combined into the primary key of the target data through bit operation.
[0077] Furthermore, based on the primary key generation component and the work sequence number, the specific implementation method of generating the primary key of the target data can be:
[0078] Get the current time to generate the timestamp, and check whether the timestamp is the same as the last generated timestamp;
[0079] If they are the same, it means that multiple primary keys need to be generated at the same time. In this case, the current sequence number is incremented to obtain a new sequence number;
[0080] Then, based on the sign bit, timestamp, work sequence number and new sequence number, the primary key of the target data is combined through calculation;
[0081] If they are different, it means that this is the first primary key generated at the current time. At this time, it can be distinguished from other primary keys based on the timestamp to meet the global uniqueness requirement of the primary key. The serial number is reset to 0, the timestamp is updated, and the primary key of the target data is combined through calculation based on the sign bit, the updated timestamp, the working sequence number and the sequence number (0). Among them, the serial number is reset to 0 in order to distinguish multiple primary keys by increasing the serial number when multiple primary keys need to be generated at the same time. In ascending order, it is convenient to manage the serial number and ensure the global uniqueness of the primary key.
[0082] S204: Store the target data in a database according to the target data and the primary key of the target data.
[0083] In this step, SQL statements are used to insert the target data into the database. When inserting the target data into the database, the primary key value is associated with the data row where the target data is located, so that the target data is stored in the database. The target data can be queried based on the primary key later.
[0084] The data processing method of a distributed system provided in an embodiment of the present application generates a working sequence number of an application microservice through a sequence number microservice. When the application microservice stores and processes the target data, the working sequence number can be directly obtained, and a primary key of the target data is generated based on a snowflake algorithm, and then the target data is stored in a database based on the primary key. The sequence number microservice generates the working sequence number of the application microservice, so there is no need to obtain the working sequence number of each application microservice through parameter configuration, thereby reducing the difficulty of obtaining the working sequence number of each application microservice. Moreover, the working sequence number of each application microservice is uniformly generated based on the sequence number microservice, which can ensure the uniqueness of the working sequence number, and then ensure the global uniqueness of the primary key, thereby improving the generation efficiency of the data primary key while ensuring the global uniqueness of the primary key, thereby improving the data processing efficiency of the distributed system.
[0085] Figure 3 Schematic diagram of the data processing method of the distributed system provided in this application Figure 2 This embodiment is based on the above embodiment, and the data processing method of the distributed system is described in detail. Figure 3 As shown, the method includes:
[0086] S301, in response to a start instruction of a target application microservice, calling a sequence number microservice to generate a working sequence number of the target application microservice;
[0087] In this embodiment, when the application microservice is started, the sequence number microservice is called to generate the working sequence number of the application microservice, and the corresponding working sequence number is assigned to each application microservice in advance. Therefore, when the application microservice processes the target data, the working sequence number sent by the sequence number microservice can be directly called to generate the primary key of the target data based on the snowflake algorithm.
[0088] As an example, the specific implementation method of the sequence number microservice generating the work sequence number of the target application microservice can be:
[0089] Obtain application parameters of the target application microservice, where the application parameters include at least one of a target application microservice name, an IP address, and a port; and generate a work sequence number of the target application microservice based on the application parameters.
[0090] In some examples, when the target application microservice is started, a work sequence number request is triggered. The sequence number microservice obtains the application parameters of the target application microservice based on the work sequence number request, and then generates a work sequence number for the target application microservice based on the application parameters and preset sequence number generation rules.
[0091] As an example, the sequence number generation rule is a hash calculation rule. For example, after obtaining the IP address of the application microservice, the IP address is hashed, and the obtained hash value is the working sequence number of the target application microservice. Alternatively, in an example of generating a working sequence number based on the target application microservice name, IP address and port, the target application microservice name, IP address and port are first processed to obtain a unified format expression of the target application microservice name, IP address and port, which are sorted and combined in a preset order, and then hashed, and the obtained hash value is used as the working sequence number of the target application microservice.
[0092] S302, querying from the work sequence number table whether there is a corresponding work sequence number;
[0093] If not, execute S303 to save the work sequence number of the target application microservice into the work sequence number table;
[0094] In this embodiment, the sequence number microservice is used to assign work sequence numbers to all application microservices and store the work sequence numbers in the database in the form of a work sequence number table. Therefore, after the microservice generates the work sequence number of the target application microservice, it is necessary to query whether the corresponding work sequence number exists in the work sequence number table to exclude the situation of duplicate work sequence numbers.
[0095] If there is no corresponding work number in the work number table, it means that the work number is the current unique work number. The work number is saved in the work number table, and the work number is associated with the target application microservice, so that when the target application microservice processes the target data, the corresponding work number can be quickly queried based on the work number table.
[0096] If so, the process returns to S301 and calls the sequence number microservice to regenerate the working sequence number of the target application microservice.
[0097] If there is a corresponding work number in the work number table, it means that the work number is repeated with the stored work number. The work number cannot be used as the work number of the target application microservice, and the work number of the target application microservice needs to be regenerated.
[0098] As an example, after adjusting the hash calculation coefficient, the work number of the target application microservice can be regenerated based on the application parameters to obtain a new work number, and then check whether there is a corresponding new work number in the work number table until a unique work number of the target application microservice is generated.
[0099] Optionally, the work sequence number is composed of application parameters and other values, and the regenerated work sequence number can be different from the previously generated work sequence number by adjusting the combination of other values, thereby obtaining a new work sequence number. Then, it is determined whether there is a corresponding new work sequence number in the work sequence number table, until a unique work sequence number of the target application microservice is generated.
[0100] S304, in response to the storage instruction of the target data, determining the target application microservice where the database where the target data is stored is located;
[0101] The specific implementation method of this step is the same as above Figure 2 The specific implementation method of step S201 is the same as that of the embodiment above, and details may be referred to in the above embodiment, which will not be repeated here.
[0102] S305, obtaining the work sequence number of the target application microservice from the work sequence number table generated by the sequence number microservice;
[0103] In this step, the sequence number microservice pre-generates the working sequence number of each application microservice and stores the working sequence number in the working sequence number table. When the data storage operation is to be performed, the working sequence number of the target application microservice is directly obtained from the working sequence number.
[0104] As an example, the specific implementation of this step may be:
[0105] Based on the name or IP address of the target application microservice, the work sequence number of the target application microservice is searched from the work sequence number table.
[0106] Alternatively, in some examples, the sequence number microservice generates a work sequence number for the target application microservice. When the work sequence number is stored in the work sequence number table, a unique identifier of the work sequence number can be configured, and the corresponding work sequence number can be obtained later through the unique identifier.
[0107] S306, generating a primary key of target data based on the primary key generation component and the work sequence number;
[0108] S307. Store the target data in a database according to the target data and the primary key of the target data.
[0109] The specific implementation of the above steps S306 and S307 is the same as the above Figure 2 Steps S203 and S204 in the example are the same, and details may be referred to the above embodiment, which will not be described again.
[0110] Furthermore, before step S301, the method further includes:
[0111] Build a serial number microservice to obtain the registration center information of each application microservice;
[0112] Based on the registration center information, register the serial number microservice so that the serial number microservice is associated with each application microservice in the same system.
[0113] In a distributed system, build a sequence microservice, register the built sequence microservice and application microservice to the same registration center, so that the sequence microservice and each application microservice are associated in the same system. In this way, the sequence microservice can assign corresponding work sequence numbers to each application microservice.
[0114] In this embodiment, the sequence number microservice is used to assign work parameters to each application microservice. On the one hand, there is no need to set work ID parameters in each application microservice to generate a work sequence number. On the other hand, based on the centralized generation of work sequence numbers by the sequence number microservice, it is possible to accurately determine whether the generated work sequence number is repeated, thereby ensuring the uniqueness of the work sequence number of each node / device or each application microservice. When the primary key of the target data is then generated, the unique work sequence number can ensure the global uniqueness of the primary key. Moreover, when the sequence number microservice generates a work sequence number, it saves the work sequence number in the work sequence number table, and can call the work sequence number locally, thereby improving the efficiency of primary key generation and thus improving data processing efficiency.
[0115] In addition, in some examples, the sequence number microservice generates a work sequence number when the application microservice is started. In the subsequent data processing process, only the work sequence number needs to be called. There is no need to call the sequence number microservice to generate a work sequence number every time data is processed. This can reduce network calls, reduce network bandwidth consumption, and ensure the timeliness and concurrency of data processing.
[0116] Figure 4 A structural diagram of a data processing device for a distributed system provided in this application, such as Figure 4 As shown, the data processing device 40 provided in this embodiment includes:
[0117] A determination module 401 is used to determine a target application microservice where a database where the target data is stored is located in response to a storage instruction of the target data;
[0118] An acquisition module 402 is used to obtain a working sequence number of a target application microservice based on a sequence number microservice;
[0119] A primary key generation module 403, used to call the primary key generation component to generate the primary key of the target data based on the work sequence number;
[0120] The data processing module 404 is used to store the target data into the database according to the target data and the primary key of the target data.
[0121] The data processing device of the distributed system provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and this embodiment will not be described in detail here.
[0122] Figure 5 This is a schematic diagram of the structure of the electronic device provided in this application. Figure 5 As shown, the electronic device 50 provided in this embodiment includes: at least one processor 501 and a memory 502. Optionally, the device 50 also includes a communication component 503. The processor 501, the memory 502 and the communication component 503 are connected via a bus 504.
[0123] In a specific implementation process, at least one processor 501 executes the computer-executable instructions stored in the memory 502, so that at least one processor 501 executes the above method.
[0124] The specific implementation process of the processor 501 can be found in the above method embodiment, and its implementation principle and technical effect are similar, so this embodiment will not be repeated here.
[0125] In the above embodiments, it should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be executed by a combination of hardware and software modules in the processor.
[0126] The memory may include a high-speed memory (Random Access Memory, RAM), and may also include a non-volatile memory (Non-volatile Memory, NVM), such as at least one disk memory.
[0127] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.
[0128] The present application also provides a computer program product, including a computer program, which implements the above method when executed by a processor.
[0129] The present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the above method is implemented.
[0130] The above-mentioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic memory, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.
[0131] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can be located in an application specific integrated circuit (Application Specific Integrated Circuits, referred to as: ASIC). Of course, the processor and the readable storage medium can also exist in the device as discrete components.
[0132] The division of units is only a logical function division, and there may be other divisions in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interface, device or unit, which can be electrical, mechanical or other forms.
[0133] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0134] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0135] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, and other media that can store program codes.
[0136] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.
[0137] Finally, it should be noted that those skilled in the art will readily conceive of other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any variations, uses or adaptations of the present application, which follow the general principles of the present application and include common knowledge or customary technical means in the art that are not disclosed in the present application, are not limited to the precise structures described above and shown in the drawings, and may be modified and changed in various ways without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
Claims
1. A data processing method for a distributed system, characterized in that: include: In response to a storage instruction of the target data, determining a target application microservice where a database where the target data is stored is located; Obtaining the working sequence number of the target application microservice based on the sequence number microservice; Generate a primary key of the target data based on a primary key generation component and the work sequence number; The target data is stored in the database according to the target data and a primary key of the target data.
2. The method according to claim 1, characterized in that The obtaining of the working sequence number of the target application microservice based on the sequence number microservice includes: Based on the work sequence number table generated by the sequence number microservice, the work sequence number of the target application microservice is obtained, and the work sequence number table is used to record the work sequence numbers of all application microservices.
3. The method according to claim 2, characterized in that Before determining the target application microservice where the database where the target data is stored is located in response to the storage instruction of the target data, the method further includes: In response to a start instruction of a target application microservice, calling a sequence number microservice to generate a working sequence number of the target application microservice; Check whether there is a corresponding work number from the work number table; If not, saving the work sequence number of the target application microservice into the work sequence number table; If so, the sequence number microservice is called to regenerate the working sequence number of the target application microservice.
4. The method according to claim 3, characterized in that The sequence number microservice generates a work sequence number for the target application microservice, including: Obtain application parameters of the target application microservice, where the application parameters include at least one of the target application microservice name, IP address, and port; A work sequence number of the target application microservice is generated based on the application parameters.
5. The method according to claim 4, characterized in that The generating the work sequence number of the target application microservice based on the application parameter includes: A hash calculation is performed on the application parameter, and the obtained hash value is determined as the working sequence number of the target application microservice.
6. The method according to any one of claims 1 to 5, characterized in that Before the target application microservice in which the database where the target data is stored is determined in response to the storage instruction of the target data, the method further includes: Build a serial number microservice to obtain the registration center information of each application microservice; Based on the registration center information, the sequence number microservice is registered so that the sequence number microservice is associated with each application microservice in the same system.
7. A data processing device for a distributed system, characterized in that: include: A determination module, configured to determine, in response to a storage instruction of the target data, a target application microservice where a database in which the target data is stored is located; An acquisition module, used to obtain the working sequence number of the target application microservice based on the sequence number microservice; A primary key generation module, which generates a primary key of the target data based on a primary key generation component and the work sequence number; A data processing module is used to store the target data in the database according to the target data and the primary key of the target data.
8. An electronic device, characterized in that: include: Memory, processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor performs the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.
Citation Information
Patent Citations
Distributed system-based serial number generation method and apparatus, and electronic device
CN108509433A
Distributed ID generation method based on optimized snowflake algorithm and application
CN114691642A
Identifier generation method and device in distributed system, equipment and medium
CN116610676A