Data storage method and device, computer equipment and storage medium
By copying and generating temporary arrays when the loop array reaches its capacity, the problem that fixed field loop arrays cannot flexibly store data with varying sizes is solved, and flexible expansion of loop arrays and seamless data migration is realized, ensuring data security Sex and consistency.
Patent Information
- Application Number
- CN202411158410.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-21
- Publication Date
- 2024-12-27
- Estimated Expiration
- 2044-08-21
AI Technical Summary
Fixed field loop arrays cannot flexibly store data with varying sizes, resulting in space waste and data loss or complex data migration problems when data volume fluctuates greatly.
By copying and generating temporary arrays when the loop array reaches capacity, storing data, and migrating data to the original array after the temporary array is filled, ensuring data integrity and consistency, avoiding data loss and processing interruptions.
It realizes flexible expansion of circular arrays and seamless data migration, reduces system resource waste, simplifies data access logic, and ensures data security and consistency.
Smart Images

Figure CN119202319A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the field of big data technology, and specifically relates to a data storage method, apparatus, computer equipment, and storage medium. Background Art
[0002] A fixed-field circular array is a data structure that combines the features of an array and a circular queue. In this storage method, each array element is designed to be a fixed size and is used to store a data field of a specific type. As data is added to the array, it fills the array space sequentially and loops back to the beginning when the end of the array is reached. Fixed-field circular arrays are suitable for scenarios that require frequent insertions and deletions but do not require the retention of old data, such as buffer management and real-time data processing.
[0003] However, fixed-field circular arrays also have some drawbacks. For example, because each field has a fixed size, they cannot store data of varying sizes, which limits their application scenarios. When the amount of data to be stored is much smaller than the total capacity of the array, the remaining space is wasted, especially in systems with large data fluctuations. When more data needs to be stored, if the fixed-size array is full, it may be necessary to overwrite the data or reallocate a larger array for data migration. The former can result in data loss, while the latter increases the complexity and cost of the operation. Summary of the Invention
[0004] The purpose of the embodiments of the present application is to propose a data storage method, apparatus, computer equipment and storage medium, aiming to provide a method for changing the capacity of a cyclic array to achieve flexible data storage.
[0005] In order to solve the above technical problems, the present application provides a data storage method, which adopts the following technical solutions:
[0006] A data storage method is applied to a circular array in a database storage structure, comprising:
[0007] Receive a data storage instruction, determine the amount of data to be stored and the storage margin of the loop array;
[0008] When the amount of data to be stored is greater than the storage margin of the loop array, the loop array is copied to generate a temporary loop array;
[0009] Storing the data to be stored in the temporary circular array until the temporary circular array is filled, and storing the unfinished data to be stored in the circular array;
[0010] Receive a storage update instruction, point the data pointer to the temporary loop array, and delete the loop array.
[0011] Furthermore, the loop array is configured with a matching index array. When the amount of data to be stored is greater than the storage margin of the loop array, the loop array is copied to generate a temporary loop array, and the method further includes:
[0012] Copy the index array of the loop array to obtain a temporary index array, wherein the temporary index array matches the temporary loop array;
[0013] Clear the stored data in the loop array and update the index array.
[0014] Furthermore, the data to be stored is stored in the temporary circular array until the temporary circular array is filled, and the unfinished data to be stored is stored in the circular array, specifically including:
[0015] Determine the data starting position of the data to be stored in the temporary loop array based on the temporary index array to obtain the first data starting position;
[0016] Point the data pointer of the database to the temporary circular array, and fill the data to be stored in the temporary circular array in sequence starting from the first data position until the temporary circular array is filled;
[0017] Determine the remaining amount of data to be stored, point the data pointer to the circular array, and fill the remaining amount of data to be stored into the circular array in sequence starting from the initial storage position of the circular array until the storage of the data to be stored is completed.
[0018] Furthermore, after the data pointer of the database is pointed to the temporary circular array, the data to be stored is sequentially filled into the temporary circular array starting from the starting position of the first data until the temporary circular array is filled, the method further includes:
[0019] Determine whether the remaining amount of data to be stored is greater than the data storage capacity of the circular array;
[0020] When the remaining amount of data to be stored is greater than the data storage capacity of the circular array, the emptied circular array is copied to generate a new circular array.
[0021] Furthermore, before receiving the storage update instruction, pointing the data pointer to the temporary loop array, and deleting the loop array, the method further includes:
[0022] Receive a data reading instruction and determine a storage location of the data to be read in the database, wherein the data reading instruction carries a data reading location identifier;
[0023] When the data to be read is stored in the circular array or the temporary circular array, intercepting and copying the data to be read in the circular array or the temporary circular array based on the data reading position identifier, generating a first data reading result, and outputting the first data reading result;
[0024] When the data to be read is stored in the circular array and the temporary circular array at the same time, the position of the data reading position identifier in the temporary circular array is determined, and a first data segment to be read is obtained from the temporary circular array. The position of the data reading position identifier in the circular array is determined, and a second data segment to be read is obtained from the circular array. A second data reading result is generated based on the first data segment to be read and the second data segment to be read, and the second data reading result is output.
[0025] Furthermore, the data read position identifier includes a read data start bit and a read data end bit, determining a position of the data read position identifier in a temporary circular array, obtaining a first to-be-read data segment from the temporary circular array, determining a position of the data read position identifier in the circular array, obtaining a second to-be-read data segment from the circular array, generating a second data read result based on the first to-be-read data segment and the second to-be-read data segment, and outputting the second data read result, specifically includes:
[0026] When the read data start bit is located in the temporary loop array and the read data end bit is located in the loop array, determining a first to-be-read data segment based on the temporary index array and the read data start bit, and determining a second to-be-read data segment based on the index array and the read data end bit;
[0027] When the read data start bit is located in the circular array and the read data end bit is located in the temporary circular array, determining a first to-be-read data segment based on the index array and the read data start bit, and determining a second to-be-read data segment based on the temporary index array and the read data end bit;
[0028] The first to-be-read data segment and the second to-be-read data segment are combined to generate a second data reading result, and the second data reading result is output.
[0029] Furthermore, after receiving the data storage instruction and determining the amount of data to be stored and the storage margin of the loop array, the method further includes:
[0030] When the amount of the data to be stored is less than or equal to the storage margin of the circular array, determining the data start position of the data to be stored in the circular array based on the index array to obtain a second data start position;
[0031] The data pointer is pointed to the circular array, and the data to be stored is sequentially filled into the circular array starting from the second data starting position until the storage of the data to be stored is completed.
[0032] In order to solve the above technical problems, the embodiment of the present application further provides a data storage device, which adopts the following technical solution:
[0033] A data storage device, the data storage device executes the above-mentioned data storage method, the data storage method is applied to a circular array in a database storage structure, the data storage device comprising:
[0034] A storage instruction receiving module is used to receive a data storage instruction and determine the amount of data to be stored and the storage margin of the loop array;
[0035] A first array copy module is used to copy the circular array to generate a temporary circular array when the amount of data to be stored is greater than the storage margin of the circular array;
[0036] A data storage module is used to store the data to be stored in the temporary circular array until the temporary circular array is filled, and store the unfinished data to be stored in the circular array;
[0037] The storage update instruction module is used to receive the storage update instruction, point the data pointer to the temporary loop array, and delete the loop array.
[0038] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:
[0039] A computer device comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of any of the above-mentioned data storage methods when executing the computer-readable instructions.
[0040] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0041] A computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of any one of the above-mentioned data storage methods.
[0042] Compared with the prior art, the embodiments of the present application have the following beneficial effects:
[0043] A data storage method, apparatus, computer equipment and storage medium belong to the field of big data technology. The data storage method is applied to a circular array in a database storage structure. Compared with traditional storage solutions that simply reject new data or overwrite old data when the amount of data to be stored exceeds the capacity of the current circular array, the present application adopts a strategy of copying the original circular array to a temporary array, thereby retaining the integrity of the original array data and ensuring the consistency and security of the data. It can also efficiently handle the continuous storage needs of large amounts of data and avoid data loss or processing interruptions due to capacity limitations. After completing partial data storage in the temporary circular array, the remaining data is then added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating the data pointer and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] In order to more clearly illustrate the solutions in this application, a brief introduction will be given below to the drawings required for use in the description of the embodiments of this application. Obviously, the drawings described below are some embodiments of this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0045] Figure 1 shows an exemplary system architecture diagram in which the present application can be applied;
[0046] Figure 2 A flow chart showing an embodiment of a data storage method according to the present application is shown;
[0047] Figure 3 A schematic structural diagram of an embodiment of a data storage device according to the present application is shown;
[0048] Figure 4 A schematic structural diagram of an embodiment of a computer device according to the present application is shown. DETAILED DESCRIPTION
[0049] Unless otherwise defined, all technical and scientific terms used herein have the same meanings as commonly understood by those skilled in the art to which this application belongs. The terms used in the specification of the application are for the purpose of describing specific embodiments only and are not intended to limit this application. The terms "including" and "having" and any variations thereof in the specification and claims of this application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of this application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.
[0050] References herein to "embodiments" mean that a particular feature, structure, or characteristic described in connection with the embodiments may be included in at least one embodiment of the present application. The appearance of this phrase in various places in the specification does not necessarily refer to the same embodiment, nor does it constitute an independent or alternative embodiment that is mutually exclusive of other embodiments. It is understood, both explicitly and implicitly, by those skilled in the art that the embodiments described herein may be combined with other embodiments.
[0051] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.
[0052] like Figure 1 As shown, system architecture 100 may include a terminal device 101, a network 102, and a server 103. Terminal device 101 may be a laptop computer 1011, a tablet computer 1012, or a mobile phone 1013. Network 102 is a medium for providing a communication link between terminal device 101 and server 103. Network 102 may include various connection types, such as wired or wireless communication links or fiber optic cables.
[0053] The user can use the terminal device 101 to interact with the server 103 via the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.
[0054] The terminal device 101 can be various electronic devices with a display screen and supporting web browsing. In addition to the laptop computer 1011, tablet computer 1012 or mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV) player, a laptop computer and a desktop computer, etc.
[0055] The server 103 may be a server that provides various services, such as a background server that provides support for web pages displayed on the terminal device 101 .
[0056] It should be noted that the data storage method provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the data storage device is generally set in the server / terminal device.
[0057] It should be understood that Figure 1 The numbers of terminal devices, networks and servers in the embodiment are merely illustrative. The above system may have any number of terminal devices, networks and servers according to implementation requirements.
[0058] Continue to refer Figure 2 , which shows a flow chart of an embodiment of the data storage method according to the present application. The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Artificial Intelligence (AI) is the theory, method, technology, and application system that uses digital computers or machines controlled by digital computers to simulate, extend, and expand human intelligence, perceive the environment, acquire knowledge, and use knowledge to achieve optimal results.
[0059] Basic AI technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing, operating / interactive systems, and mechatronics. AI software technologies primarily encompass computer vision, robotics, biometrics, speech processing, natural language processing, and machine learning / deep learning. The data storage method includes the following steps:
[0060] S201, receiving a data storage instruction, and determining the amount of data to be stored and the storage margin of the loop array.
[0061] A circular array is a special data structure where the positions of elements in the array are circular. When an index reaches the end of the array, the next element will be placed at the beginning of the array. In a circular array, you can use the modulo operator (%) to map the index to the correct position. For example, if you have a circular array of length n, the index will start at 0, then 1, 2, ..., n-1, then start at 0 again, and so on.
[0062] The loop array is configured with a corresponding index array, and the effect of loop indexing can be indirectly achieved by configuring the index array. For example, there is a loop array arr with a length of 5, whose elements are [a, b, c, d, e]. When configuring the index array, you can design a strategy to simulate the access method of the loop index. For example, you can create an index array indices containing a series of configured index values (such as [0, 1, 2, 3, 4]), and then access the elements in arr in the order in indices, thereby achieving a specific access pattern.
[0063] Specifically, after receiving a data storage instruction, the system first needs to evaluate the amount of data to be stored and the remaining capacity of the current circular array. By comparing the amount of data to be stored with the remaining capacity of the current circular array, the system determines the direction of subsequent operations. For example, if a batch of log information is to be stored, the system will first calculate the total size of this batch of logs and compare it with the remaining space in the circular array. If the remaining space is sufficient, storage will be carried out directly; if it is insufficient, an array copy operation will be triggered to expand the data storage capacity, ensuring effective planning and resource allocation of data before storage.
[0064] S202 : When the amount of data to be stored is greater than the storage margin of the circular array, the circular array is copied to generate a temporary circular array.
[0065] Specifically, when the amount of data to be stored exceeds the storage capacity of the circular array, a strategy is adopted to copy the original circular array to generate a temporary array, improving the flexibility and security of data processing. This copy operation ensures that the data in the original array is not corrupted or lost during the expansion process. For example, in a video playback application, if the cached video clip exceeds the capacity of the circular buffer, the system will copy the contents of the current buffer to a new temporary buffer to make room for the new video clip, not only preserving the old data but also preparing for the addition of new data.
[0066] S203 , storing the data to be stored in the temporary circular array until the temporary circular array is filled, and storing the unfinished data to be stored in the circular array.
[0067] Specifically, the temporary circular array continues to store data until it is full. Once the temporary circular array is full, the remaining data is stored in the original circular array according to a predetermined strategy (such as overwriting the oldest data or overwriting based on priority), ensuring the integrity and order of the data. For example, in a real-time data acquisition system, when the temporary buffer is full, new data points are added to the starting position of the original buffer, overwriting the oldest data points, thus maintaining the real-time and up-to-date nature of the data.
[0068] S204, receiving a storage update instruction, pointing the data pointer to the temporary loop array, and deleting the loop array.
[0069] Specifically, when a temporary circular array is fully utilized, the system seamlessly switches storage structures by updating the data pointer and deleting the original circular array. This simplifies the logic for subsequent data access and reduces system resource usage. For example, in IoT device data logging, once new data has been completely written to the temporary array and verified to be correct, the system updates the data pointer to point to the temporary array and deletes the old circular array, ensuring that all subsequent data accesses are directed to the latest dataset. Deleting the circular array signifies the successful completion of the data storage cycle and prepares for the next round of data storage.
[0070] In the above embodiment, the present application discloses a data storage method, which belongs to the field of big data technology. The data storage method is applied to a circular array in a database storage structure. Compared with the traditional storage solution, when the amount of data to be stored exceeds the capacity of the current circular array, the method simply rejects the new data or overwrites the old data. In this application, the strategy of copying the original circular array to a temporary array is adopted, thereby retaining the integrity of the original array data and ensuring the consistency and security of the data. It can also efficiently handle the continuous storage requirements of a large amount of data, avoiding data loss or processing interruption due to capacity limitations. After completing part of the data storage in the temporary circular array, the remaining data is then added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating the data pointer and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0071] Furthermore, the loop array is configured with a matching index array. When the amount of data to be stored is greater than the storage margin of the loop array, the loop array is copied to generate a temporary loop array, and the method further includes:
[0072] Copy the index array of the loop array to obtain a temporary index array, wherein the temporary index array matches the temporary loop array;
[0073] Clear the stored data in the loop array and update the index array.
[0074] This embodiment further introduces a synchronous update mechanism for the index array. When the amount of data to be stored exceeds the capacity of the loop array, not only is the loop array copied to create a temporary loop array for continued storage, but the index array is also copied to create a temporary index array to match the temporary loop count. Subsequently, the data in the original loop array is cleared, and the index array is updated to reflect the new data storage state, providing an accurate index basis for subsequent data operations.
[0075] This step ensures that the data index remains consistent with the data itself during the expansion process, avoids the destruction of data accessibility due to expansion operations, effectively maintains the consistency of data structure and index, and improves the flexibility and reliability of data management.
[0076] Furthermore, the data to be stored is stored in the temporary circular array until the temporary circular array is filled, and the unfinished data to be stored is stored in the circular array, specifically including:
[0077] Determine the data starting position of the data to be stored in the temporary loop array based on the temporary index array to obtain the first data starting position;
[0078] Point the data pointer of the database to the temporary circular array, and fill the data to be stored in the temporary circular array in sequence starting from the first data position until the temporary circular array is filled;
[0079] Determine the remaining amount of data to be stored, point the data pointer to the circular array, and fill the remaining amount of data to be stored into the circular array in sequence starting from the initial storage position of the circular array until the storage of the data to be stored is completed.
[0080] In this embodiment, a temporary index array is first used to precisely locate the starting position of the data in the temporary circular array, ensuring the storage of the data to be stored in the temporary circular array and achieving orderly and accurate data storage. Subsequently, the data pointer is sequentially moved to continuously fill the temporary circular array with data to be stored until its capacity is full. For any remaining unstored data, the data pointer is switched to the original circular array and storage continues from its initial position, effectively utilizing the remaining space in the original array.
[0081] For example, there is an initial circular array arr with a capacity of 5. It currently stores the following data (indexed starting at 0): arr = [0, 1, 2, 3, 4]. At the same time, there is an index array indexes matching arr, which is used to record a specific order or logical position of the data in arr: indexes = [0, 1, 2, 3, 4]. Now, a new batch of data to be stored [5, 6, 7, 8, 9, 10] is received, which exceeds the current capacity of arr. According to the above scheme, arr and indexes are first copied to the temporary circular array temp_arr = [0', 1', 2', 3', 4'] and the temporary index array temp_indexes = [0', 1', 2', 3', 4']. Then, the position in temp_arr where the new data begins to be stored is determined (here, it is assumed to start at index 0 because temp_arr is newly created and is completely empty or overwritable). Next, the data pointer is set to point to the temporary circular array temp_arr, and new data [5, 6, 7, 8, 9] is sequentially filled in starting from index 0, i.e., temp_arr = [5, 6, 7, 8, 9]. After temp_arr is filled, the remaining amount of data to be stored is determined to be 1 (i.e., the number 10). Finally, the data pointer is set to point to the circular array arr, and starting from its initial position (index 0), the remaining data to be stored (10) is filled into arr, now arr = [10, 1', 2', 3', 4'].
[0082] This step enables efficient allocation and storage of data exceeding the capacity of the original array between the temporary loop array and the original loop array, which not only optimizes the efficiency of data storage but also ensures the integrity and continuity of the data.
[0083] Furthermore, after the data pointer of the database is pointed to the temporary circular array, the data to be stored is sequentially filled into the temporary circular array starting from the starting position of the first data until the temporary circular array is filled, the method further includes:
[0084] Determine whether the remaining amount of data to be stored is greater than the data storage capacity of the circular array;
[0085] When the remaining amount of data to be stored is greater than the data storage capacity of the circular array, the emptied circular array is copied to generate a new circular array.
[0086] In this embodiment, when storing data that exceeds the capacity of the current circular array, after the temporary circular array is filled, the system first evaluates whether the amount of data remaining to be stored still exceeds the capacity of the original circular array. If so, further capacity expansion measures are taken, namely, copying the emptied original circular array to generate one or more new circular arrays until the new circular arrays and the original circular array can accommodate the remaining data to provide more storage space.
[0087] It should be noted that when the amount of data remaining to be stored exceeds the capacity of the original circular array, it is necessary to copy the cleared original circular array to generate one or more new circular arrays. At this time, the database simultaneously contains the original circular array, temporary circular array and new circular array. When storing data, the priority of the above circular arrays is temporary circular array, new circular array, and original circular array.
[0088] This step ensures that the system can respond flexibly even when large amounts of data arrive continuously. By continuously generating new circular arrays to continuously store data, it avoids storage failures caused by data overflow, effectively improving the flexibility and scalability of data storage, and is particularly suitable for scenarios that require continuous, large-scale data processing.
[0089] Furthermore, before receiving the storage update instruction, pointing the data pointer to the temporary loop array, and deleting the loop array, the method further includes:
[0090] Receive a data reading instruction and determine a storage location of the data to be read in the database, wherein the data reading instruction carries a data reading location identifier;
[0091] When the data to be read is stored in the circular array or the temporary circular array, intercepting and copying the data to be read in the circular array or the temporary circular array based on the data reading position identifier, generating a first data reading result, and outputting the first data reading result;
[0092] When the data to be read is stored in the circular array and the temporary circular array at the same time, the position of the data reading position identifier in the temporary circular array is determined, and a first data segment to be read is obtained from the temporary circular array. The position of the data reading position identifier in the circular array is determined, and a second data segment to be read is obtained from the circular array. A second data reading result is generated based on the first data segment to be read and the second data segment to be read, and the second data reading result is output.
[0093] In this embodiment, the system receives data read instructions and parses the location identifiers they carry, accurately locating the storage location of the data to be read in a loop array or a temporary loop array. For data stored in a single array, the required data is directly intercepted and copied within that array, enabling rapid reading and output. However, when data is stored in two arrays due to expansion strategies, intelligent location identification is required to retrieve data in segments from both the temporary loop array and the loop array, and then merge them to generate a complete data read result.
[0094] This step not only ensures the accuracy and completeness of data reading, but also improves the flexibility and efficiency of data processing. Especially when processing large-scale, dynamically changing data sets, it can significantly reduce data access delays and errors, and improve user experience and system stability.
[0095] Furthermore, the data read position identifier includes a read data start bit and a read data end bit, determining a position of the data read position identifier in a temporary circular array, obtaining a first to-be-read data segment from the temporary circular array, determining a position of the data read position identifier in the circular array, obtaining a second to-be-read data segment from the circular array, generating a second data read result based on the first to-be-read data segment and the second to-be-read data segment, and outputting the second data read result, specifically includes:
[0096] When the read data start bit is located in the temporary loop array and the read data end bit is located in the loop array, determining a first to-be-read data segment based on the temporary index array and the read data start bit, and determining a second to-be-read data segment based on the index array and the read data end bit;
[0097] When the read data start bit is located in the circular array and the read data end bit is located in the temporary circular array, determining a first to-be-read data segment based on the index array and the read data start bit, and determining a second to-be-read data segment based on the temporary index array and the read data end bit;
[0098] The first to-be-read data segment and the second to-be-read data segment are combined to generate a second data reading result, and the second data reading result is output.
[0099] In this embodiment, when a data read operation spans both the temporary loop array and the original loop array, the system intelligently determines the start and end bit locations of the data to be read, flexibly utilizing the temporary index array and the original index array to determine the data segments to be read from each array. These two data segments are then combined into a complete read result, which is then output to the user. The start and end bit locations of the read operation determine which index array is used to locate the data. The temporary index array is used for the temporary loop array, while the index array is used for the original loop array, ensuring accurate data location.
[0100] Using the temporary index array and the read data start bit, the system determines the first data segment to be read. The system then searches the temporary index array for the data location corresponding to the start bit and extracts data from that location until it reaches the boundary between the temporary loop array and the original loop array, or until it reaches an internal logical breakpoint for the read operation. Similarly, if the start bit is located in the original loop array, the system uses the index array and the read data start bit to determine the first data segment to be read.
[0101] When the end bit is in the original loop array, the index array and the read data end bit are used to determine the second data segment to be read. The system can accurately locate the end bit in the original loop array and extract the data from the starting boundary to the end bit. Similarly, if the end bit is in the temporary index array, the temporary index array and the read data end bit are used to determine the second data segment to be read.
[0102] Assume that there is an original loop array arr and a temporary loop array temp_arr, as well as their corresponding index arrays indies and temporary index arrays temp_indies, as follows:
[0103] Loop array arr = [f, g, h, 3, 4], index array indices = [0, 1, 2, 3, 4];
[0104] Temporary loop array temp_arr = [a, b, c, d, e], temporary index array temp_i nd i ces = [0', 1', 2', 3', 4'];
[0105] Now, there is a read data instruction that requires reading from position 2' to the end of position 2. Among them, position 2' is in temp_arr, and position 2 is in arr. The physical position corresponding to position 2' is found in temp_i nd i ces, and the data starting from this position is extracted from temp_arr until the end of temp_arr, obtaining the first data fragment to be read [c, d, e]. And because position 2' to position 2 needs to be read across the array, that is, it is necessary to continue reading in arr, the physical position corresponding to position 2 is found in i nd i ces, and data is extracted starting from the first data storage bit of arr (i.e., i nd ices position 0) until the physical position corresponding to i nd ices position 2 of arr is obtained. The second data fragment to be read [f, g, h] is finally merged to generate the second data read result [c, d, e, f, g, h].
[0106] This step ensures that the required data fragments can be accurately located and extracted regardless of data distribution. This not only improves data processing flexibility but also ensures data consistency and integrity, avoiding read errors or omissions caused by dispersed data storage. In application scenarios that require frequent cross-array data access, this solution can significantly improve data processing efficiency and user experience.
[0107] Furthermore, after receiving the data storage instruction and determining the amount of data to be stored and the storage margin of the loop array, the method further includes:
[0108] When the amount of the data to be stored is less than or equal to the storage margin of the circular array, determining the data start position of the data to be stored in the circular array based on the index array to obtain a second data start position;
[0109] The data pointer is pointed to the circular array, and the data to be stored is sequentially filled into the circular array starting from the second data starting position until the storage of the data to be stored is completed.
[0110] In this embodiment, data overflow or space waste is avoided by first accurately calculating the relationship between the amount of data to be stored and the remaining space in the circular array. When the amount of data fits within or is less than the remaining space, the index array is directly used to locate the starting point for data insertion, i.e., the second data start position, ensuring orderly and continuous data storage within the circular array. Subsequently, data is sequentially filled in from the specified position by directly manipulating the data pointer until all the data to be stored is securely and efficiently stored in the circular array, effectively improving data processing efficiency and accuracy.
[0111] In this embodiment, the data storage method is executed on the electronic device (eg Figure 1 The server shown in the figure) can receive instructions or obtain data through a wired connection or a wireless connection. It should be noted that the above-mentioned wireless connection method may include but is not limited to 3G / 4G connection, WiFi connection, Bluetooth connection, WiMAX connection, Zigbee connection, UWB (ultra wideband) connection, and other wireless connection methods currently known or to be developed in the future.
[0112] It should be emphasized that in order to further ensure the privacy and security of the above-mentioned data to be stored, the above-mentioned data to be stored can also be stored in a node of a blockchain.
[0113] The blockchain referred to in this application is a new application model for computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and encryption algorithms. Blockchain is essentially a decentralized database, a series of data blocks generated using cryptographic methods. Each data block contains information about a batch of network transactions, which is used to verify the validity of this information (to prevent counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, the platform product service layer, and the application service layer.
[0114] Those skilled in the art will appreciate that all or part of the processes in the above-described method embodiments can be implemented by instructing related hardware via computer-readable instructions. The computer-readable instructions can be stored in a computer-readable storage medium. When executed, the computer-readable instructions can include the processes in the above-described method embodiments. The aforementioned storage medium can be a non-volatile storage medium such as a magnetic disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).
[0115] It should be understood that although the steps in the flowcharts of the accompanying drawings are shown in sequence as indicated by the arrows, these steps are not necessarily executed in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least some of the steps in the flowcharts of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
[0116] Further references Figure 3 , as a response to the above Figure 2 In order to realize the method shown in the figure, the present application provides an embodiment of a data storage device. Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.
[0117] like Figure 3 As shown, the data storage device 300 of this embodiment executes the data storage method in the above embodiment. The data storage method is applied to a circular array in a database storage structure. The data storage device 300 includes:
[0118] A storage instruction receiving module 301 is configured to receive a data storage instruction and determine the amount of data to be stored and the storage margin of the loop array;
[0119] A first array copy module 302 is configured to copy the circular array to generate a temporary circular array when the amount of data to be stored is greater than the storage margin of the circular array;
[0120] The first data storage module 303 is used to store the data to be stored in the temporary circular array until the temporary circular array is filled, and store the unfinished data to be stored in the circular array;
[0121] The storage update instruction module 304 is configured to receive a storage update instruction, point the data pointer to the temporary loop array, and delete the loop array.
[0122] Furthermore, the data storage device 300 further includes:
[0123] An index array copy module is used to copy the index array of the loop array to obtain a temporary index array, wherein the temporary index array matches the temporary loop array;
[0124] The loop array clearing module is used to clear the stored data in the loop array and update the index array.
[0125] Furthermore, the first data storage module 303 specifically includes:
[0126] A first data position determining unit is configured to determine a data starting position of the data to be stored in the temporary circular array based on the temporary index array to obtain a first data starting position;
[0127] A first data storage unit is used to point the data pointer of the database to the temporary circular array, and fill the temporary circular array with the data to be stored starting from the starting position of the first data until the temporary circular array is filled;
[0128] The second data storage unit is used to determine the remaining amount of data to be stored, point the data pointer to the circular array, and fill the remaining amount of data to be stored into the circular array in sequence starting from the initial storage position of the circular array until the storage of the data to be stored is completed.
[0129] Furthermore, the data storage device 300 further includes:
[0130] A storage capacity determination module, configured to determine whether the remaining amount of data to be stored is greater than the data storage capacity of the circular array;
[0131] The second array copy module is used to copy the cleared circular array to generate a new circular array when the remaining amount of data to be stored is greater than the data storage capacity of the circular array.
[0132] Furthermore, the data storage device 300 further includes:
[0133] A reading position determination module is used to receive a data reading instruction and determine the storage position of the data to be read in the database, wherein the data reading instruction carries a data reading position identifier;
[0134] a first data reading module, configured to, when the data to be read is stored in the circular array or the temporary circular array, intercept and copy the data to be read in the circular array or the temporary circular array based on the data reading position identifier, generate a first data reading result, and output the first data reading result;
[0135] The second data reading module is used to determine the position of the data reading position identifier in the temporary circular array when the data to be read is stored in the circular array and the temporary circular array at the same time, and obtain the first data segment to be read from the temporary circular array; determine the position of the data reading position identifier in the circular array, and obtain the second data segment to be read from the circular array; generate a second data reading result based on the first data segment to be read and the second data segment to be read, and output the second data reading result.
[0136] Furthermore, the data reading position identifier includes a data reading start bit and a data reading end bit, and the second data reading module specifically includes:
[0137] a unit for determining a first to-be-read data segment based on the temporary index array and the read data start bit, and determining a second to-be-read data segment based on the index array and the read data end bit, when the read data start bit is located in the temporary circular array and the read data end bit is located in the circular array;
[0138] a unit for determining a first to-be-read data segment based on the index array and the read data start bit, and determining a second to-be-read data segment based on the temporary index array and the read data end bit, when the read data start bit is located in the circular array and the read data end bit is located in the temporary circular array;
[0139] The data reading combination unit is configured to combine the first to-be-read data segment and the second to-be-read data segment to generate a second data reading result, and output the second data reading result.
[0140] Furthermore, the data storage device 300 further includes:
[0141] a second data position determining unit, configured to determine, based on the index array, a data starting position of the data to be stored in the circular array to obtain a second data starting position when the amount of the data to be stored is less than or equal to the storage margin of the circular array;
[0142] The second data storage module is used to point the data pointer to the circular array, and fill the data to be stored in the circular array in sequence starting from the starting position of the second data until the storage of the data to be stored is completed.
[0143] In the above embodiment, the present application discloses a data storage device, which belongs to the field of big data technology. The data storage method is applied to the circular array in the database storage structure. Compared with the traditional storage solution, when the amount of data to be stored exceeds the capacity of the current circular array, the method simply rejects the new data or overwrites the old data. The present application adopts the strategy of copying the original circular array to a temporary array, thereby retaining the integrity of the original array data and ensuring the consistency and security of the data. It can also efficiently handle the continuous storage requirements of large amounts of data and avoid data loss or processing interruption due to capacity limitations. After completing part of the data storage in the temporary circular array, the remaining data is then added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating the data pointer and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0144] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of the computer device in this embodiment.
[0145] The computer device 4 includes a memory 41, a processor 42, and a network interface 43 that are interconnected via a system bus. It should be noted that the figure only shows a computer device 4 having components 41-43, but it should be understood that it is not required to implement all of the components shown, and more or fewer components may be implemented instead. Among them, those skilled in the art will understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to a microprocessor, an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), a digital signal processor (DSP), an embedded device, etc.
[0146] The computer device may be a desktop computer, notebook computer, PDA, cloud server, etc. The computer device may interact with the user via a keyboard, mouse, remote control, touchpad, or voice control device.
[0147] The memory 41 includes at least one type of readable storage medium, including flash memory, hard disk, multimedia card, card-type memory (e.g., SD or DX memory), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic storage, magnetic disk, optical disk, etc. In some embodiments, the memory 41 can be an internal storage unit of the computer device 4, such as the hard disk or memory of the computer device 4. In other embodiments, the memory 41 can also be an external storage device of the computer device 4, such as a plug-in hard disk equipped on the computer device 4, a smart memory card (SMC), a secure digital (SD) card, a flash memory card, etc. Of course, the memory 41 can also include both the internal storage unit of the computer device 4 and its external storage device. In this embodiment, the memory 41 is generally used to store the operating system and various application software installed on the computer device 4, such as computer-readable instructions for data storage methods. In addition, the memory 41 can also be used to temporarily store various types of data that have been output or are to be output.
[0148] In some embodiments, the processor 42 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 42 is generally used to control the overall operation of the computer device 4. In this embodiment, the processor 42 is used to execute computer-readable instructions stored in the memory 41 or process data, such as computer-readable instructions for executing the data storage method.
[0149] The network interface 43 may include a wireless network interface or a wired network interface. The network interface 43 is generally used to establish a communication connection between the computer device 4 and other electronic devices.
[0150] In the above embodiment, the present application discloses a computer device, which belongs to the field of big data technology. The data storage method is applied to the circular array in the database storage structure. Compared with the traditional storage solution, when the amount of data to be stored exceeds the capacity of the current circular array, the method simply rejects the new data or overwrites the old data. The present application adopts the strategy of copying the original circular array to a temporary array, thereby retaining the integrity of the original array data and ensuring the consistency and security of the data. It can also efficiently handle the continuous storage requirements of large amounts of data and avoid data loss or processing interruption due to capacity limitations. After completing part of the data storage in the temporary circular array, the remaining data is then added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating the data pointer and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0151] The present application also provides another embodiment, namely, providing a computer-readable storage medium, wherein the computer-readable storage medium stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the data storage method as described above.
[0152] In the above embodiment, the present application discloses a computer-readable storage medium, which belongs to the field of big data technology. The data storage method is applied to the circular array in the database storage structure. Compared with the traditional storage solution, when the amount of data to be stored exceeds the capacity of the current circular array, the method simply rejects the new data or overwrites the old data. The present application adopts the strategy of copying the original circular array to a temporary array, thereby retaining the integrity of the original array data and ensuring the consistency and security of the data. It can also efficiently handle the continuous storage requirements of large amounts of data and avoid data loss or processing interruption due to capacity limitations. After completing part of the data storage in the temporary circular array, the remaining data is then added to the original circular array in an orderly manner, realizing seamless data migration and expansion. In addition, by updating the data pointer and deleting the old circular array, a smooth transition of the storage structure is achieved, reducing the waste of system resources and simplifying the logic of subsequent data access.
[0153] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus the necessary general hardware platform, and of course can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for enabling a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.
[0154] The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set-top boxes, programmable consumer electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc. The present application can be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. The present application can also be practiced in distributed computing environments, in which tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules can be located in local and remote computer storage media, including storage devices.
[0155] Obviously, the embodiments described above are only some of the embodiments of the present application, rather than all of the embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application has been described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions described in the aforementioned specific embodiments, or to make equivalent replacements for some of the technical features therein. Any equivalent structure made using the contents of the present application specification and the accompanying drawings, directly or indirectly used in other related technical fields, is also within the scope of patent protection of the present application.
Claims
1. A data storage method, characterized in that: The data storage method is applied to a circular array in a database storage structure, and includes: Receive a data storage instruction, determine the amount of data to be stored and the storage margin of the loop array; When the amount of the data to be stored is greater than the storage margin of the circular array, the circular array is copied to generate a temporary circular array; Storing the data to be stored in the temporary circular array until the temporary circular array is filled, and storing the data to be stored that have not been completely stored in the circular array; A storage update instruction is received, a data pointer is pointed to the temporary loop array, and the loop array is deleted.
2. The data storage method according to claim 1, characterized in that: The circular array is configured with a matching index array. When the amount of the data to be stored is greater than the storage margin of the circular array, the circular array is copied to generate a temporary circular array, and the method further includes: Copying the index array of the loop array to obtain a temporary index array, wherein the temporary index array matches the temporary loop array; Clear the data stored in the loop array and update the index array.
3. The data storage method according to claim 2, characterized in that: Storing the data to be stored in the temporary circular array until the temporary circular array is filled, and storing the data to be stored that have not been completely stored in the circular array, specifically includes: Determine the data starting position of the data to be stored in the temporary loop array based on the temporary index array, and obtain a first data starting position; Pointing the data pointer of the database to the temporary circular array, and sequentially filling the data to be stored in the temporary circular array from the starting position of the first data until the temporary circular array is filled; The remaining amount of the data to be stored is determined, the data pointer is pointed to the circular array, and the remaining amount of the data to be stored is sequentially filled into the circular array starting from the initial storage position of the circular array until the storage of the data to be stored is completed.
4. The data storage method according to claim 3, characterized in that: After pointing the data pointer of the database to the temporary circular array and sequentially filling the data to be stored in the temporary circular array from the starting position of the first data until the temporary circular array is filled, the method further includes: Determine whether the remaining amount of the data to be stored is greater than the data storage capacity of the circular array; When the remaining amount of the data to be stored is greater than the data storage capacity of the circular array, the emptied circular array is copied to generate a new circular array.
5. The data storage method according to claim 2, characterized in that: Before receiving the storage update instruction, pointing the data pointer to the temporary loop array, and deleting the loop array, the method further includes: receiving a data reading instruction and determining a storage location of the data to be read in the database, wherein the data reading instruction carries a data reading location identifier; When the data to be read is stored in the loop array or the temporary loop array, intercepting and copying the data to be read in the loop array or the temporary loop array based on the data reading position identifier, generating a first data reading result, and outputting the first data reading result; When the data to be read is stored in the circular array and the temporary circular array at the same time, the position of the data reading position identifier in the temporary circular array is determined, and a first data segment to be read is obtained from the temporary circular array, the position of the data reading position identifier in the circular array is determined, and a second data segment to be read is obtained from the circular array, a second data reading result is generated based on the first data segment to be read and the second data segment to be read, and the second data reading result is output.
6. The data storage method according to claim 5, characterized in that: The data reading position identifier includes a reading data start bit and a reading data end bit, determining a position of the data reading position identifier in the temporary circular array, and obtaining a first to-be-read data segment from the temporary circular array, determining a position of the data reading position identifier in the circular array, and obtaining a second to-be-read data segment from the circular array, generating a second data reading result based on the first to-be-read data segment and the second to-be-read data segment, and outputting the second data reading result, specifically includes: When the read data start bit is located in the temporary circular array and the read data end bit is located in the circular array, determining the first to-be-read data segment based on the temporary index array and the read data start bit, and determining the second to-be-read data segment based on the index array and the read data end bit; When the read data start bit is located in the loop array and the read data end bit is located in the temporary loop array, determining the first to-be-read data segment based on the index array and the read data start bit, and determining the second to-be-read data segment based on the temporary index array and the read data end bit; The first to-be-read data segment and the second to-be-read data segment are combined to generate the second data reading result, and the second data reading result is output.
7. The data storage method according to claim 2, characterized in that: After receiving the data storage instruction and determining the amount of data to be stored and the storage margin of the loop array, the method further includes: When the amount of the data to be stored is less than or equal to the storage margin of the circular array, determining the data start position of the data to be stored in the circular array based on the index array to obtain a second data start position; The data pointer is pointed to the circular array, and the data to be stored are sequentially filled into the circular array starting from the starting position of the second data until the storage of the data to be stored is completed.
8. A data storage device, characterized in that: The data storage device executes the data storage method according to any one of claims 1 to 7, wherein the data storage method is applied to a circular array in a database storage structure, and the data storage device comprises: A storage instruction receiving module, used for receiving a data storage instruction, determining the amount of data to be stored and the storage margin of the loop array; A first array copying module, configured to copy the circular array to generate a temporary circular array when the amount of the data to be stored is greater than the storage margin of the circular array; A data storage module, used for storing the data to be stored in the temporary circular array until the temporary circular array is filled, and storing the data to be stored that have not been completely stored in the circular array; The storage update instruction module is used to receive the storage update instruction, point the data pointer to the temporary loop array, and delete the loop array.
9. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores computer-readable instructions, and the processor implements the steps of the data storage method according to any one of claims 1 to 7 when executing the computer-readable instructions.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the data storage method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Annular queue storage method and device, computing equipment and storage medium
CN111708495A
Data circulation storage method and device, server and storage medium
CN117632953A
