Dynamic fragment indexing method and related device
Through the dynamic sharding index method, the hash ring is used to map data to distributed indexes, and the number of indexes is adjusted when the writing status is abnormal. This solves the problem of low efficiency of high concurrent writing in traditional databases and achieves efficient data storage. and processing.
Patent Information
- Application Number
- CN202410808687.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-21
- Publication Date
- 2024-08-30
AI Technical Summary
In the case of high concurrent writing, traditional databases have low data writing efficiency, and increasing the number of indexes will lead to a waste of storage and computing resources.
The dynamic sharding index method is used to obtain the hash value of the data to be written, map it to multiple indexes in a distributed configuration based on the hash ring, and dynamically adjust the number of indexes when the writing status is abnormal, and update the index hash ring to Optimize index structure.
It improves the efficiency of data reading and writing, avoids waste of resources, and achieves efficient data storage and processing under high concurrency conditions.
Smart Images

Figure CN118568098A
Abstract
Description
Technical Field
[0001] The present application relates to the field of database technology, and in particular to a dynamic sharding indexing method and related devices. Background Art
[0002] An index is a data structure used by the storage engine to quickly find data records. Traditional databases only have one index data structure configured in memory, and all data writes will compete for the lock of the index data structure. Therefore, in the case of high concurrent writes, data write efficiency is low. Therefore, data write efficiency is usually improved by increasing the number of indexes, but too many indexes will cause a waste of storage and computing resources.
[0003] Therefore, how to optimize the index data structure to improve data reading and writing efficiency is a technical problem that needs to be solved urgently by those skilled in the art. Summary of the invention
[0004] In view of the above problems, the present application provides a dynamic sharding indexing method and related devices to achieve the purpose of improving data reading and writing efficiency. The specific scheme is as follows:
[0005] The first aspect of the present application provides a dynamic sharding indexing method, comprising:
[0006] Get the hash value of the data to be written;
[0007] Obtaining an index value of the data to be written based on a hash value of the data to be written;
[0008] Obtaining a write status of a distributed index structure, wherein the distributed index structure includes a plurality of indexes constructed in a distributed manner;
[0009] If the write status is normal, the index corresponding to the data to be written is obtained based on the index hash ring and the hash value of the data to be written, and the index value of the data to be written is written into the index corresponding to the data to be written; the index hash ring is used to configure the mapping relationship between the index and the hash value;
[0010] If the write status is abnormal, the distributed index structure is updated by updating the number of indexes in the distributed index structure, and the index hash ring is updated based on the updated distributed index structure; based on the updated index hash ring and the hash value of the data to be written, the index corresponding to the data to be written is obtained, and the index value of the data to be written is written into the index corresponding to the data to be written.
[0011] In a possible implementation, obtaining the index value of the data to be written based on the hash value of the data to be written includes:
[0012] The hash value of the data to be written and the key value of the data to be written are concatenated to obtain the index value of the data to be written.
[0013] In a possible implementation, the mapping relationship includes a one-to-one correspondence between a hash interval and an index; and obtaining the index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written includes:
[0014] Obtaining a hash interval of the hash value of the data to be written on the index hash ring as a target hash interval;
[0015] The index corresponding to the target hash interval is obtained according to the mapping relationship as the index corresponding to the data to be written.
[0016] In a possible implementation, writing the index value of the data to be written into the index corresponding to the data to be written includes:
[0017] The index value of the data to be written is written into a write queue corresponding to a target index, where the target index is the index corresponding to the data to be written, and the write queue corresponding to the target index is used to write the data in the queue into the target index in sequence.
[0018] In a possible implementation, obtaining the write status of the distributed index structure includes:
[0019] According to a preset cycle, the performance parameters of each write queue are obtained, wherein the performance parameters include a data volume ratio, and the data volume ratio is equal to a ratio of a queue length to a queue capacity;
[0020] Determine whether a preset optimization condition is met according to the performance parameters of each of the write queues, and if the optimization condition is met, determine that the write state of the distributed index structure is abnormal; if the optimization condition is not met, determine that the write state of the distributed index structure is normal;
[0021] The optimization condition includes any one of a first optimization condition and a second optimization condition, wherein the first optimization condition includes that the ratio of the number of congested queues to the total number of write queues is greater than a preset first ratio threshold, and / or there is at least one item in at least one overflow queue; the second optimization condition includes that the ratio of the number of redundant queues to the total number of write queues is greater than a preset second ratio threshold, and / or there is at least one idle queue.
[0022] In a possible implementation, updating the distributed index structure by updating the number of indexes in the distributed index structure, and updating the index hash ring based on the updated distributed index structure includes:
[0023] If the first optimization condition is met, the number of indexes in the distributed index structure is increased to update the distributed index structure, and based on the number of indexes in the updated distributed index structure, the hash intervals of the index hash ring are re-divided, and a corresponding relationship between each index in the updated distributed index structure and each hash interval in the updated index hash ring is established;
[0024] If the second optimization condition is met, the number of indexes in the distributed index structure is reduced to update the distributed index structure, and based on the number of indexes in the updated distributed index structure, the hash intervals of the index hash ring are re-divided, and a correspondence between each index in the updated distributed index structure and each hash interval in the updated index hash ring is established.
[0025] A second aspect of the present application provides a dynamic shard indexing device, including:
[0026] A hash operation unit, used to obtain a hash value of the data to be written;
[0027] An index calculation unit, configured to obtain an index value of the data to be written based on a hash value of the data to be written;
[0028] A write status monitoring unit, used to obtain a write status of a distributed index structure, wherein the distributed index structure includes a plurality of indexes constructed in a distributed manner;
[0029] A first data writing unit is used to obtain the index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written if the writing state is normal, and write the index value of the data to be written into the index corresponding to the data to be written; the index hash ring is used to configure the mapping relationship between the index and the hash value;
[0030] A second data writing unit is used to update the distributed index structure by updating the number of indexes in the distributed index structure if the writing status is abnormal, and to update the index hash ring based on the updated distributed index structure; based on the updated index hash ring and the hash value of the data to be written, obtain the index corresponding to the data to be written, and write the index value of the data to be written into the index corresponding to the data to be written.
[0031] The third aspect of the present application provides a computer program product, including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the dynamic shard indexing method of the first aspect or any implementation of the first aspect.
[0032] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:
[0033] The memory is used to store computer programs;
[0034] The processor is used to execute the computer program so that the electronic device can implement the dynamic shard indexing method of the above-mentioned first aspect or any implementation method of the first aspect.
[0035] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the dynamic sharding indexing method of the above-mentioned first aspect or any implementation of the first aspect.
[0036] By means of the above technical scheme, the present application provides a dynamic sharding indexing method and related devices, which obtain the hash value of the data to be written. The index value of the data to be written is obtained based on the hash value of the data to be written. The write status of the distributed index structure is obtained, and the distributed index structure includes multiple indexes constructed in a distributed manner. If the write status is normal, the index corresponding to the data to be written is obtained based on the index hash ring and the hash value of the data to be written, and the index value of the data to be written is written into the index corresponding to the data to be written. The index hash ring is used to configure the mapping relationship between the index and the hash value. If the write status is abnormal, the distributed index structure is updated by updating the number of indexes in the distributed index structure, and the index hash ring is updated based on the updated distributed index structure. The index corresponding to the data to be written is obtained based on the updated index hash ring and the hash value of the data to be written, and the index value of the data to be written is written into the index corresponding to the data to be written. It can be seen that the present application maps data to multiple indexes of a distributed configuration through a hash ring, thereby improving data storage efficiency. And when the write status is abnormal, the number of indexes is dynamically adjusted to maintain high efficiency of data storage. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.
[0038] Figure 1 A schematic diagram of a system architecture provided for an embodiment of the present application;
[0039] Figure 2 A schematic diagram of an optional hardware structure of a terminal provided in an embodiment of the present application;
[0040] Figure 3 A schematic diagram of an optional hardware structure of a server provided in an embodiment of the present application;
[0041] Figure 4A schematic diagram of a flow chart of a dynamic sharding indexing method provided in an embodiment of the present application;
[0042] Figure 5 A schematic diagram of the specific structure of a dynamic sharding indexing system provided in an embodiment of the present application;
[0043] Figure 6 A schematic diagram of a specific implementation flow of a dynamic sharding indexing method provided in an embodiment of the present application;
[0044] Figure 7 A schematic diagram of the structure of a dynamic sharding indexing device provided in an embodiment of the present application;
[0045] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0046] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.
[0047] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.
[0048] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0049] The present application can be applied in the field of database technology. Taking a banking system database as an example, a large amount of business data is written and read out of the banking system database every day. In order to improve the reading and writing efficiency of business data, an embodiment of the present application provides a dynamic sharding indexing method, which is applied to but not limited to a dynamic sharding indexing system. The system can dynamically adjust the number of indexes and index data to optimize the index structure, thereby improving the data reading and writing efficiency.
[0050] See also Figure 1 , Figure 1A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers ( Figure 1 In the example, a server is included, and the server 200 can provide the method provided in the embodiment of the present application for one or more terminals.
[0051] Among them, a dynamic sharding index application can be installed on the terminal 100. The above application and web page can provide an interface. The terminal 100 can receive relevant parameters entered by the user on a pre-configured interface and send the above parameters to the server 200. The server 200 can obtain processing results based on the received parameters and return the processing results to the terminal 100.
[0052] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters by itself without the cooperation of the server, and the embodiments of the present application are not limited to this.
[0053] Next describe Figure 1 The product form of the mid-terminal 100;
[0054] The terminal 100 in the embodiment of the present application can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiment of the present application does not impose any limitation on this.
[0055] Figure 2 An optional hardware structure diagram of the terminal 100 is shown.
[0056] refer to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), an earphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190 and other components. Those skilled in the art will appreciate that Figure 2 These are merely examples of terminals or multi-function devices and do not constitute limitations on the terminals or multi-function devices, which may include more or fewer components than those shown in the figures, or combinations of certain components, or different components.
[0057] The input unit 130 can be used to receive input digital or character information, and generate key signal input related to the user settings and function control of the portable multifunctional device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect the user's touch operations on or near it (such as the user's operation on or near the touch screen using any suitable object such as fingers, joints, stylus, etc.), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the user's touch action on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute the command sent by the processor 170; the touch signal at least includes the touch point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, the touch screen can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic wave. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.
[0058] Among them, the input device 132 can receive input data and the like.
[0059] The display unit 140 can be used to display information input by the user or information provided to the user, various menus of the terminal 100, interactive interfaces, file display and / or playback of any multimedia file. In the embodiment of the present application, the display unit 140 can be used to display the interface of the data read and write instructions, processing results, etc.
[0060] The memory 120 can be used to store instructions and data. The memory 120 can mainly include an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files, texts, etc.; the instruction storage area can store software units such as operating systems, applications, instructions required for at least one function, or their subsets and extensions. It can also include a non-volatile random access memory; provide the processor 170 with hardware, software and data resources including management of computing and processing equipment, and support control software and applications. It is also used for the storage of multimedia files, and the storage of running programs and applications.
[0061] The processor 170 is the control center of the terminal 100. It uses various interfaces and lines to connect various parts of the entire terminal 100. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal 100 and processes data, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips. The processor 170 may also be used to generate corresponding operation control signals, send them to corresponding components of the computing and processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein performs corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.
[0062] Among them, the memory 120 can be used to store software code related to a dynamic sharding indexing method, the processor 170 can execute the steps of a dynamic sharding indexing method, and can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to implement corresponding functions.
[0063] The radio frequency unit 110 (optional) can be used for receiving and sending information or receiving and sending signals during a call, for example, after receiving the downlink information of the base station, it is sent to the processor 170 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (Global System of Mobile communication, GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE), email, Short Messaging Service (SMS), etc.
[0064] In this embodiment of the present application, the RF unit 110 can send data to the server 200 and receive processing results sent by the server 200.
[0065] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network port.
[0066] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption.
[0067] The terminal 100 further includes an external interface 180 , which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal 100 to communicate with other devices, or to connect a charger to charge the terminal 100 .
[0068] Although not shown, the terminal 100 may also include a flashlight, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which are not described in detail here. Some or all of the methods described below may be applied in the following embodiments. Figure 2 In the terminal 100 shown.
[0069] Next describe Figure 1 The product form of the server 200;
[0070] Figure 3 A structural diagram of a server 200 is provided, such as Figure 3 As shown, the server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other via the bus 201.
[0071] The bus 201 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0072] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0073] The memory 204 may include a volatile memory, such as a random access memory (RAM). The memory 204 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard drive (HDD), or a solid state drive (SSD).
[0074] Among them, the memory 204 can be used to store software codes related to a shard indexing method based on a hash ring, the processor 202 can execute the steps of a shard indexing method based on a hash ring of the chip, and can also schedule other units to implement corresponding functions.
[0075] It should be understood that the above-mentioned terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above-mentioned terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as application specific integrated circuit (ASIC), field-programmable gate array (FPGA), general-purpose processor, digital signal processor (DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.
[0076] In the field of database technology, a database is a system for storing, managing and retrieving data. Key-value storage is a simple data storage model in which kv data consists of a key and a corresponding value. This model is similar to a dictionary, where data values are accessed through a unique key. Key-value storage is often used in scenarios that require fast read and write access, simple data structures, and distributed storage. The hash ring achieves the distribution and management of data among distributed nodes by mapping nodes to a ring structure and then evenly mapping data to the ring.
[0077] In order to solve the problem of low efficiency in reading and writing KV data in the database, an embodiment of the present application provides a dynamic sharding indexing method. A dynamic sharding indexing method of an embodiment of the present application is described in detail below in conjunction with the accompanying drawings.
[0078] Reference Figure 4 , Figure 4 A flow chart of a dynamic sharding indexing method provided in an embodiment of the present application is as follows: Figure 4 As shown, a dynamic shard indexing method provided in an embodiment of the present application may include S401 to S406, and these steps are described in detail below.
[0079] S401. Obtain a hash value of the data to be written.
[0080] In this embodiment, the data to be written is kv data, and the hash value of the data to be written is obtained by performing a hash operation on the key value key.
[0081] S402: Obtain an index value of the data to be written based on the hash value of the data to be written.
[0082] In this embodiment, the index value is obtained by combining the hash value hash of the data to be written and the key.
[0083] In a possible implementation, the hash value of the data to be written and the key value of the data to be written are concatenated to obtain the index value of the data to be written. The index value of the data to be written is equal to the concatenation result of the hash value and the key value key. For example, the data structure of the index value of the data to be written is hash+key.
[0084] S403: Obtain the write status of the distributed index structure.
[0085] In this embodiment, the distributed index structure includes multiple indexes constructed in a distributed manner. The write state of the distributed index structure is determined by the write congestion level and write idle level of each index in the distributed index structure. The write congestion level of the index is positively correlated with the number of data to be written waiting to be written to the index, and the write idle level of the index is negatively correlated with the number of data to be written waiting to be written to the index. For example, if the number of data to be written waiting to be written to the index is greater than a preset first waiting number threshold, it indicates that the write congestion level of the index is high. If the number of data to be written waiting to be written to the index is less than a preset second waiting number threshold, it indicates that the write idle level of the index is high.
[0086] In this embodiment, if the index has a high write idleness or a high write congestion, it is determined that the index write is abnormal. The write status of the distributed index structure is related to the write status of each index. For example, if the number of indexes with write abnormalities is greater than a preset abnormal number threshold, it means that the write status of the distributed index structure is abnormal. Taking the distributed index structure including 10 indexes as an example, if 8 indexes are in a write congestion state, it means that the overall write status of the distributed index structure is congested, indicating that the write status of the distributed index structure is abnormal.
[0087] S404: If the writing status is normal, obtain the index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written, and write the index value of the data to be written into the index corresponding to the data to be written.
[0088] In this embodiment, the index hash ring is used to configure the mapping relationship between the index and the hash value.
[0089] In one possible implementation, the index hash ring is constructed based on the initial hash ring and is updated based on the write status of the distributed index structure. The mapping relationship between the index and the hash value is constructed through the correspondence between the index identifier and the hash interval. Optionally, the hash ring is divided into hash intervals with the same number of indexes, and a hash interval is configured for each index, thereby constructing a mapping relationship between the index and the hash value. In this embodiment, the hash interval of the hash value of the data to be written on the index hash ring is obtained as the target hash interval; the index corresponding to the target hash interval is obtained according to the mapping relationship as the index corresponding to the data to be written.
[0090] S405: If the write status is abnormal, update the distributed index structure by updating the number of indexes in the distributed index structure, and update the index hash ring based on the updated distributed index structure.
[0091] In this embodiment, the number of indexes in the distributed index structure is reconfigured, and the index hash ring is updated according to the updated distributed index structure.
[0092] S406 , obtaining an index corresponding to the data to be written based on the updated index hash ring and the hash value of the data to be written, and writing the index value of the data to be written into the index corresponding to the data to be written.
[0093] In a possible implementation, a hash interval of a hash value of the data to be written on the updated index hash ring is obtained as a target hash interval; and an index corresponding to the target hash interval is obtained according to a mapping relationship as an index corresponding to the data to be written.
[0094] It can be seen from the above technical scheme that a dynamic sharding indexing method provided by an embodiment of the present application obtains a hash value of the data to be written. The index value of the data to be written is obtained based on the hash value of the data to be written. The write status of the distributed index structure is obtained, and the distributed index structure includes multiple indexes constructed in a distributed manner. If the write status is normal, the index corresponding to the data to be written is obtained based on the index hash ring and the hash value of the data to be written, and the index value of the data to be written is written into the index corresponding to the data to be written. The index hash ring is used to configure the mapping relationship between the index and the hash value. If the write status is abnormal, the distributed index structure is updated by updating the number of indexes in the distributed index structure, and the index hash ring is updated based on the updated distributed index structure. The index corresponding to the data to be written is obtained based on the updated index hash ring and the hash value of the data to be written, and the index value of the data to be written is written into the index corresponding to the data to be written. It can be seen that the present application maps data to multiple indexes of a distributed configuration through a hash ring, thereby improving data storage efficiency. And when the write status of the distributed index structure is abnormal, the number of indexes is dynamically adjusted to achieve the scalability of the distributed index structure, maintaining high efficiency of data storage while avoiding waste of resources.
[0095] Reference Figure 5 , Figure 5 A specific structural diagram of a dynamic sharding indexing system provided in an embodiment of the present application. Optionally, the dynamic sharding indexing system can be applied to the above-mentioned server, such as Figure 5 As shown, the dynamic shard index system 500 includes: a shard index module, a distributed index structure including multiple indexes, and multiple write queues corresponding to the multiple indexes one by one, such as Figure 5 As shown, the distributed index structure includes index 1 to index n, where n is the number of indexes, and multiple write queues include write queue 1 to write queue n, where write queue i corresponds to index i, and i∈[1,n]. The shard index module is configured with a hash ring and a cache queue, and optionally, the write queue and the cache queue are both first-in-first-out queues.
[0096] Reference Figure 6 , Figure 6 A schematic diagram of a specific implementation flow of a dynamic sharding indexing method provided in an embodiment of the present application is shown in FIG. Figure 6 As shown, a dynamic shard indexing method provided in an embodiment of the present application may include steps 601 to 612, and these steps are described in detail below.
[0097] S601 . Obtain a hash value of the data to be written, and obtain an index value of the data to be written based on the hash value of the data to be written.
[0098] In this embodiment, the data to be written is kv data, the hash value of the data to be written is obtained by performing a hash operation on the key value key, the index value of the data to be written is equal to the concatenation of the hash value and the key value key, and optionally, the data structure of the index value of the data to be written is hash+key.
[0099] S602: Obtain performance parameters of each write queue according to a preset period.
[0100] In this embodiment, the performance parameter is used to indicate the congestion level of the write queue. Optionally, the performance parameter includes a data volume ratio, which is equal to the ratio of the queue length to the queue capacity, wherein the queue length is the amount of data stored and the queue capacity is the maximum amount of data that can be stored.
[0101] S603. Determine whether the optimization condition is met based on the performance parameters of each write queue. If the optimization condition is not met, execute S604 to S605. If the optimization condition is met, execute S606 to S612.
[0102] In this embodiment, the optimization condition includes a first optimization condition and a second optimization condition, wherein the first optimization condition includes that the ratio of the number of crowded queues to the total number of write queues is greater than a preset first ratio threshold, and / or there is at least one item in at least one overflow queue, a crowded queue refers to a write queue whose data volume ratio is greater than the preset first data volume ratio threshold but not equal to 1, and an overflow queue is a queue whose data volume ratio is equal to 1. The second optimization condition includes that the ratio of the number of redundant queues to the total number of write queues is greater than a preset second ratio threshold, and / or there is at least one idle queue, a redundant queue refers to a write queue whose data volume ratio is less than the preset second data volume ratio threshold but not equal to 0, and an idle queue is a queue whose data volume ratio is equal to 0.
[0103] Optionally, taking the first ratio threshold of 50% and the first data volume ratio threshold of 80% as an example, when the data volume ratio of the target write queue is greater than 80%, the target write queue is judged as a congested queue. If the ratio of the congested queue to the total number of write queues is greater than 50% or there is an overflow queue, it means that more than half of the write queues are in a congested state or there is at least one queue overflow. Therefore, the first optimization condition is met.
[0104] Optionally, taking the second ratio threshold of 50% and the second data volume ratio threshold of 20% as an example, when the data volume ratio of the target write queue is less than 20%, the target write queue is judged as a redundant queue. If the ratio of the redundant queue to the total number of write queues is greater than 50%, or there is at least one idle queue, it means that more than half of the write queues are idle, or there is at least one queue with no data, and therefore, the second optimization condition is met.
[0105] S604: If the optimization condition is not met, obtain a target index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written.
[0106] In this embodiment, the index hash ring includes n hash intervals, each hash interval corresponds to an index, and the index corresponding to the target hash interval to which the hash value of the data to be written belongs is obtained as the target index.
[0107] In this embodiment, the method for generating a hash ring includes:
[0108] A1. Construct a distributed index structure including n indexes, including index 1 to index n.
[0109] A2. Divide the hash ring into n hash intervals evenly according to the number of indexes in the distributed index structure. Each hash interval represents a hash range. A mapping relationship between n hash intervals and n index data structures is constructed to obtain an index hash ring.
[0110] That is, the index hash ring is used to allocate n hash intervals to n indexes, each index uniquely corresponds to a hash interval, and the hash intervals have no intersection.
[0111] S605: Write the index value of the data to be written into the write queue corresponding to the target index.
[0112] In this embodiment, the write queue is used to write the index values in the queue into the corresponding indexes in sequence.
[0113] S606: If the optimization condition is met, suspend the read and write operations in the write queue, and write the index values of the data to be written into the preset cache queue in sequence.
[0114] S607: Update the distributed index structure based on the performance parameters of the write queues corresponding to the respective indexes and the number of indexes in the distributed index structure.
[0115] In this embodiment, based on the performance parameters of the write queues corresponding to the respective indexes, the index quantity of the indexes in the distributed index structure is updated, and based on the updated index quantity, the distributed index structure and the write queues corresponding to the respective indexes are constructed.
[0116] Specifically, if the first optimization condition is met, the number of indexes in the distributed index structure is increased to update the distributed index structure, and if the second optimization condition is met, the number of indexes in the distributed index structure is reduced to update the distributed index structure.
[0117] S608. Update the index hash ring based on the updated distributed index structure.
[0118] In this embodiment, that is, taking the total number of indexes included in the updated distributed index structure as N as an example, n is replaced with N and A2 is executed.
[0119] S609: Based on the updated index hash ring, obtain the target index corresponding to the index value of each written data in the updated distributed index structure, and write the index value of the written data into the write queue corresponding to the target index.
[0120] In this embodiment, the index corresponding to the index value is the index corresponding to the hash interval in which the hash value is located.
[0121] In this embodiment, the index value of the written data includes the index value written in the distributed index structure before the update.
[0122] S610. Based on the updated index hash ring, obtain the target index corresponding to the index value of each data to be written in the updated distributed index structure, and write the index value of each data to be written into the write queue corresponding to the target index.
[0123] In this embodiment, the index value of the data to be written includes the index value written in the write queue corresponding to the distributed index structure before updating and the index value written in the cache queue.
[0124] It should be noted that, for the cache queue and the write queue corresponding to the distributed index structure before the update, obtaining the target index corresponding to the index value of each data to be written is performed in parallel until the data amount of each queue is zero.
[0125] S611. Release the write queue corresponding to the distributed index structure before the update whose data volume is 0.
[0126] It should be noted that when the amount of data in the cache queue is 0, the index value of the data to be written is directly input into the write queue, thereby idling the cache queue; or, when the index values of all written data are rewritten into the distributed index structure, the index value of the data to be written is directly input into the write queue. At this time, the index value in the original write queue, the index value in the cache queue, and the index value of the new data to be written are synchronously written into the write queue corresponding to the updated distributed index structure.
[0127] It can be seen from the above technical solutions that the dynamic sharding indexing method provided by the embodiment of the present application reduces the granularity of the index lock by constructing a distributed index structure, and writes the data belonging to different indexes to each index in parallel through the queue corresponding to each index. Only the keys mapped to the same index will compete for the same lock, which avoids the need to maintain a global index lock, realizes the decentralized storage of data, and improves the concurrent performance of data writing. The writing performance of each distributed index structure is monitored by the congestion level of the queue, and the number of indexes is adjusted in real time to maintain the high concurrency and writing efficiency of data writing while avoiding waste of resources, thereby improving the writing performance and scalability of the system.
[0128] Furthermore, when the first optimization condition is met, the number of indexes is increased to improve concurrency and write performance. When the second optimization condition is met, the number of indexes is reduced to avoid resource waste and avoid index complexity in the data search stage.
[0129] Furthermore, each data is mapped to each index by constructing an index hash ring, and the data is written to the index through a write queue, thereby achieving data orderliness and load balancing.
[0130] It should be noted that the dynamic sharding indexing method and related devices provided by the present invention can be used in the distributed field or the financial field. The above is only an example and does not limit the application field of the dynamic sharding indexing method and related devices provided by the present invention.
[0131] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant laws, regulations and standards of relevant countries and regions.
[0132] A dynamic sharding indexing method provided in an embodiment of the present application is introduced above, and a device for executing the above dynamic sharding indexing method will be introduced below.
[0133] See also Figure 7 , Figure 7 A schematic diagram of the structure of a dynamic sharding indexing device provided in an embodiment of the present application. Figure 7 As shown, the dynamic shard indexing device 700 includes:
[0134] A hash operation unit 701 is used to obtain a hash value of the data to be written;
[0135] An index calculation unit 702 is used to obtain an index value of the data to be written based on the hash value of the data to be written;
[0136] A write status monitoring unit 703, used to obtain a write status of a distributed index structure, wherein the distributed index structure includes a plurality of indexes constructed in a distributed manner;
[0137] A first data writing unit 704 is used to obtain the index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written, and write the index value of the data to be written into the index corresponding to the data to be written if the writing state is normal; the index hash ring is used to configure the mapping relationship between the index and the hash value;
[0138] The second data writing unit 705 is used to update the distributed index structure by updating the number of indexes in the distributed index structure if the writing status is abnormal, and update the index hash ring based on the updated distributed index structure; obtain the index corresponding to the data to be written based on the updated index hash ring and the hash value of the data to be written, and write the index value of the data to be written into the index corresponding to the data to be written.
[0139] In a possible implementation, when the index calculation unit is used to obtain the index value of the data to be written based on the hash value of the data to be written, it is specifically used to:
[0140] The hash value of the data to be written and the key value of the data to be written are concatenated to obtain the index value of the data to be written.
[0141] In a possible implementation, the mapping relationship includes a one-to-one correspondence between a hash interval and an index; when either the first data writing unit or the second data writing unit is used to obtain an index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written, it is specifically used to:
[0142] Obtaining a hash interval of the hash value of the data to be written on the index hash ring as a target hash interval;
[0143] The index corresponding to the target hash interval is obtained according to the mapping relationship as the index corresponding to the data to be written.
[0144] In a possible implementation, when used to write the index value of the data to be written into the index corresponding to the data to be written, either the first data writing unit or the second data writing unit is specifically used to:
[0145] The index value of the data to be written is written into a write queue corresponding to a target index, where the target index is the index corresponding to the data to be written, and the write queue corresponding to the target index is used to write the data in the queue into the target index in sequence.
[0146] In a possible implementation, when the write status monitoring unit is used to obtain the write status of the distributed index structure, it is specifically used to: obtain the performance parameters of each of the write queues according to a preset period, the performance parameters including a data volume ratio, the data volume ratio being equal to the ratio of the queue length to the queue capacity; determine whether a preset optimization condition is met based on the performance parameters of each of the write queues, and if the optimization condition is met, determine that the write status of the distributed index structure is abnormal; if the optimization condition is not met, determine that the write status of the distributed index structure is normal; the optimization condition includes any one of a first optimization condition and a second optimization condition, wherein the first optimization condition includes that the ratio of the number of crowded queues to the total number of write queues is greater than a preset first ratio threshold, and / or there is at least one item in at least one overflow queue; the second optimization condition includes that the ratio of the number of redundant queues to the total number of write queues is greater than a preset second ratio threshold, and / or there is at least one idle queue.
[0147] In a possible implementation, the second data writing unit is used to update the distributed index structure by updating the number of indexes in the distributed index structure, and update the index hash ring based on the updated distributed index structure, specifically for:
[0148] If the first optimization condition is met, the number of indexes in the distributed index structure is increased to update the distributed index structure, and based on the number of indexes in the updated distributed index structure, the hash intervals of the index hash ring are re-divided, and a corresponding relationship between each index in the updated distributed index structure and each hash interval in the updated index hash ring is established;
[0149] If the second optimization condition is met, the number of indexes in the distributed index structure is reduced to update the distributed index structure, and based on the number of indexes in the updated distributed index structure, the hash intervals of the index hash ring are re-divided, and a correspondence between each index in the updated distributed index structure and each hash interval in the updated index hash ring is established.
[0150] The present application also provides an electronic device in an embodiment. Figure 8 As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiments of the present application. The electronic device in the embodiments of the present application may include but is not limited to fixed terminals such as mobile phones, notebook computers, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Figure 8 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0151] like Figure 8 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage device 808 to a random access memory (RAM) 803. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 803. The processing device 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0152] Typically, the following devices may be connected to the I / O interface 805: input devices 806 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; output devices 807 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 808 including, for example, a memory card, a hard disk, etc.; and communication devices 809. The communication device 809 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Figure 6 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.
[0153] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any one of the dynamic sharding indexing methods provided in the embodiments of the present application.
[0154] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any dynamic sharding indexing method provided in an embodiment of the present application.
[0155] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0156] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0157] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0158] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
Claims
1. A dynamic sharding indexing method, characterized in that: include: Get the hash value of the data to be written; Obtaining an index value of the data to be written based on a hash value of the data to be written; Obtaining a write status of a distributed index structure, wherein the distributed index structure includes a plurality of indexes constructed in a distributed manner; If the write status is normal, the index corresponding to the data to be written is obtained based on the index hash ring and the hash value of the data to be written, and the index value of the data to be written is written into the index corresponding to the data to be written; the index hash ring is used to configure the mapping relationship between the index and the hash value; If the write status is abnormal, the distributed index structure is updated by updating the number of indexes in the distributed index structure, and the index hash ring is updated based on the updated distributed index structure; based on the updated index hash ring and the hash value of the data to be written, the index corresponding to the data to be written is obtained, and the index value of the data to be written is written into the index corresponding to the data to be written.
2. The dynamic sharding indexing method according to claim 1, characterized in that: The obtaining the index value of the data to be written based on the hash value of the data to be written includes: The hash value of the data to be written and the key value of the data to be written are concatenated to obtain the index value of the data to be written.
3. The dynamic sharding indexing method according to claim 1, characterized in that: The mapping relationship includes a one-to-one correspondence between a hash interval and an index; and obtaining the index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written includes: Obtaining a hash interval of the hash value of the data to be written on the index hash ring as a target hash interval; The index corresponding to the target hash interval is obtained according to the mapping relationship as the index corresponding to the data to be written.
4. The dynamic sharding indexing method according to claim 1, characterized in that: Writing the index value of the data to be written into the index corresponding to the data to be written includes: The index value of the data to be written is written into a write queue corresponding to a target index, where the target index is the index corresponding to the data to be written, and the write queue corresponding to the target index is used to write the data in the queue into the target index in sequence.
5. The dynamic sharding indexing method according to claim 4, characterized in that: The obtaining the write status of the distributed index structure includes: According to a preset cycle, the performance parameters of each write queue are obtained, wherein the performance parameters include a data volume ratio, and the data volume ratio is equal to a ratio of a queue length to a queue capacity; Determine whether a preset optimization condition is met according to the performance parameters of each of the write queues, and if the optimization condition is met, determine that the write state of the distributed index structure is abnormal; if the optimization condition is not met, determine that the write state of the distributed index structure is normal; The optimization condition includes any one of a first optimization condition and a second optimization condition, wherein the first optimization condition includes that the ratio of the number of congested queues to the total number of write queues is greater than a preset first ratio threshold, and / or there is at least one item in at least one overflow queue; the second optimization condition includes that the ratio of the number of redundant queues to the total number of write queues is greater than a preset second ratio threshold, and / or there is at least one idle queue.
6. The dynamic sharding indexing method according to claim 5, characterized in that: The updating of the distributed index structure by updating the number of indexes in the distributed index structure, and updating the index hash ring based on the updated distributed index structure, includes: If the first optimization condition is met, the number of indexes in the distributed index structure is increased to update the distributed index structure, and based on the number of indexes in the updated distributed index structure, the hash intervals of the index hash ring are re-divided, and a corresponding relationship between each index in the updated distributed index structure and each hash interval in the updated index hash ring is established; If the second optimization condition is met, the number of indexes in the distributed index structure is reduced to update the distributed index structure, and based on the number of indexes in the updated distributed index structure, the hash intervals of the index hash ring are re-divided, and a correspondence between each index in the updated distributed index structure and each hash interval in the updated index hash ring is established.
7. A dynamic sharding indexing device, characterized in that: include: A hash operation unit, used to obtain a hash value of the data to be written; An index calculation unit, configured to obtain an index value of the data to be written based on a hash value of the data to be written; A write status monitoring unit, used to obtain a write status of a distributed index structure, wherein the distributed index structure includes a plurality of indexes constructed in a distributed manner; A first data writing unit is used to obtain the index corresponding to the data to be written based on the index hash ring and the hash value of the data to be written if the writing state is normal, and write the index value of the data to be written into the index corresponding to the data to be written; the index hash ring is used to configure the mapping relationship between the index and the hash value; A second data writing unit is used to update the distributed index structure by updating the number of indexes in the distributed index structure if the writing status is abnormal, and to update the index hash ring based on the updated distributed index structure; based on the updated index hash ring and the hash value of the data to be written, obtain the index corresponding to the data to be written, and write the index value of the data to be written into the index corresponding to the data to be written.
8. A computer program product, characterized in that It includes computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the dynamic sharding indexing method as described in any one of claims 1 to 5.
9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the dynamic shard indexing method as described in any one of claims 1 to 6.
10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the dynamic shard indexing method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data caching method and device, server and recharging system
CN113704308A
Data processing method and device, electronic equipment and storage medium
CN115422205A
Data processing method, electronic equipment and medium thereof
CN115580728A
Method and device for constructing hash index of distributed storage system
CN116303258A
Query method and device based on disk storage
CN116991897A
Cited By
Data processing method and device, electronic equipment and storage medium
CN119621132A
