A data processing method and apparatus
By processing data processing instructions in a key-value database in parallel, Jedis's performance bottleneck problem in high concurrency environments is solved, efficient data processing is achieved, and the application performance and user experience is improved.
Patent Information
- Application Number
- CN202410829376.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-25
- Publication Date
- 2025-07-11
- Estimated Expiration
- 2044-06-25
AI Technical Summary
The existing Jedis clients have performance bottlenecks in high concurrency environments and do not support non-blocking and asynchronous operations. They require additional connection pooling, which increases development complexity.
Provide a data processing method and device, by receiving data processing instructions from clients, processing key-value pairs in parallel, and leveraging the multi-core performance of HetuKV key-value database, efficient parallel data processing is achieved, application performance is improved and operation delay is reduced.
It realizes efficient parallel data processing in key-value databases, improves application performance, reduces operation delays, and improves data processing efficiency and user experience.
Smart Images

Figure CN118796920B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and particularly to a data processing method and apparatus. Background Art
[0002] NoSQL databases are a type of databases that emerged outside of relational databases, aiming to address challenges such as large-scale data storage and high-concurrency access that are difficult for traditional relational databases to handle. Key-value databases are a major type of NoSQL databases. They store data in the form of key-value pairs and are suitable for simple data models and fast read-write operations. In particular, Redis, as a key-value database in memory, is widely used due to its fast read-write operations and rich functions (such as publish / subscribe, transactions, pipelines, etc.).
[0003] In the field of Java development, with the rapid development of Internet applications, the demand for high performance, scalability, and flexibility is increasing. Traditional relational databases may face performance bottlenecks when dealing with large amounts of data and high-concurrency requests. Therefore, developers have started to seek alternative solutions. The emergence of key-value databases has filled this demand gap and provided more options for Java developers. Java is a widely used programming language, which is applied in enterprise, network, mobile, and embedded systems. Many enterprise-level applications and microservice architectures are based on the Java technology stack. Developing Java interfaces for key-value databases enables these applications to easily access and operate key-value databases to meet the requirements of application scenarios.
[0004] Key-value databases usually have the characteristics of high performance and scalability because they are based on a simple key-value pair data model, allowing fast read-write operations. Through Java interfaces, developers can utilize the performance advantages of key-value databases and apply them to application scenarios such as caching, session management, and real-time data processing. Developing Java interfaces for key-value databases can simplify the development process by abstracting and encapsulating database operations. Developers can use familiar Java APIs to interact with key-value databases without having to delve into the underlying implementation of the databases. This simplification helps to improve development efficiency and reduce the probability of errors.
[0005] In the prior art, Jedis is a Java client library for Redis, providing comprehensive support and direct mapping for Redis commands. Jedis provides encapsulation of Redis commands, including strings, hashes, sets, sorted sets, transactions, publish / subscribe, etc. It also provides APIs that allow developers to interact using Redis's native commands.
[0006] Jedis runs synchronously, which means it blocks while waiting for a Redis response. This can lead to performance bottlenecks, especially in high-concurrency environments. Since Jedis is synchronous, it is not suitable for scenarios that require non-blocking and asynchronous operations. Jedis does not come with a connection pool by default and requires additional configuration of a connection pool to manage connections. This may increase the development complexity. Therefore, there is an urgent need for a method that can be applied to high-concurrency environments and enables Java clients to efficiently connect to a key-value database. Summary of the Invention
[0007] The present invention provides a data processing method and apparatus, which can enable a client to efficiently connect to a key-value database by using preset data processing instructions, and can perform parallel data processing on key-value pair data in the key-value database, achieving efficient parallel data processing, thereby improving the performance of the application program, enhancing the performance of the client, reducing operation latency, and further enabling improvement of the data processing efficiency, reducing the data processing cost, and improving the user experience of data processing.
[0008] In a first aspect, the present invention provides a data processing method, which is applied to a solid-state drive corresponding to a key-value database. The method includes:
[0009] Receiving at least one data processing instruction sent by a client; wherein each data processing instruction includes: target set type data and a target set operation type;
[0010] Performing parallel data processing on the at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction; wherein, for each data processing instruction, determining target key-value pair data in the key-value database according to the target set type data, wherein each key-value pair data in the key-value database includes a key and at least one value, each value includes at least one ordered set, and each ordered set includes at least one element, wherein each element includes at least one field and data values corresponding to each field, and the multiple elements in each ordered set are sorted according to the data values corresponding to the preset fields; performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction;
[0011] Feeding back the data processing results respectively corresponding to the at least one data processing instruction to the client.
[0012] In a second aspect, the present invention provides a data processing apparatus, which is applied to a solid-state drive corresponding to a key-value database. The apparatus includes:
[0013] A first unit for receiving at least one data processing instruction sent by a client; wherein each data processing instruction includes: target set type data and a target set operation type;
[0014] A second unit for performing parallel data processing on the at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction; wherein, for each data processing instruction, according to the target set type data, target key-value pair data in the key-value database is determined, wherein each key-value pair data in the key-value database includes a key and at least one value, each value includes at least one ordered set, and each ordered set includes at least one element, wherein each element includes at least one field and data values corresponding to the respective fields, and multiple elements in each ordered set are sorted according to the data values corresponding to a preset field; data processing corresponding to the target set operation type is performed on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction;
[0015] A third unit for feeding back the data processing results respectively corresponding to the at least one data processing instruction to the client.
[0016] In a third aspect, the present invention provides a readable medium including execution instructions, and when a processor of an electronic device executes the execution instructions, the electronic device executes the method according to any one of the first aspect.
[0017] In a fourth aspect, the present invention provides an electronic device including a processor and a memory storing execution instructions, and when the processor executes the execution instructions stored in the memory, the processor executes the method according to any one of the first aspect.
[0018] As can be seen from the above technical solution, the method provided by the present invention can be applied to a solid-state drive corresponding to a key-value database. The method includes: receiving at least one data processing instruction sent by a client; wherein each data processing instruction includes: target set type data and a target set operation type; performing parallel data processing on the at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction; wherein, for each data processing instruction, determining target key-value pair data in the key-value database according to the target set type data, wherein each key-value pair data in the key-value database includes a key and at least one value, each value includes at least one ordered set, and each ordered set includes at least one element, wherein each element includes at least one field and data values corresponding to each field, and multiple elements in each ordered set are sorted according to data values corresponding to a preset field; performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction; feeding back the data processing results respectively corresponding to the at least one data processing instruction to the client. Since in this application, parallel data processing can be performed on the key-value pair data in the key-value database according to at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction, and the data processing results respectively corresponding to the at least one data processing instruction are fed back to the client, therefore, this application can enable the client to efficiently connect to the key-value database by using preset data processing instructions, and can perform parallel data processing on the key-value pair data in the key-value database, achieving efficient parallel data processing, thereby improving the performance of the application program, enhancing the performance of the client, reducing operation latency, further enabling the improvement of data processing efficiency, reducing data processing costs, and further improving the user experience of data processing.
[0019] The further effects of the above non-conventional preferred manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] In order to more clearly illustrate the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings described below are only some embodiments recorded in the present invention. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0021] Figure 1 It is a schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0022] Figure 2Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0023] Figure 3 Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0024] Figure 4 Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0025] Figure 5 Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0026] Figure 6 Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0027] Figure 7 Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0028] Figure 8 Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0029] Figure 9 Schematic flowchart of a data processing method provided by an embodiment of the present invention;
[0030] Figure 10 Schematic structural diagram of a data processing device provided by an embodiment of the present invention;
[0031] Figure 11 Schematic structural diagram of an electronic device provided by an embodiment of the present invention. Detailed implementation manners
[0032] To make the objectives, technical solutions and advantages of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below in conjunction with specific embodiments and the corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts shall fall within the protection scope of the present invention.
[0033] The following will describe in detail various non-limiting implementation manners of the present invention in conjunction with the drawings.
[0034] Refer to Figure 1 , which shows a data processing method in an embodiment of the present invention. The method can be applied to a solid-state drive corresponding to a key-value database. In this embodiment, the method may include the following steps, for example:
[0035] Step 1: Receive at least one data processing instruction sent by the client.
[0036] In this embodiment, when the client needs to perform data processing on the key-value pair data in the key-value database through the solid-state drive, the client can send at least one data processing instruction to the solid-state drive corresponding to the key-value database. In one implementation manner, the client can be a Java client, and the key-value database can be a Hetu Key-Value database (i.e., HetuKV key-value database).
[0037] Among them, each data processing instruction can include: target set type data, target set operation type. The target set type data can be understood as the relevant information of the data set to be processed and / or the elements in the data set. For example, the key and / or value of the key-value pair to be processed. It should be noted that each key-value pair data in the key-value database includes a key and at least one value, each value includes at least one sorted set (i.e., sorted set), and each sorted set includes at least one element. Among them, each element includes at least one field and the data value corresponding to each field. The multiple elements in each sorted set are sorted according to the data value corresponding to the preset field. A sorted set, that is, a sorted set, is a data structure with the characteristics of unique elements and ordered elements. A grade ranking list is a sorted set. The target set operation type can be understood as the operation method for processing the key-value pairs to be processed, such as query, delete, add, and so on.
[0038] It should be noted that the key-value pair data in the key-value database can be related data in fields such as artificial intelligence, content recommendation, image rendering, financial risk control, Internet of Things, game development, and big data analysis. For example, in the field of artificial intelligence, the solution provided by this application can be used for training and deploying machine learning and deep learning models. The application method includes: reading and processing a large amount of training data, quickly performing data preprocessing, caching intermediate results, and storing the trained model in the cache for real-time inference and prediction. In the field of content recommendation systems, content recommendation systems usually need to quickly access and process a large amount of user and content data to generate personalized recommendations. The solution provided by this application can be used to cache user preferences, recommendation history, popular content, etc., to reduce the reading pressure on the database and improve the real-time performance and accuracy of the recommendation system. In the field of image rendering and processing, quickly accessing and caching intermediate results is crucial for performance. The solution provided by this application can be used to store and cache intermediate data generated during the rendering process, such as textures, image slices, rendering results, etc., to help accelerate the rendering process and reduce the computational load. Financial institutions need to quickly process and analyze a large amount of transaction and user data to detect fraud and manage risks. The solution provided by this application can be used to cache and quickly access transaction records, account information, risk assessment results, etc., thereby improving the real-time response ability and data processing performance of the risk control system. In the field of the Internet of Things (IoT), IoT devices generate a large amount of data. Quickly processing and analyzing this data is crucial for system stability and performance. The solution provided by this application can be used to store and cache sensor data, device status, real-time events, etc., to help the IoT system quickly respond to events and instructions and ensure the real-time performance of the system. Game development requires processing a large amount of real-time data, including game status, player information, and game events. The solution provided by this application can be used to cache game status, player data, leaderboards, etc., to improve the response speed and performance of the game. Big data analysis requires quickly processing and analyzing a large amount of data to obtain valuable insights. The solution provided by this application can be used as a data processing transfer station to help achieve fast data import, processing, and caching, thereby improving the performance of the analysis system.
[0039] Step 2: Perform parallel data processing on the at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction.
[0040] In this embodiment, if multiple data processing instructions are received simultaneously, parallel data processing can be performed on the multiple data processing instructions to obtain the data processing results respectively corresponding to the at least one data processing instruction. For example, when the client can be a Java client and the key-value database can be a HetuKV key-value database, the multi-core performance advantage of the HetuKV key-value database can be utilized to achieve efficient parallel data processing, thereby improving the performance of the application program. The HetuKV key-value database has multi-core parallelism, and the Java client supports and can implement multi-threading. Therefore, multiple cores of the CPU can be enabled, and each core processes one data processing instruction separately. For example, when storing a large String file in a multi-core environment, the file can be split into multiple parts, and each core stores a part of the data separately, and they can be carried out simultaneously without interference. This multi-core parallel processing method can greatly improve the performance of data processing.
[0041] Specifically, for each data processing instruction, the target key-value pair data in the key-value database can be determined first according to the target set type data, that is, the target key-value pair data corresponding to the target set type data is queried from the key-value database according to the target set type data. Each key-value pair data in the key-value database includes a key and at least one value, and each value includes at least one ordered set, and each ordered set includes at least one element. Each element includes at least one field and the data values corresponding to the respective fields. The multiple elements in each ordered set are sorted according to the data values corresponding to the preset fields. It can be understood that in this embodiment, the value corresponding to the key in each key-value pair data is at least one ordered set (i.e., sorted set), that is, a key-value storage is used to store an ordered set (i.e., sorted set). The key is the unique identifier of this ordered set (i.e., sorted set), and the value is this ordered set (i.e., sorted set). There are multiple elements in the ordered set (i.e., sorted set). Each element includes at least one field and the data values corresponding to the respective fields. The multiple elements in each ordered set are sorted according to the data values corresponding to the preset fields. Simply put, the key is the name of an ordered set, and the value corresponding to this key is the elements (members) in this ordered set. For example, taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set):
[0042] Rank 1|Student a|100;
[0043] Rank 2|Student b|98;
[0044] Rank 3|Student c|97;
[0045] 4th|Student d|95;
[0046] 5th|Student e|94;
[0047] 6th|Student f|90.
[0048] Then, the data processing corresponding to the target set operation type can be performed on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction. That is to say, the target key-value pair data is processed according to the data processing method corresponding to the target set operation type, and the processed data processing result is obtained. For example, the target set operation type is the sorted set operation for performing key-value operations, such as zadd, zcard, zrange, zrangebyscore, etc. In this way, fast and efficient key-value data storage and retrieval can be ensured.
[0049] Step 3: Feedback the data processing results respectively corresponding to the at least one data processing instruction to the client.
[0050] After obtaining the data processing results respectively corresponding to the at least one data processing instruction, the data processing results respectively corresponding to the at least one data processing instruction can be fed back to the client.
[0051] As can be seen from the above technical solutions, the method provided by the present invention can be applied to a solid-state drive corresponding to a key-value database. The method includes: receiving at least one data processing instruction sent by a client; wherein each data processing instruction includes: target set type data and a target set operation type; performing parallel data processing on the at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction; wherein, for each data processing instruction, according to the target set type data, determining target key-value pair data in the key-value database, wherein each key-value pair data in the key-value database includes a key and at least one value, each value includes at least one ordered set, and each ordered set includes at least one element, wherein each element includes at least one field and data values corresponding to the respective fields, and the multiple elements in each ordered set are sorted according to the data values corresponding to the preset fields; performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction; and feeding back the data processing results respectively corresponding to the at least one data processing instruction to the client. Since in the present application, parallel data processing can be performed on the key-value pair data in the key-value database according to at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction, and the data processing results respectively corresponding to the at least one data processing instruction are fed back to the client, therefore, the present application can use preset data processing instructions to enable the client to efficiently connect to the key-value database, and can perform parallel data processing on the key-value pair data in the key-value database, realizing efficient parallel data processing, thereby improving the performance of the application program, improving the performance of the client, reducing the operation latency, and further enabling the improvement of the data processing efficiency, reducing the data processing cost, and further improving the user experience of data processing.
[0052] Next, embodiments in the cases of different target set type data and target set operation types will be introduced respectively.
[0053] In one implementation, the target set type data includes the key of the key-value pair to be processed, a target field, and the data value corresponding to the target field, and the target set operation type is a first addition operation.
[0054] In this embodiment, the specific implementation manner of determining the target key-value pair data in the key-value database according to the target set type data may be:
[0055] If the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field all conform to their respective preset string types, the key of the key-value pair to be processed conforms to the preset threshold condition, and each target field has a corresponding data value, then a key-value pair class is generated using the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field;
[0056] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0057] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data;
[0058] If there is no key-value pair data corresponding to the key-value pair class in the key-value database, create an empty key-value pair data in the key-value database and use the empty key-value pair data as the target key-value pair data.
[0059] Correspondingly, the data processing of the target key-value pair data corresponding to the target set operation type to obtain the data processing result corresponding to the data processing instruction includes:
[0060] Convert the value in the target key-value pair data into tree map class data;
[0061] Insert the target field and the data value corresponding to the target field as an element into the tree map class data to obtain updated tree map class (TreeMap) data;
[0062] Convert the updated tree map class data into the value in the target key-value pair data;
[0063] Determine that the data processing result corresponding to the data processing instruction is that the element addition is successful, and the number of successfully added elements is used as the data processing result corresponding to the data processing instruction.
[0064] Next, in combination with Figure 2 For example. Such as Figure 2As shown, the target set type data includes the key of the key-value pair to be processed, the target field in the target element member, and the data value corresponding to the target field (such as score corresponding to score). The target set operation type is the first addition operation zadd, which adds a specified member with a specified score to the sorted set stored at the key. If the member is already a member of the sorted set, the score will be updated and the element will be reinserted into the correct position to ensure sorting; if the key does not exist, a new sorted set with the specified member as the only member will be created. For example, it can be understood that an element has a standard (weight) for comparison. There are three people, Zhang San, Li Si, and Wang Wu. Zhang San's height is 160, Li Si's height is 180, and Wang Wu's height is 175. In the queue from tallest to shortest, height is the standard for comparison. When these three people are lined up, the order is: Li Si, Wang Wu, Zhang San. This queue is an ordered set, and these three people in the queue are the members of the ordered set. Specifically, it includes the following steps:
[0065] S101: Accept parameters
[0066] For step 101, accept three parameters: key, score, member. Key is the key value corresponding to the sorted list to be stored. Score and member are the score and element of the sorted list. The sorted list will be sorted in ascending order of score, and multiple pairs of score and member are accepted.
[0067] S102: Judge whether the parameters are even numbers.
[0068] For step 102, judge whether the parameters are even numbers. One score and one member form a pair. If so, execute S103; if not, execute S115.
[0069] S103: Initialize a HetuItem with the parameters.
[0070] For step 103, legal parameters will be passed here to initialize a HetuItem object.
[0071] S104: Initialize a TreeMap.
[0072] For step 104, TreeMap is a class in Java used to perform operations such as adding and changing TreeMap data in Java.
[0073] S105: Judge whether the key exists.
[0074] For step 105, the program will first check if there is an input key. If there is, it will execute S106; if not, it will execute S107.
[0075] S106: Return the Value corresponding to the key and decode it into a TreeMap.
[0076] For step 106, when there is a key, the corresponding value of the key will be retrieved from HetuKV. This value is stored in the type of ByteStream, so it needs to be converted into the corresponding TreeMap for convenient operation in Java.
[0077] S107: Check if the parameter is Double and String.
[0078] For step 107, Double and String exactly correspond to Score and Member. Therefore, it is necessary to check if the parameter is legal to continue the subsequent operations. If so, execute S108; otherwise, execute S115.
[0079] S108: Check if the parameter to be added exists.
[0080] For step 108, it will be checked in the TreeMap obtained in 106 whether the input parameter Member exists. If not, execute S109; if so, execute S110.
[0081] S109: Increment the count by 1.
[0082] For step 109, the number of new Members will be recorded.
[0083] S110: Store the input parameter into the TreeMap.
[0084] For step 110, update Score and Member into the TreeMap.
[0085] S111: Convert the TreeMap into a ByteStream.
[0086] For step 111, convert the TreeMap into a ByteStream.
[0087] S112: Set a new Value for HetuKVItem.
[0088] For step 112, update the Value of HetuKVItem.
[0089] S113: Check if the update is successful.
[0090] For step 113, use the updated HetuItem to update the object of HetuKV. If the update is successful, execute S114; if it fails, execute S115.
[0091] S114: Return the count.
[0092] For step 114, return the count of the new Members.
[0093] S115: Return the error code.
[0094] For step 115, it is entered when S102, S107, and S113 fail to execute, indicating that the operation has an error and cannot proceed. At this time, the corresponding error code will be returned and the operation will end.
[0095] For example, there are three people, Zhang San, Li Si, and Wang Wu. Zhang San's height is 160, Li Si's height is 180, and Wang Wu's height is 175. In the queue from tallest to shortest, height is the standard for comparison. When these three people are lined up, the order is: Li Si, Wang Wu, Zhang San. This queue is an ordered set, and these three people in the queue are the members of the ordered set.
[0096] In one implementation, the target set type data includes the key of the key-value pair to be processed, and the target set operation type is the first query operation.
[0097] In this embodiment, the specific implementation of determining the target key-value pair data in the key-value database according to the target set type data may be:
[0098] If the key of the key-value pair to be processed conforms to the preset string type and the key of the key-value pair to be processed conforms to the preset threshold condition, then use the key of the key-value pair to be processed to generate a key-value pair class;
[0099] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0100] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0101] Correspondingly, the data processing of the target key-value pair data corresponding to the target set operation type to obtain the data processing result corresponding to the data processing instruction includes:
[0102] Convert the value in the target key-value pair data into tree graph class data;
[0103] Determine the number of elements in the tree graph class data;
[0104] Use the number of elements in the tree diagram - type data as the data processing result corresponding to the data processing instruction.
[0105] Next, an example will be given in combination with Figure 3 As shown in Figure 3 , the target set - type data includes the key key of the key - value pair to be processed, and the target set operation type is the first query operation zcard, that is, it returns the number of elements in the sorted set. If the key does not exist, it returns 0, just like an empty sorted set. Specifically, it includes the following steps:
[0106] S201: Receive the parameter: key.
[0107] For step 201, receive a parameter key. key is the key corresponding to the sortedlist to be queried.
[0108] S202: Initialize a HetuItem with the parameter.
[0109] For step 202, legal parameters will be passed here to initialize a HetuItem object.
[0110] S203: Initialize a TreeMap.
[0111] For step 203, TreeMap is a class in Java used for operations such as adding and changing TreeMap data in Java.
[0112] S204: Whether to successfully return the Value corresponding to key.
[0113] For step 204, the program will first determine whether the query instruction has been successfully executed. If successful, execute S205; if not, execute S207.
[0114] S205: Return the Value corresponding to key and decode it into a TreeMap.
[0115] For step 205, in the case of the existence of key, the Value corresponding to key will be retrieved from HetuKV. This Value is stored in the type of ByteStream, so it needs to be converted into the corresponding TreeMap for convenient operation in Java.
[0116] S206: Return the length of the TreeMap.
[0117] For step 206, return the length of the TreeMap, that is, the number of elements in the sorted set.
[0118] S207: Determine whether the error message is "Item Not Found".
[0119] For step 207, it will further determine whether the reason for the error is that the key is not found. If the key is found, execute S109; if not, execute S108.
[0120] S208: Return an error code.
[0121] For step 208, it enters when S207 fails to execute, indicating that the operation has an error and cannot proceed. At this time, the corresponding error code will be returned and the operation will end.
[0122] S209: Return "0".
[0123] For step 209, when a new key that has not been stored is input, "0" will be returned.
[0124] In one implementation, the target set type data includes the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element, and the target set operation type is the second query operation.
[0125] In this embodiment, determining the target key-value pair data in the key-value database according to the target set type data includes:
[0126] If the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element conform to the preset string type, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element to generate a key-value pair class;
[0127] Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0128] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0129] Correspondingly, performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes:
[0130] Convert the value in the target key-value pair data into tree diagram class data;
[0131] Judge whether the sorting method of the elements in the tree diagram class data is the same as the sorting method corresponding to the starting position of the element and the ending position of the element;
[0132] If the sorting method of the elements in the tree graph - like data is different from the sorting method corresponding to the starting position and the ending position of the elements, reverse - sort the elements in the tree graph - like data to obtain the adjusted tree graph - like data; if the sorting method of the elements in the tree graph - like data is the same as the sorting method corresponding to the starting position and the ending position of the elements, do not adjust the elements in the tree graph - like data.
[0133] Using the binary search method, determine the element corresponding to the starting position of the element and the element corresponding to the ending position of the element in the tree graph - like data according to the starting position of the element and the ending position of the element; take the elements from the element corresponding to the starting position of the element to the element corresponding to the ending position of the element as the target element set.
[0134] If the data values corresponding to the preset fields in each element of the target element set are all of integer type, take the data values corresponding to the preset fields in each element of the target element set as the data processing result corresponding to the data processing instruction.
[0135] Next, combined with Figure 4 for illustration. As Figure 4 shown, the target set - type data includes the key of the key - value pair to be processed key, the starting position of the element start, and the ending position of the element stop, and the target set operation type is the second query operation zrange, that is, to find the values in the sorted set for a given index range in the key / sorted - set pair. Specifically, it includes the following steps:
[0136] S301: Receive parameters.
[0137] For step 301, receive three parameters key, start, and stop. Among them, key represents the key of the ordered set to be queried, start represents the starting value of the index range, and stop represents the ending value of the index range.
[0138] S302: Initialize HetuKVItem.
[0139] For step 302, legal parameters will be passed here to initialize a HetuItem object.
[0140] S303: Initialize a TreeMap.
[0141] For step 303, initialize a TreeMap to facilitate editing operations in Java.
[0142] S304: Query whether HetuKVItem is successful.
[0143] For step 304, use HetuKVItem to query in HetuKV according to its key and determine whether the query is successful. If so, execute S305; otherwise, execute S320.
[0144] S305: Return the Value corresponding to the key and decode it into a TreeMap.
[0145] For step 305, return the value and decode it into a TreeMap type.
[0146] S306: Extract and initialize the input parameters.
[0147] For step 306, initialize the input parameters.
[0148] S307: Traverse all input parameters.
[0149] For step 307, traverse all input parameters and determine whether to end the traversal.
[0150] S308: Determine whether it is a String.
[0151] For step 308, determine whether the input parameter is a String. If so, execute S313; otherwise, execute S318.
[0152] S309: Determine whether it contains "REV".
[0153] For step 309, determine whether the input parameter is REV. If so, execute S310; otherwise, execute S307.
[0154] S310: Sort all data in reverse order.
[0155] For step 310, if "REV" appears, sort all data in reverse order.
[0156] S311: Apply binary search to the range boundary.
[0157] For step 311, apply binary search to the range boundary.
[0158] S312: Return the elements within the specified range.
[0159] For step 312, return the sorted set values within the given score range.
[0160] S313: Determine whether it contains "LIMIT".
[0161] For step 313, determine whether the input parameter is LIMIT. If so, execute S314; otherwise, execute S307.
[0162] S314: Return a sublist within the specified range.
[0163] For step 314, if LIMIT appears, a sublist within the specified range will be returned.
[0164] S315: Determine whether it contains "WITHSCORES".
[0165] For step 315, check if the input parameter is WITHSCORES. If it is, execute S316; otherwise, execute S317.
[0166] S316: Return the list and the score.
[0167] For step 316, if WITHSCORES appears, both the value and the score will be returned.
[0168] S317: Return the list.
[0169] For step 317, if WITHSCORES does not appear, only the value will be returned.
[0170] S318: Whether it is an Integer.
[0171] For step 318, check if it is of integer type. If it is, execute S319; otherwise, execute S311.
[0172] S319: Add the integer to limitnumber.
[0173] For step 319, if it is of integer type, add this integer type to the limitnumber variable.
[0174] S320: Return an error code.
[0175] For step 320, it enters when S304 fails to execute, indicating that the operation encounters an error and cannot proceed. At this time, the corresponding error code will be returned and the operation will end.
[0176] For example, taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set):
[0177] Rank 1|Student a|100;
[0178] Rank 2|Student b|98;
[0179] Rank 3|Student c|97;
[0180] Rank 4|Student d|95;
[0181] Rank 5|Student e|94;
[0182] 6th | Student f | 90;
[0183] To find the students between the 2nd and 5th (i.e., to find the elements between index 1 and index 4 in the ordered set {index starts from 0}), the search result is: [b, c, d, e].
[0184] In one implementation, the target set type data includes the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field, and the target set operation type is the third query operation.
[0185] In this embodiment, determining the target key-value pair data in the key-value database according to the target set type data includes:
[0186] If the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed, the starting position of the element and the ending position of the element to generate a key-value pair class;
[0187] Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0188] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0189] Correspondingly, performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes:
[0190] Convert the value in the target key-value pair data into tree graph class data;
[0191] Judge whether the sorting method of the elements in the tree graph class data is the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field;
[0192] If the sorting method of the elements in the tree graph class data is not the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field, reverse the order of the elements in the tree graph class data to obtain the adjusted tree graph class data; if the sorting method of the elements in the tree graph class data is the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field, do not adjust the elements in the tree graph class data;
[0193] Using a binary search method, determine a target element in the tree graph - like data where the data value of the target field is greater than or equal to the starting position of the data value corresponding to the target field and less than or equal to the ending position of the data value corresponding to the target field, based on the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value corresponding to the target field.
[0194] If the data values corresponding to the target field in the target elements are all of integer type, use the data value corresponding to the preset field in the target elements as the data processing result corresponding to the data processing instruction.
[0195] Next, an example will be given in combination with Figure 5 As shown, the target set - type data includes the key of the key - value pair to be processed, the target field, the starting position min of the data value corresponding to the target field, and the ending position max of the data value corresponding to the target field. The target set operation type is the third query operation zrangebyscore, that is, to find the sorted set values within a given score range in the key / sorted - set pair. The target field can be a score, and the score can be understood as the weight corresponding to the element, and the index can be understood as the position of the element in the list. Taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set): Figure 5 As shown, the target set - type data includes the key of the key - value pair to be processed, the target field, the starting position min of the data value corresponding to the target field, and the ending position max of the data value corresponding to the target field. The target set operation type is the third query operation zrangebyscore, that is, to find the sorted set values within a given score range in the key / sorted - set pair. The target field can be a score, and the score can be understood as the weight corresponding to the element, and the index can be understood as the position of the element in the list. Taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set):
[0196] Rank 1|Student a|100
[0197] Rank 2|Student b|98
[0198] Rank 3|Student c|97
[0199] Rank 4|Student d|95
[0200] Rank 5|Student e|94
[0201] Rank 6|Student f|90; The third query operation zrangebyscore needs to find the students between 90 points and 96 points. The search result is: [d, e, f]. Specifically, it includes the following steps:
[0202] S401: Receive parameters.
[0203] For step 401, receive five parameters: key, min, max, offset, and count. Among them, key represents the key of the ordered set to be queried, min represents the starting value of the score range, max represents the ending value of the score range, offset represents the initial value of the sorted set limit quantity index, and count represents the sorted set limit quantity value.
[0204] S402: Initialize HetuKVItem.
[0205] For step 402, legal parameters will be passed here to initialize a HetuItem object.
[0206] S403: Initialize a TreeMap.
[0207] For step 403, initialize a TreeMap for ease of editing operations in Java.
[0208] S404: Query whether HetuKVItem is successful.
[0209] For step 404, use HetuKVItem to query in HetuKV according to its key and determine whether the query is successful. If so, execute S405; otherwise, execute S420.
[0210] S405: Return the Value corresponding to the key and decode it into a TreeMap.
[0211] For step 405, return the value and decode it into a TreeMap type.
[0212] S406: Extract and initialize the input parameters.
[0213] For step 406, initialize the input parameters.
[0214] S407: Traverse all input parameters.
[0215] For step 407, traverse all input parameters and determine whether to end the traversal.
[0216] S408: Determine whether it is a String.
[0217] For step 408, determine whether the input parameter is a String. If so, execute S413; otherwise, execute S418.
[0218] S409: Determine whether it contains "REV".
[0219] For step 409, determine whether the input parameter is REV. If so, execute S410; otherwise, execute S407.
[0220] S410: Sort all data in reverse order.
[0221] For step 410, if "REV" appears, sort all data in reverse order.
[0222] S411: Apply binary search to the range boundaries.
[0223] For step 411, apply binary search to the range boundaries.
[0224] S412: Return elements within a specified range.
[0225] For step 412, return the sorted set values within a given score range.
[0226] S413: Determine whether "LIMIT" is included.
[0227] For step 413, determine whether the input parameter is "LIMIT". If it is, execute S414; otherwise, execute S407.
[0228] S414: Return a sublist within a specified range.
[0229] For step 414, if "LIMIT" appears, return a sublist within the specified range.
[0230] S415: Determine whether "WITHSCORES" is included.
[0231] For step 415, determine whether the input parameter is "WITHSCORES". If it is, execute S416; otherwise, execute S417.
[0232] S416: Return the list and score.
[0233] For step 416, if "WITHSCORES" appears, return both the value and the score.
[0234] S417: Return the list.
[0235] For step 417, if "WITHSCORES" does not appear, return only the value.
[0236] S418: Whether it is an Integer.
[0237] For step 418, determine whether it is of integer type. If it is, execute S419; otherwise, execute S411.
[0238] S419: Add the integer to limitnumber.
[0239] For step 419, if it is of integer type, add this integer type to the limitnumber variable.
[0240] S420: Return an error code.
[0241] For step 420, it enters when S404 fails to execute, indicating that the operation has an error and cannot proceed. At this time, the corresponding error code will be returned and the operation will end.
[0242] In one implementation, the target set type data includes the key of the key-value pair to be processed, the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value, and the target set operation type is the fourth query operation.
[0243] In this embodiment, determining the target key-value pair data in the key-value database according to the target set type data includes:
[0244] If the key of the key-value pair to be processed, the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element to generate a key-value pair class;
[0245] Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0246] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0247] Correspondingly, performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes:
[0248] Convert the value in the target key-value pair data into tree graph class data;
[0249] Judge whether the sorting method of the elements in the tree graph class data is the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field;
[0250] If the sorting method of the elements in the tree graph class data is not the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field, reverse the order of the elements in the tree graph class data to obtain the adjusted tree graph class data; if the sorting method of the elements in the tree graph class data is the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field, do not adjust the elements in the tree graph class data;
[0251] Using the binary search method, according to the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value, determine the target element in the tree graph class data whose data value of the target field is greater than or equal to the starting position of the data value corresponding to the target field and less than or equal to the ending position of the data value corresponding to the target field;
[0252] Use the number of target elements as the data processing result corresponding to the data processing instruction.
[0253] Next, an example will be given in combination with Figure 6 As shown in Figure 6 The target set type data includes the key of the key-value pair to be processed, the target field, the starting position start and the ending position end of the data value corresponding to the target field. The target set operation type is the fourth query operation zcount, that is, to check the size of the sorted set within a given score range in the key / sorted set pair. Taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set):
[0254] Rank 1|Student a|100
[0255] Rank 2|Student b|98
[0256] Rank 3|Student c|97
[0257] Rank 4|Student d|95
[0258] Rank 5|Student e|94
[0259] Rank 6|Student f|90; The fourth query operation zcount is to find out how many students are between 90 and 96 points. The query result is: 3. Specifically, it includes the following steps:
[0260] S501: Receive parameters.
[0261] For step 501, receive three parameters key, start, and end. Among them, key represents the key of the ordered set to be queried, start represents the starting value of the score range, and end represents the ending value of the score range.
[0262] S502: Initialize HetuKVItem.
[0263] For step 502, legal parameters will be passed here to initialize a HetuItem object.
[0264] S503: Set the key of HetuKVItem.
[0265] For step 503, set the input parameter as the key of HetuKVItem.
[0266] S504: Check if the query is successful.
[0267] For step 504, use HetuKVItem to query in HetuKV according to its key and judge whether the query is successful. If yes, execute S505, otherwise execute S507.
[0268] S505: If the input is of double type.
[0269] For step 505, determine whether the input is of double type. If it is, execute S506; otherwise, execute S508.
[0270] S506: Return the length of the set.
[0271] For step 506, return the length of the set.
[0272] S507: Return an error code.
[0273] For step 507, it enters when S504 fails to execute, indicating that the operation has an error and cannot proceed. At this time, the corresponding error code will be returned and the operation will end.
[0274] S508: If the input is of String type.
[0275] For step 508, determine whether the input is of String type. If it is, execute S509; otherwise, execute S510.
[0276] S509: Return the length of the set.
[0277] For step 509, return the length of the set.
[0278] S510: Return "0".
[0279] For step 510, if it is neither of String type nor of Double type, return 0.
[0280] In one implementation, the target set type data includes the key of the key-value pair to be processed, the target field, and the target element position, and the target set operation type is the fifth query operation.
[0281] In this embodiment, determining the target key-value pair data in the key-value database according to the target set type data includes:
[0282] If the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed, the starting position of the element and the ending position of the element to generate a key-value pair class;
[0283] Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0284] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0285] Correspondingly, performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes:
[0286] Convert the value in the target key-value pair data into tree diagram class data;
[0287] Determine the target element corresponding to the target element position from the tree diagram class data according to the target element position;
[0288] Use the data value corresponding to the target field in the target element as the data processing result corresponding to the data processing instruction.
[0289] Next, an example will be given in combination with Figure 7 As shown in the following example. For example, Figure 7 The target set type data includes the key key of the key-value pair to be processed, the target field, and the target element position member. The target set operation type is the fifth query operation zscore, that is, return the score of the specified element in the sorted set at the keyword. If the specified element does not exist in the sorted set, or the key does not exist at all, a special "null" value will be returned. Taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set):
[0290] Rank 1|Student a|100
[0291] Rank 2|Student b|98
[0292] Rank 3|Student c|97
[0293] Rank 4|Student d|95
[0294] Rank 5|Student e|94
[0295] Rank 6|Student f|90; The fifth query operation zscore is to find the score of Student a, and the search result is: 100. To find the score of Student H, the search result is: Null. Specifically, it includes the following steps:
[0296] S601: Receive parameters.
[0297] For step 601, receive two parameters key and member. Where key represents the key of the ordered set to be queried, and member represents the target member.
[0298] S602: Initialize HetuKVItem.
[0299] For step 602, legal parameters will be passed here to initialize a HetuItem object.
[0300] S603: Set the key of HetuKVItem.
[0301] For step 603, set the input parameter as the key of HetuKVItem.
[0302] S604: Query whether it is successful.
[0303] For step 604, use HetuKVItem to query in HetuKV according to its key and determine whether the query is successful. If yes, execute S605; otherwise, execute S606.
[0304] S605: Return the score of the member.
[0305] For step 605, when the query is successful, directly return the score corresponding to the member.
[0306] S606: If the item does not exist.
[0307] For step 606, determine whether the item exists. If it exists, execute S608; if not, execute S607.
[0308] S607: Return Null.
[0309] For step 607, when the item does not exist, return Null.
[0310] S608: Return an error code.
[0311] For step 608, when S606 fails to execute, it means that the operation goes wrong and cannot be carried out. At this time, the corresponding error code will be returned and the operation will end.
[0312] In one implementation, the target set type data includes the key of the key-value pair to be processed and the target element position, and the target set operation type is a delete operation.
[0313] In this embodiment, determining the target key-value pair data in the key-value database according to the target set type data includes:
[0314] If the key of the key-value pair to be processed and the target field both conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed and the target field to generate a key-value pair class;
[0315] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0316] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0317] Correspondingly, performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes:
[0318] Convert the value in the target key-value pair data into tree diagram class data;
[0319] Delete the target element corresponding to the target element position in the tree diagram class data;
[0320] Use the number of successfully deleted target elements as the data processing result corresponding to the data processing instruction.
[0321] Next, an example will be given in combination with Figure 8 As shown in the following, the target set type data includes the key key of the key-value pair to be processed and the target element position member, and the target set operation type is the delete operation zrem, that is, delete the specified member from the sorted set value stored at key. If the member is not in it, no operation will be performed. If key does not contain a set value, an error message will be returned. Taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set): Figure 8 As shown, the target set type data includes the key key of the key-value pair to be processed and the target element position member, and the target set operation type is the delete operation zrem, that is, delete the specified member from the sorted set value stored at key. If the member is not in it, no operation will be performed. If key does not contain a set value, an error message will be returned. Taking the student exam score ranking as an example, the following is a score ranking table (which is an ordered set):
[0322] Rank 1|Student a|100
[0323] Rank 2|Student b|98
[0324] Rank 3|Student c|97
[0325] Rank 4|Student d|95
[0326] Rank 5|Student e|94
[0327] Rank 6|Student f|90;
[0328] The delete operation zrem is to re-sort the record of deleting student b. After the operation, the new score ranking table is obtained:
[0329] Rank 1|Student a|100
[0330] Rank 2|Student c|97
[0331] Rank 3|Student d|95
[0332] 4th | Student e | 94
[0333] 5th | Student f | 90. Specifically, it includes the following steps:
[0334] S701: Receive parameters.
[0335] For step 701, receive two parameters key and member. Where key represents the key of the ordered set to be queried, and member represents the target member.
[0336] S702: Initialize HetuKVItem.
[0337] For step 702, legal parameters will be passed here to initialize a HetuItem object.
[0338] S703: Set the key of HetuKVItem.
[0339] For step 703, set the input parameter as the key of HetuKVItem.
[0340] S704: Check if the query is successful.
[0341] For step 704, use HetuKVItem to query in HetuKV according to its key and judge whether the query is successful. If yes, execute S705, otherwise execute S712.
[0342] S705: Set count = 0.
[0343] For step 705, initialize the count to 0.
[0344] S706: Traverse all objects to be deleted.
[0345] For step 706, judge whether all objects to be deleted have been traversed. If so, execute S710, otherwise execute S707.
[0346] S707: If the treeMap contains the object.
[0347] For step 707, if the Treemap contains the object to be deleted, execute S708, otherwise execute S706.
[0348] S708: Delete the object.
[0349] For step 708, delete the object in the Treemap.
[0350] S709: count + 1.
[0351] For step 709, record the number of deleted objects.
[0352] S710: Update the Treemap to HetuKV.
[0353] For step 710, update the Treemap with the completed operation to HetuKV.
[0354] S711: Return the count.
[0355] For step 711, return the count.
[0356] S712: Return an error code.
[0357] For step 712, it enters when S704 fails to execute, indicating that the operation has an error and cannot proceed. At this time, the corresponding error code will be returned and the operation will end.
[0358] In one implementation, the target set type data includes the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field, the starting position of the index, and the number of index elements. The target set operation type is the sixth query operation.
[0359] In this embodiment, determining the target key-value pair data in the key-value database according to the target set type data includes:
[0360] If the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field, the starting position of the index, and the number of index elements all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key, the target field, the starting position and the ending position of the data value corresponding to the target field, the starting position of the index, and the number of index elements to generate a key-value pair class;
[0361] Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0362] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0363] Correspondingly, performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes:
[0364] Convert the value in the target key-value pair data into tree map class data;
[0365] Determine whether the sorting method of the elements in the tree diagram - type data is the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field;
[0366] If the sorting method of the elements in the tree diagram - type data is not the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field, then reverse - sort the elements in the tree diagram - type data to obtain the adjusted tree diagram - type data; if the sorting method of the elements in the tree diagram - type data is the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field, then do not adjust the elements in the tree diagram - type data;
[0367] Using the binary search method, determine the target element set in the tree diagram - type data according to the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value corresponding to the target field, where the data value of the target field of each target element in the target element set is greater than or equal to the starting position of the data value corresponding to the target field and less than or equal to the ending position of the data value corresponding to the target field;
[0368] If the data values corresponding to the target fields in the target elements are all of integer type, use the target element corresponding to the starting position of the index in the target element set as the starting point to determine the target elements of the number of index elements, and use the target elements of the number of index elements as the data processing result corresponding to the data processing instruction.
[0369] Next, combine Figure 9 for an example. As Figure 9 shown, the target set - type data includes the key of the key - value pair to be processed, the target field, the starting position min of the data value corresponding to the target field and the ending position max of the data value, the starting position offset of the index, and the number of index elements count. The target set operation type is the sixth query operation zrangebylex, that is, to find the values in the sorted set within the given part - of - speech range of the key / sorted - set pair. For example, there is an ordered set [a, b, c, d, e, f, g], and a subset [b, c, d, e, f] of this ordered set is filtered according to the scores min and max. offset represents the index position of this subset, and count represents how many elements to search starting from this index position. For example: offset = 0, count = 2, the search result is [b, c]; offset = 1, count = 1, the search result is [c]; offset = 1, count = 2, the search result is [c, d]; offset = 2, count = 3, the search result is [d, e, f]; offset = 2, count = 5, the search result is [d, e, f]. Specifically, it includes the following steps:
[0370] S801: Receive parameters.
[0371] For step 801, key is the target key, min is the starting value of the score range, max is the ending value of the score range, offset is the initial value of the sorted set limit quantity index, and count is the sorted set limit quantity value. Its function is to find the sorted set values within a given score range in the key / sorted set pair. min, max, offset, and count are all used to limit the range during the search. min and max are the minimum and maximum values of a closed interval, used to perform a preliminary search in the ordered set to obtain a subset of the ordered set. offset and count are then used to perform a further search within this subset of the ordered set.
[0372] S802: Initialize HetuKVItem.
[0373] For step 802, valid parameters will be passed here to initialize a HetuItem object.
[0374] S803: Initialize a TreeMap.
[0375] For step 803, initialize a TreeMap to facilitate editing operations in Java.
[0376] S804: Query whether HetuKVItem is successful.
[0377] For step 804, use HetuKVItem to query in HetuKV according to its key and determine whether the query is successful. If yes, execute S805; otherwise, execute S820.
[0378] S805: Return the Value corresponding to the key and decode it into a TreeMap.
[0379] For step 805, return the value and decode it into a TreeMap type.
[0380] S806: Extract and initialize the input parameters.
[0381] For step 806, initialize the input parameters.
[0382] S807: Traverse all input parameters.
[0383] For step 807, traverse all the input parameters and determine whether to end the traversal.
[0384] S808: Judge whether it is a String.
[0385] For step 808, determine whether the input parameter is a String. If so, execute S813; otherwise, execute S818.
[0386] S809: Determine whether "REV" appears.
[0387] For step 809, determine whether the input parameter is REV. If so, execute S810; if not, execute S807.
[0388] S810: Sort all data in reverse order.
[0389] For step 810, if "REV" appears, sort all data in reverse order.
[0390] S811: Apply binary search to the range boundaries.
[0391] For step 811, apply binary search to the range boundaries.
[0392] S812: Return the elements within the specified range.
[0393] For step 812, return the sorted set values within the given score range.
[0394] S813: Determine whether "LIMIT" appears.
[0395] For step 813, determine whether the input parameter is LIMIT. If so, execute S814; if not, execute S807.
[0396] S814: Return a sublist of the specified range.
[0397] For step 814, if LIMIT appears, return a sublist of the specified range.
[0398] S815: Determine whether "WITHSCORES" appears.
[0399] For step 815, determine whether the input parameter is WITHSCORES. If so, execute S816; if not, execute S817.
[0400] S816: Return the list and the score.
[0401] For step 816, if WITHSCORES appears, return both the value and the score.
[0402] S817: Return the list.
[0403] For step 817, if WITHSCORES does not appear, return only the value.
[0404] S818: Whether it is an Integer.
[0405] For step S818, determine whether it is of integer type. If so, execute S819; otherwise, execute S811.
[0406] S819: Add the integer to limitnumber.
[0407] For step S819, if it is of integer type, add this integer type to the limitnumber variable.
[0408] S820: Return an error code.
[0409] For step S820, it is entered when S804 fails to execute, indicating that the operation has an error and cannot proceed. At this time, the corresponding error code will be returned and the operation will end.
[0410] In one embodiment, before the step of receiving at least one data processing instruction sent by the client, the method further includes:
[0411] Receive a call instruction sent by the client; wherein, the call instruction includes a target solid-state drive identifier.
[0412] Call the solid-state drive corresponding to the target solid-state drive identifier according to the target solid-state drive identifier, and use the solid-state drive corresponding to the target solid-state drive identifier as the solid-state drive corresponding to the key-value database, and adjust the state of the solid-state drive corresponding to the key-value database to the locked state.
[0413] Correspondingly, after the step of feeding back the data processing results corresponding to each of the at least one data processing instruction to the client, the method further includes:
[0414] Release the memory of the solid-state drive corresponding to the key-value database, and adjust the state of the solid-state drive corresponding to the key-value database to the idle state.
[0415] As an example, when using the Java client to call the HetuKV key-value database, a certain solid-state drive will be specified and locked, and released after the call ends, that is, the garbage collection mechanism of the HetuKV key-value database is used to promptly release the memory occupied by the solid-state drive. In the process of locking the solid-state drive, other processes cannot use the solid-state drive. In addition, in this embodiment, data calculation is delegated to the solid-state drive, which can reduce dependence on memory, and optimize resource utilization by using the garbage collection mechanism, and lock the solid-state drive to ensure data security and reliability, thereby achieving resource optimization and security, that is, through the advantages of HetuKV, optimize resource utilization, ensure data security and reliability, and reduce memory dependence, optimize hardware resource utilization, reduce memory consumption, and make the system more flexible. In addition, it can also enhance security and control, provide complete control, and strengthen data security to ensure data security for enterprise-level applications.
[0416] So far, this embodiment has realized the processing process of the data processing method in combination with a specific application scenario. Of course, it should be considered that the above scenario is only an exemplary scenario and does not limit the method provided by the present invention. The method provided by the present invention can be extended to other data processing methods with the same principle.
[0417] like Figure 10 As shown, it is a specific embodiment of the data processing device described in this application. The device described in this embodiment is a physical device for executing the method described in the above embodiment. Its technical solution is essentially consistent with the above embodiment, and the corresponding description in the above embodiment is also applicable to this embodiment. In this embodiment, the device is applied to a solid-state hard disk corresponding to a key-value database. The device includes:
[0418] The first unit 1001 is used to receive at least one data processing instruction sent by a client; wherein each data processing instruction includes: target set type data and target set operation type;
[0419] The second unit 1002 is used to perform parallel data processing on the at least one data processing instruction to obtain the data processing results respectively corresponding to the at least one data processing instruction; wherein, for each data processing instruction, according to the target set type data, the target key-value pair data in the key-value database is determined, wherein each key-value pair data in the key-value database includes a key and at least one value, each value includes at least one ordered set, and each ordered set includes at least one element, wherein each element includes at least one field and the data value corresponding to each field, and the multiple elements in each ordered set are sorted according to the data value corresponding to the preset field; perform data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction;
[0420] The third unit 1003 is used to feedback the data processing results respectively corresponding to the at least one data processing instruction to the client.
[0421] Optionally, the target set type data includes the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field, and the target set operation type is the first addition operation.
[0422] Optionally, the second unit 1002 is used for:
[0423] If the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field all respectively conform to their corresponding preset string types, the key of the key-value pair to be processed conforms to the preset threshold condition, and each target field has a data value corresponding to it, then use the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field to generate a key-value pair class;
[0424] Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0425] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data;
[0426] If there is no key-value pair data corresponding to the key-value pair class in the key-value database, create an empty key-value pair data in the key-value database and use the empty key-value pair data as the target key-value pair data.
[0427] Optionally, the second unit 1002 is used for:
[0428] Convert the value in the target key-value pair data into tree diagram class data;
[0429] Insert the target field and the data value corresponding to the target field as an element into the tree graph data to obtain the updated tree graph data;
[0430] Convert the updated tree graph data into the value in the target key-value pair data;
[0431] Determine that the data processing result corresponding to the data processing instruction is that the element addition is successful, and the number of successfully added elements is used as the data processing result corresponding to the data processing instruction.
[0432] Optionally, the target set type data includes the key of the key-value pair to be processed, and the target set operation type is the first query operation.
[0433] Optionally, the second unit 1002 is used for:
[0434] If the key of the key-value pair to be processed conforms to the preset string type and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed to generate a key-value pair class;
[0435] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0436] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0437] Optionally, the second unit 1002 is used for:
[0438] Convert the value in the target key-value pair data into tree graph data;
[0439] Determine the number of elements in the tree graph data;
[0440] Use the number of elements in the tree graph data as the data processing result corresponding to the data processing instruction.
[0441] Optionally, the target set type data includes the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element, and the target set operation type is the second query operation.
[0442] Optionally, the second unit 1002 is used for:
[0443] If the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element conform to the preset string type, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element to generate a key-value pair class;
[0444] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0445] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0446] Optionally, the second unit 1002 is used for:
[0447] Convert the value in the target key-value pair data into tree graph class data;
[0448] Determine whether the sorting method of the elements in the tree graph class data is the same as the sorting method corresponding to the starting position and the ending position of the elements;
[0449] If the sorting method of the elements in the tree graph class data is not the same as the sorting method corresponding to the starting position and the ending position of the elements, reverse the order of the elements in the tree graph class data to obtain the adjusted tree graph class data; if the sorting method of the elements in the tree graph class data is the same as the sorting method corresponding to the starting position and the ending position of the elements, do not adjust the elements in the tree graph class data;
[0450] Using the binary search method, determine the element corresponding to the starting position of the elements and the element corresponding to the ending position of the elements in the tree graph class data according to the starting position and the ending position of the elements; use the elements from the element corresponding to the starting position of the elements to the element corresponding to the ending position of the elements as the target element set;
[0451] If the data values corresponding to the preset fields in each element of the target element set are all of integer type, use the data values corresponding to the preset fields in each element of the target element set as the data processing result corresponding to the data processing instruction.
[0452] Optionally, the target set type data includes the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field, and the target set operation type is the third query operation.
[0453] Optionally, the second unit 1002 is used for:
[0454] If the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, generate a key-value pair class using the key of the key-value pair to be processed, the starting position and the ending position of the elements;
[0455] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0456] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0457] Optionally, the second unit 1002 is used for:
[0458] Convert the value in the target key-value pair data into tree diagram class data;
[0459] Determine whether the sorting method of the elements in the tree diagram class data is the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field;
[0460] If the sorting method of the elements in the tree diagram class data is not the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field, reverse the order of the elements in the tree diagram class data to obtain the adjusted tree diagram class data; if the sorting method of the elements in the tree diagram class data is the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field, do not adjust the elements in the tree diagram class data;
[0461] Using the binary search method, according to the target field, the starting position and the ending position of the data value corresponding to the target field, determine the target element in the tree diagram class data whose data value of the target field is greater than or equal to the starting position of the data value corresponding to the target field and less than or equal to the ending position of the data value corresponding to the target field;
[0462] If the data values corresponding to the target fields in the target elements are all of integer type, use the data values corresponding to the preset fields in the target elements as the data processing results corresponding to the data processing instructions.
[0463] Optionally, the target set type data includes the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field, and the target set operation type is the fourth query operation.
[0464] Optionally, the second unit 1002 is used for:
[0465] If the key of the key-value pair to be processed, the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element to generate a key-value pair class;
[0466] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0467] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0468] Optionally, the second unit 1002 is used for:
[0469] Convert the value in the target key-value pair data into tree diagram class data;
[0470] Determine whether the sorting method of the elements in the tree diagram class data is the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field;
[0471] If the sorting method of the elements in the tree diagram class data is different from the sorting method corresponding to the starting position and the ending position of the data value of the target field, reverse the order of the elements in the tree diagram class data to obtain the adjusted tree diagram class data; if the sorting method of the elements in the tree diagram class data is the same as the sorting method corresponding to the starting position and the ending position of the data value of the target field, do not adjust the elements in the tree diagram class data;
[0472] Using the binary search method, according to the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value, determine the target element in the tree diagram class data whose data value of the target field is greater than or equal to the starting position of the data value corresponding to the target field and less than or equal to the ending position of the data value corresponding to the target field;
[0473] Use the number of target elements as the data processing result corresponding to the data processing instruction.
[0474] Optionally, the target set type data includes the key of the key-value pair to be processed, the target field, and the target element position, and the target set operation type is the fifth query operation.
[0475] Optionally, the second unit 1002 is used for:
[0476] If the key of the key-value pair to be processed, the target field, the starting position of the data value corresponding to the target field, and the ending position of the data value all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element to generate a key-value pair class;
[0477] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0478] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0479] Optionally, the second unit 1002 is used for:
[0480] Convert the value in the target key-value pair data into tree diagram class data;
[0481] According to the target element position, determine the target element corresponding to the target element position from the tree diagram class data;
[0482] Use the data value corresponding to the target field in the target element as the data processing result corresponding to the data processing instruction.
[0483] Optionally, the target set type data includes the key of the key-value pair to be processed and the target element position, and the target set operation type is a deletion operation.
[0484] Optionally, the second unit 1002 is used for:
[0485] If the key of the key-value pair to be processed and the target field both conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, use the key of the key-value pair to be processed and the target field to generate a key-value pair class;
[0486] Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0487] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0488] Optionally, the second unit 1002 is used for:
[0489] Convert the value in the target key-value pair data into tree diagram class data;
[0490] Delete the target element corresponding to the position of the target element in the tree diagram data;
[0491] Use the number of successfully deleted target elements as the data processing result corresponding to the data processing instruction.
[0492] Optionally, it is characterized in that the target set type data includes the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field, the starting position of the index, and the number of index elements, and the target set operation type is the sixth query operation.
[0493] Optionally, the second unit 1002 is used for:
[0494] If the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field, the starting position of the index, and the number of index elements all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, generate a key-value pair class by using the key, the target field, the starting position and the ending position of the data value corresponding to the target field, the starting position of the index, and the number of index elements;
[0495] Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed;
[0496] If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
[0497] Optionally, the second unit 1002 is used for:
[0498] Convert the value in the target key-value pair data into tree diagram data;
[0499] Judge whether the sorting method of the elements in the tree diagram data is the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field;
[0500] If the sorting method of the elements in the tree diagram data is not the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field, reverse the order of the elements in the tree diagram data to obtain the adjusted tree diagram data; if the sorting method of the elements in the tree diagram data is the same as the sorting method corresponding to the starting position and the ending position of the data value corresponding to the target field, do not adjust the elements in the tree diagram data;
[0501] Using a binary search method, according to the target field, the starting position and the ending position of the data value corresponding to the target field, determine a set of target elements in the tree graph data, where the data value of the target field of each target element in the set of target elements is greater than or equal to the starting position of the data value corresponding to the target field and less than or equal to the ending position of the data value corresponding to the target field;
[0502] If the data values corresponding to the target fields in the target elements are all of integer type, use the target element corresponding to the starting position of the index in the set of target elements as the starting point to determine the target elements with the number of index elements, and use the target elements with the number of index elements as the data processing result corresponding to the data processing instruction.
[0503] Optionally, the client is a Java client, and the key-value database is a co-storage key-value database.
[0504] Optionally, the device further includes a fourth unit for:
[0505] Receive a call instruction sent by the client; where the call instruction includes a target solid-state drive identifier;
[0506] Call the solid-state drive corresponding to the target solid-state drive identifier according to the target solid-state drive identifier, and use the solid-state drive corresponding to the target solid-state drive identifier as the solid-state drive corresponding to the key-value database, and adjust the state of the solid-state drive corresponding to the key-value database to a locked state.
[0507] Optionally, the fourth unit is used for, after the step of feeding back the data processing results corresponding to each of the at least one data processing instruction to the client respectively, the method further includes:
[0508] Release the memory of the solid-state drive corresponding to the key-value database, and adjust the state of the solid-state drive corresponding to the key-value database to an idle state.
[0509] Figure 11 It is a schematic structural diagram of an electronic device provided by an embodiment of the present invention. At the hardware level, the electronic device includes a processor, and optionally also includes an internal bus, a network interface, and a memory. Among them, the memory may include a memory, such as a high-speed random access memory (Random-Access Memory, RAM), and may also include a non-volatile memory, such as at least one disk memory, etc. Of course, the electronic device may also include other hardware required for other services.
[0510] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 11 only a bidirectional arrow is used in
[0511] Memory, for storing executable instructions. Specifically, executable instructions are computer programs that can be executed. The memory can include a memory and a non-volatile memory, and provide executable instructions and data to the processor.
[0512] In a possible implementation, the processor reads the corresponding executable instructions from the non-volatile memory into the memory and then runs them, or can also obtain the corresponding executable instructions from other devices to form a data processing device at the logical level. The processor executes the executable instructions stored in the memory to implement the data processing method provided in any embodiment of the present invention through the executed executable instructions.
[0513] The above as in the present invention Figure 1 The method executed by the data processing device provided in the embodiments shown can be applied to the processor or implemented by the processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, the steps of the above method can be completed by the integrated logic circuit in the hardware of the processor or instructions in software form. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc.
[0514] The steps of the method disclosed in the embodiments of the present invention can be directly implemented by a hardware decoding processor, or implemented by a combination of hardware and software modules in the decoding processor. The software module can be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory, and the processor reads the information in the memory and combines its hardware to complete the steps of the above method.
[0515] The embodiments of the present invention also propose a readable medium. When the execution instructions stored in this readable storage medium are executed by the processor of an electronic device, the electronic device can execute the data processing method provided in any embodiment of the present invention, and is specifically used to execute the method described in the above data query.
[0516] The electronic device described in each of the foregoing embodiments may be a computer.
[0517] Those skilled in the art should understand that the embodiments of the present invention can be provided as a method or a computer program product. Therefore, the present invention can adopt a completely hardware embodiment, a completely software embodiment, or a form combining software and hardware.
[0518] The embodiments of the present invention are described in a progressive manner. The same or similar parts among the embodiments can be referred to each other, and the differences between each embodiment and other embodiments are emphasized. In particular, for the device embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can refer to the description of the method embodiments.
[0519] It should also be noted that the term "including", "comprising" or any other variant thereof is intended to cover a non-exclusive inclusion, so that a process, method, commodity or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. Without further limitation, the element defined by the statement "including one..." does not exclude the existence of another identical element in the process, method, commodity or device including the said element.
[0520] The above description is only for the embodiments of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention can have various changes and modifications. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included within the scope of the claims of the present invention.
Claims
1. A data processing method, characterized in that, The method is applied to a solid-state drive corresponding to a key-value database. The method includes: Receiving at least one data processing instruction sent by a client; wherein, each data processing instruction includes: target set type data, target set operation type; Performing parallel data processing on the at least one data processing instruction to obtain data processing results respectively corresponding to the at least one data processing instruction; wherein, for each data processing instruction, according to the target set type data, determining target key-value pair data in the key-value database, wherein each key-value pair data in the key-value database includes a key and at least one value, each value includes at least one ordered set, and each ordered set includes at least one element, wherein each element includes at least one field and data values corresponding to each field, and multiple elements in each ordered set are sorted according to data values corresponding to a preset field; performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction; Feeding back the data processing results respectively corresponding to the at least one data processing instruction to the client; Wherein, the target set type data includes the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element, and the target set operation type is a second query operation; The determining the target key-value pair data in the key-value database according to the target set type data includes: If the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element conform to a preset string type, and the key of the key-value pair to be processed conforms to a preset threshold condition, generating a key-value pair class by using the key of the key-value pair to be processed, the starting position of the element, and the ending position of the element; Judging whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed; If there is key-value pair data corresponding to the key-value pair class in the key-value database, taking the key-value pair data corresponding to the key-value pair class as the target key-value pair data; Wherein, the performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes: Converting the value in the target key-value pair data into tree graph class data; Judging whether the sorting method of elements in the tree graph class data is the same as the sorting method corresponding to the starting position of the element and the ending position of the element; If the sorting method of elements in the tree graph class data is not the same as the sorting method corresponding to the starting position of the element and the ending position of the element, performing reverse sorting on the elements in the tree graph class data to obtain adjusted tree graph class data; if the sorting method of elements in the tree graph class data is the same as the sorting method corresponding to the starting position of the element and the ending position of the element, no adjustment is made to the elements in the tree graph class data; Using the binary search method, determine the element corresponding to the starting position of the element and the element corresponding to the ending position of the element in the tree graph data according to the starting position of the element and the ending position of the element; use the element corresponding to the starting position of the element to the element corresponding to the ending position of the element as the target element set; If the data values corresponding to the preset fields in each element of the target element set are all of integer type, use the data values corresponding to the preset fields in each element of the target element set as the data processing result corresponding to the data processing instruction.
2. The method according to claim 1, characterized in that The target set type data includes the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field, and the target set operation type is the first addition operation.
3. The method according to claim 2, wherein The determining the target key-value pair data in the key-value database according to the target set type data includes: If the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field all conform to their respective preset string types, the key of the key-value pair to be processed conforms to the preset threshold condition, and each target field has a corresponding data value, then use the key of the key-value pair to be processed, the target field, and the data value corresponding to the target field to generate a key-value pair class; Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed; If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data; If there is no key-value pair data corresponding to the key-value pair class in the key-value database, create an empty key-value pair data in the key-value database and use the empty key-value pair data as the target key-value pair data.
4. The method according to claim 3, characterized in that, The performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes: Convert the value in the target key-value pair data into tree graph data; Insert the target field and the data value corresponding to the target field as an element into the tree graph data to obtain the updated tree graph data; Convert the updated tree graph data into the value in the target key-value pair data; Determine that the data processing result corresponding to the data processing instruction is that the element addition is successful, and the number of successfully added elements is used as the data processing result corresponding to the data processing instruction.
5. The method according to claim 1, characterized in that, The target set type data includes the key of the key-value pair to be processed, and the target set operation type is the first query operation.
6. The method according to claim 5, characterized in that, The determining the target key-value pair data in the key-value database according to the target set type data includes: If the key of the key-value pair to be processed conforms to the preset string type and the key of the key-value pair to be processed conforms to the preset threshold condition, then use the key of the key-value pair to be processed to generate a key-value pair class; Judge whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed; If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
7. The method according to claim 6, wherein Performing data processing corresponding to the target set operation type on the target key-value pair data to obtain a data processing result corresponding to the data processing instruction includes: Converting the value in the target key-value pair data into tree diagram class data; Determining the number of elements in the tree diagram class data; Using the number of elements in the tree diagram class data as the data processing result corresponding to the data processing instruction.
8. The method according to claim 1, wherein The target set type data includes the key of the key-value pair to be processed, the target field, and the target element position, and the target set operation type is the fifth query operation.
9. The method according to claim 8, wherein Determining the target key-value pair data in the key-value database according to the target set type data includes: If the key of the key-value pair to be processed, the target field, the starting position and the ending position of the data value corresponding to the target field all conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, generate a key-value pair class by using the key of the key-value pair to be processed, the starting position of the element and the ending position of the element; Judging whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed; If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
10. The method according to claim 9, wherein Performing data processing corresponding to the target set operation type on the target key-value pair data to obtain a data processing result corresponding to the data processing instruction includes: Converting the value in the target key-value pair data into tree diagram class data; Determining the target element corresponding to the target element position from the tree diagram class data according to the target element position; Using the data value corresponding to the target field in the target element as the data processing result corresponding to the data processing instruction.
11. The method according to claim 1, characterized in that, The target set type data includes the key of the key-value pair to be processed and the target element position, and the target set operation type is a deletion operation.
12. The method according to claim 11, wherein Determining the target key-value pair data in the key-value database according to the target set type data includes: If the key of the key-value pair to be processed and the target field both conform to their respective preset string types, and the key of the key-value pair to be processed conforms to the preset threshold condition, generate a key-value pair class by using the key of the key-value pair to be processed and the target field; Judging whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed; If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data.
13. The method according to claim 12, characterized in that, Performing data processing corresponding to the target set operation type on the target key-value pair data to obtain a data processing result corresponding to the data processing instruction includes: Converting the value in the target key-value pair data into tree diagram class data; Delete the target element corresponding to the target element position in the tree diagram - type data; Use the number of successfully deleted target elements as the data processing result corresponding to the data processing instruction.
14. The method according to any one of claims 1-13, characterized in that, The client is a Java client, and the key - value database is a co - storage key - value database.
15. According to the method described in any one of claims 1-13, characterized in that, Before the step of receiving at least one data processing instruction sent by the client, the method further includes: Receive a call instruction sent by the client; wherein, the call instruction includes a target solid - state drive identifier; Call the solid - state drive corresponding to the target solid - state drive identifier according to the target solid - state drive identifier, and use the solid - state drive corresponding to the target solid - state drive identifier as the solid - state drive corresponding to the key - value database, and adjust the state of the solid - state drive corresponding to the key - value database to the locked state.
16. The method according to claim 15, characterized in that, After the step of feeding back the data processing results corresponding to each of the at least one data processing instruction to the client, the method further includes: Release the memory of the solid - state drive corresponding to the key - value database, and adjust the state of the solid - state drive corresponding to the key - value database to the idle state.
17. A data processing device, characterized in that, The device is applied to the solid - state drive corresponding to the key - value database, and the device includes: A first unit for receiving at least one data processing instruction sent by the client; wherein each data processing instruction includes: target set - type data, target set operation type; A second unit for performing parallel data processing on the at least one data processing instruction to obtain the data processing results corresponding to each of the at least one data processing instruction; wherein, for each data processing instruction, determine the target key - value pair data in the key - value database according to the target set - type data, wherein each key - value pair data in the key - value database includes a key and at least one value, each value includes at least one ordered set, and each ordered set includes at least one element, wherein each element includes at least one field and the data values corresponding to each field, and the multiple elements in each ordered set are sorted according to the data values corresponding to the preset fields; perform the data processing corresponding to the target set operation type on the target key - value pair data to obtain the data processing result corresponding to the data processing instruction; A third unit for feeding back the data processing results corresponding to each of the at least one data processing instruction to the client; Wherein, the target set - type data includes the key of the key - value pair to be processed, the starting position of the element, and the ending position of the element, and the target set operation type is a second query operation; The determining the target key - value pair data in the key - value database according to the target set - type data includes: If the key of the key - value pair to be processed, the starting position of the element, and the ending position of the element conform to the preset string type, and the key of the key - value pair to be processed conforms to the preset threshold condition, generate a key - value pair class using the key of the key - value pair to be processed, the starting position of the element, and the ending position of the element; Determine whether there is key-value pair data corresponding to the key-value pair class in the key-value database; wherein, the key in the key-value pair data is the same as the key of the key-value pair to be processed; If there is key-value pair data corresponding to the key-value pair class in the key-value database, use the key-value pair data corresponding to the key-value pair class as the target key-value pair data; Among them, performing data processing corresponding to the target set operation type on the target key-value pair data to obtain the data processing result corresponding to the data processing instruction includes: Convert the value in the target key-value pair data into tree diagram class data; Determine whether the sorting method of the elements in the tree diagram class data is the same as the sorting method corresponding to the element start position and the element end position; If the sorting method of the elements in the tree diagram class data is different from the sorting method corresponding to the element start position and the element end position, perform reverse sorting on the elements in the tree diagram class data to obtain the adjusted tree diagram class data; if the sorting method of the elements in the tree diagram class data is the same as the sorting method corresponding to the element start position and the element end position, do not adjust the elements in the tree diagram class data; Using the binary search method, determine the element corresponding to the element start position and the element corresponding to the element end position in the tree diagram class data according to the element start position and the element end position; use the element corresponding to the element start position to the element corresponding to the element end position as the target element set; If the data values corresponding to the preset fields in each element of the target element set are all of integer type, use the data values corresponding to the preset fields in each element of the target element set as the data processing result corresponding to the data processing instruction.
18. A readable medium includes execution instructions. When a processor of an electronic device executes the execution instructions, the electronic device executes the method according to any one of claims 1 to 16.
19. An electronic device includes a processor and a memory storing execution instructions. When the processor executes the execution instructions stored in the memory, the processor executes the method according to any one of claims 1 to 16.
Citation Information
Patent Citations
Binary serialization method and system for key value pair set type
CN113867703A
Data processing method and device, retrieval method and device, equipment and storage medium
CN116521816A