Time series data processing method, system and equipment and storage medium

By generating a unique timestamp sequence and using it as the only time primary key of the timing database, the inefficiency of the timing database and large cache occupancy of the timing database when writing data is solved, and efficient insertion of the timing database is achieved.

CN120144628APending Publication Date: 2025-06-13SF TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311719816.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-12-13
Publication Date
2025-06-13

AI Technical Summary

Technical Problem

When writing data, the timing database needs to maintain the number of repetitions and duplicate tag values ​​of each duplicate timestamp, resulting in large cache usage, difficulty in processing late data and low writing efficiency.

Method used

Generate the timestamp sequence corresponding to the access request through the current timestamp, access sequence number and timestamp generation rules, ensure the uniqueness of the timestamp sequence and use it as the unique time primary key of the timing database, supporting efficient insertion of the timing database.

Benefits of technology

It realizes efficient insertion of timing databases without losing data or adding additional data, reducing cache usage and improving writing efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120144628A_ABST
    Figure CN120144628A_ABST
Patent Text Reader

Abstract

The invention discloses a time sequence data processing method, system and device and a storage medium, and the method comprises the steps: responding to a received access request, and selecting a matched target timestamp sequence generation mode from at least two timestamp sequence generation modes pre-deployed in a time sequence database; generating a timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode, wherein the timestamp sequence comprises a current timestamp and a dynamic parameter; and storing the timestamp sequence as a primary key into the time sequence database for query. The timestamp sequence corresponding to the access request is generated through the current timestamp, the access sequence number and the timestamp generation rule, the uniqueness of the timestamp sequence is ensured, the timestamp sequence serves as a unique time main key of the time sequence database, and efficient insertion into the time sequence database in the form of not losing data and not adding additional data in various scenes is supported.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computers, and particularly to a method, system, device and storage medium for processing time series data. Background Art

[0002] With the development of the times, time series databases are increasingly widely used in the fields of Internet of Things, finance, industrial monitoring, log analysis, etc. A time series database is a database designed to process time series data, aiming to achieve efficient collection, storage, calculation and application of time series data. The basic design goal of a time series database is to achieve efficient insertion, storage and query.

[0003] A time series database often ensures the uniqueness of data within a time stamp period through the combination of a time stamp and a repeating tag. For example, within the same millisecond, 10 pieces of data are sent from an upstream machine, and a repeating tag value from 1 to 10 and a time stamp combination are required to confirm the uniqueness of each piece of data. However, since it is necessary to maintain the repetition count of each repeating time stamp and the above-mentioned repeating tag value when writing data, not only a large amount of cache is occupied, it is difficult to handle late data, but also the writing efficiency is low. Summary of the Invention

[0004] The main object of the present invention is to provide a method, system, device and storage medium for processing time series data, which generates a time stamp sequence corresponding to an access request through a current time stamp, an access sequence number and a time stamp generation rule, ensures the uniqueness of the time stamp sequence, and serves as the only time primary key of the time series database, supporting efficient insertion into the time series database in various scenarios in a form of not losing data and not adding extra data.

[0005] To achieve the above object, the embodiments of the present application provide the following technical solutions:

[0006] According to a first aspect of the embodiments of the present application, there is provided a method for processing time series data, the method comprising:

[0007] In response to the received access request, select a target time stamp sequence generation mode that matches from at least two pre-deployed time stamp sequence generation modes in the time series database;

[0008] Generate a time stamp sequence corresponding to the access request according to the target time stamp sequence generation mode, the time stamp sequence including a current time stamp and a dynamic parameter, the current time stamp referring to the time stamp corresponding to the access request, and the dynamic parameter being obtained according to the current time stamp and the target time stamp sequence generation mode;

[0009] Store the time stamp sequence as a primary key in the time series database for query.

[0010] Optionally, before generating the timestamp sequence corresponding to the access request according to the pattern generated from the target timestamp sequence, the following steps are further included:

[0011] Select a target thread for executing the access request from a preset multiple threads;

[0012] Determine a target timestamp generation rule corresponding to the target thread from the time series database;

[0013] Determine an access sequence number and a preset index of the target timestamp generation rule according to the target timestamp generation rule, and the access sequence number and the preset index of the target timestamp generation rule constitute the dynamic parameters.

[0014] Optionally, the target timestamp sequence generation mode is a lock-free mode or a locked mode. The step of determining a target timestamp generation rule corresponding to the target thread from the time series database includes:

[0015] In the case of the lock-free mode, obtain, according to a pre-configured first correspondence, a timestamp generation rule corresponding to the target thread from the time series database as the target timestamp generation rule; the first correspondence includes the correspondences between the multiple threads and the timestamp generation rules respectively;

[0016] In the case of the locked mode, allocate a corresponding first segment lock for the access request from a pre-configured set number of segment locks according to a set rule; the first segment lock is used to identify the permission for the target thread to execute the access request; determine a timestamp generation rule corresponding to the first segment lock as the target timestamp generation rule according to a pre-configured second correspondence; the second correspondence includes the correspondences between the multiple segment locks and the timestamp generation rules respectively.

[0017] Optionally, the step of allocating a corresponding first segment lock for the access request from a pre-configured set number of segment locks according to a set rule includes:

[0018] Query whether there is an unoccupied segment lock among the set number of segment locks according to the access request. If so, randomly select one segment lock from the unoccupied segment locks as the first segment lock; or,

[0019] Obtain any random number within the set number range, and use the segment lock corresponding to the random number as the first segment lock, and each segment lock within the set number range corresponds to an identifier.

[0020] Optionally, the step of determining an access sequence number and a preset index of the target timestamp generation rule according to the target timestamp generation rule includes:

[0021] When in the lock-free mode, obtain the reference serial number saved in the target timestamp generation rule, and determine the next serial number in the sequential arrangement of the reference serial number as the access serial number;

[0022] When in the locked mode, obtain the reference timestamp and the reference serial number saved in the target timestamp generation rule; determine the access serial number according to the current timestamp, the reference timestamp, and the reference serial number.

[0023] Optionally, the determining the access serial number according to the current timestamp, the reference timestamp, and the reference serial number includes:

[0024] If the current timestamp is less than the reference timestamp, randomly generate a serial number within the serial number range corresponding to the target timestamp generation rule as the access serial number; the serial number range corresponding to the target timestamp generation rule is determined according to the magnitude corresponding to the target timestamp generation rule;

[0025] If the current timestamp is greater than the reference timestamp, determine the access serial number as 0;

[0026] If the current timestamp is equal to the reference timestamp, determine the next serial number in the sequential arrangement of the reference serial number as the access serial number.

[0027] Optionally, the method further includes:

[0028] If the access request is the first request, both the reference timestamp and the reference serial number are 0;

[0029] If the access request is not the first request, the reference timestamp is the previous timestamp, and the reference serial number is the previous serial number.

[0030] Optionally, the generating the timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode includes:

[0031] Concatenate the current timestamp, the access serial number, the preset index and parameters of the target timestamp generation rule to obtain the timestamp sequence corresponding to the access request; the parameters are determined according to the magnitude corresponding to the target timestamp sequence generation mode.

[0032] According to the second aspect of the embodiments of the present application, a timing data processing system is provided, and the system includes:

[0033] A mode determination module, configured to select a matching target timestamp sequence generation mode from at least two pre-deployed timestamp sequence generation modes in a time series database in response to a received access request;

[0034] A timestamp sequence generation module, configured to generate a timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode, where the timestamp sequence includes a current timestamp and a dynamic parameter, the current timestamp refers to the timestamp corresponding to the access request, and the dynamic parameter is obtained according to the current timestamp and the target timestamp sequence generation mode;

[0035] A processing module, configured to store the timestamp sequence as a primary key in the time series database for query.

[0036] According to a third aspect of the embodiments of the present application, an electronic device is provided, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, where when the processor runs the computer program, it is configured to implement the method described in the first aspect above.

[0037] According to a fourth aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which computer-readable instructions are stored, and the computer-readable instructions can be executed by a processor to implement the method described in the first aspect above.

[0038] In summary, the embodiments of the present application provide a method, a system, a device, and a storage medium for processing time series data. By responding to a received access request, a matching target timestamp sequence generation mode is selected from at least two pre-deployed timestamp sequence generation modes in a time series database; a timestamp sequence corresponding to the access request is generated according to the target timestamp sequence generation mode, where the timestamp sequence includes a current timestamp and a dynamic parameter, the current timestamp refers to the timestamp corresponding to the access request, and the dynamic parameter is obtained according to the current timestamp and the target timestamp sequence generation mode; the timestamp sequence is stored as a primary key in the time series database for query. A timestamp sequence corresponding to the access request is generated through the current timestamp, the access serial number, and the timestamp generation rule, ensuring the uniqueness of the timestamp sequence, which is used as the unique time primary key of the time series database, and supports efficient insertion into the time series database in various scenarios without losing data or adding extra data. BRIEF DESCRIPTION OF THE DRAWINGS

[0039] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for the description of the embodiments or the prior art. Obviously, the drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on the structures shown in these drawings.

[0040] The structures, ratios, sizes, etc. illustrated in this specification are only used to cooperate with the content disclosed in the specification for those familiar with this technology to understand and read, and are not used to limit the limited conditions for the implementation of the present invention. Therefore, they do not have substantial technical significance. Any modification of the structure, change of the proportional relationship, or adjustment of the size, without affecting the effects that the present invention can produce and the purposes that can be achieved, should still fall within the scope covered by the technical content disclosed in the present invention.

[0041] Figure 1 It is a schematic flowchart of a method for processing time series data provided by an embodiment of this application;

[0042] Figure 2 It is a schematic diagram of the use of a segmented lock provided by an embodiment of this application;

[0043] Figure 3 It is a flowchart for generating a time stamp sequence of a segmented lock provided by an embodiment of this application;

[0044] Figure 4 It is a block diagram of a time series data processing system provided by an embodiment of this application;

[0045] Figure 5 It shows a schematic structural diagram of an electronic device provided by an embodiment of this application;

[0046] Figure 6 It shows a schematic diagram of a computer-readable storage medium provided by an embodiment of this application.

[0047] The realization of the objectives of the present invention, functional features, and advantages will be further described with reference to the embodiments and the accompanying drawings. Detailed Embodiments

[0048] The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, rather than all, of the embodiments of the present invention. All other embodiments obtained by those of ordinary skill in the art based on the embodiments of the present invention without creative efforts belong to the scope of protection of the present invention.

[0049] It should be noted that all directional indications (such as up, down, left, right, front, back...) in the embodiments of the present invention are only used to explain the relative positional relationship, movement conditions, etc. between components in a specific posture (as shown in the attached drawings). If the specific posture changes, the directional indications will also change accordingly.

[0050] In addition, in the present invention, descriptions such as "first" and "second" are only for descriptive purposes and should not be construed as indicating or implying their relative importance or implicitly specifying the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In the description of the present invention, the meaning of "a plurality" is at least two, such as two, three, etc., unless otherwise specifically defined.

[0051] In the present invention, unless otherwise clearly specified and limited, terms such as "connection" and "fixation" should be understood in a broad sense. For example, "fixation" can be a fixed connection, a detachable connection, or integrated; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the communication inside two components or the interaction relationship between two components, unless otherwise clearly limited. For those of ordinary skill in the art, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0052] In addition, the technical solutions between various embodiments of the present invention can be combined with each other, but it must be based on the fact that those of ordinary skill in the art can implement it. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the protection scope required by the present invention.

[0053] Figure 1 The figure shows a method for processing time-series data provided by an embodiment of the present application. The method includes:

[0054] Step 101: In response to the received access request, select a matching target timestamp sequence generation mode from at least two pre-deployed timestamp sequence generation modes in the time-series database;

[0055] Step 102: Generate a timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode. The timestamp sequence includes a current timestamp and dynamic parameters. The current timestamp refers to the timestamp corresponding to the access request, and the dynamic parameters are obtained according to the current timestamp and the target timestamp sequence generation mode;

[0056] Step 103: Store the timestamp sequence as a primary key in the time-series database for query.

[0057] In a possible implementation, before generating the timestamp sequence corresponding to the access request according to the target timestamp sequence generation pattern, the following steps are further included:

[0058] Select a target thread for executing the access request from a preset plurality of threads; determine a target timestamp generation rule corresponding to the target thread from the time series database; determine an access sequence number and a preset index of the target timestamp generation rule according to the target timestamp generation rule, and the access sequence number and the preset index of the target timestamp generation rule constitute the dynamic parameter.

[0059] In a possible implementation, the dynamic parameter includes an access sequence number and a preset index of the target timestamp generation rule. In the method provided in the embodiments of the present application, the dynamic parameter will generate access sequence numbers with different generation methods and different target timestamp generation rules according to different target timestamp sequence generation patterns. Thus, the uniqueness of the time series is ensured.

[0060] In a possible implementation, the generation process of the target timestamp generation rule includes:

[0061] Select a target thread for executing the access request from a preset plurality of threads; determine a target timestamp generation rule corresponding to the target thread from the time series database.

[0062] In the method provided in the embodiments of the present application, the target timestamp generation rule can be understood as a target timestamp generator, which is used to generate the current timestamp of the access request and the access sequence number. In different target timestamp sequence generation patterns (segmented lock and lock-free mode), there are target timestamp generation rules for the segmented lock mode and target timestamp generation rules for the lock-free mode.

[0063] In a possible implementation, generating the timestamp sequence corresponding to the access request according to the target timestamp sequence generation pattern includes:

[0064] Generate the timestamp sequence corresponding to the access request according to the current timestamp, the access sequence number, and the preset index of the target timestamp generation rule.

[0065] In a possible implementation, the timestamp sequence corresponding to the access request is obtained by splicing the current timestamp, the access sequence number, the preset index of the target timestamp generation rule, and a parameter; the parameter is determined according to the magnitude corresponding to the target timestamp sequence generation pattern. The uniqueness of the timestamp sequence is ensured.

[0066] In a possible implementation, the target timestamp sequence generation mode is a lock-free mode or a locked mode. Determining the target timestamp generation rule corresponding to the target thread from the time series database includes:

[0067] When in the lock-free mode, according to a pre-configured first correspondence, obtain the timestamp generation rule corresponding to the target thread from the time series database as the target timestamp generation rule; the first correspondence includes the correspondences between the multiple threads and the timestamp generation rules.

[0068] When in the locked mode, allocate a corresponding first segmented lock for the access request from a pre-configured set number of segmented locks according to a set rule; the first segmented lock is used to identify the permission of the target thread to execute the access request; determine the timestamp generation rule corresponding to the first segmented lock according to a pre-configured second correspondence as the target timestamp generation rule; the second correspondence includes the correspondences between the multiple segmented locks and the timestamp generation rules.

[0069] In a specific application, the target timestamp generation rule in the segmented lock mode has applicability. The target timestamp generation rule in the lock-free mode is allocated according to the maximum number of threads in the thread pool and cannot be used if not allocated. Selecting different rules according to different modes is more efficient.

[0070] Regarding how to determine which specific segmented lock to use in the segmented lock mode, it includes at least two methods listed in the embodiments of the present application. The embodiments of the present application do not limit this.

[0071] In a possible implementation, allocating a corresponding first segmented lock for the access request from a pre-configured set number of segmented locks according to a set rule includes:

[0072] Query whether there is an unoccupied segmented lock among the set number of segmented locks according to the access request. If so, randomly select one of the unoccupied segmented locks as the first segmented lock; or, obtain any random number within the set number range, and use the segmented lock corresponding to the random number as the first segmented lock. Each segmented lock within the set number range corresponds to an identifier.

[0073] By means of selecting an idle segmented lock or randomly selecting a segmented lock, quickly determine the target segmented lock, so that the segmented lock generates the current timestamp and the access sequence number based on the corresponding time generation rule.

[0074] The determination methods of the access sequence numbers for the lock-free mode and the locked mode are different. In a possible implementation manner, before generating the timestamp sequence corresponding to the access request according to the preset index of the current timestamp, the access sequence number, and the target timestamp generation rule, it further includes:

[0075] When it is in the lock-free mode, obtain the reference sequence number saved in the target timestamp generation rule, and determine the next sequence number in sequence of the reference sequence number as the access sequence number;

[0076] When it is in the locked mode, obtain the reference timestamp and the reference sequence number saved in the target timestamp generation rule; determine the access sequence number according to the current timestamp, the reference timestamp, and the reference sequence number.

[0077] Further, in the locked mode, determining the access sequence number according to the current timestamp, the reference timestamp, and the reference sequence number includes:

[0078] If the current timestamp is less than the reference timestamp, randomly generate a sequence number within the sequence number range corresponding to the target timestamp generation rule as the access sequence number; the sequence number range corresponding to the target timestamp generation rule is determined according to the magnitude corresponding to the target timestamp generation rule; if the current timestamp is greater than the reference timestamp, determine the access sequence number as 0; if the current timestamp is equal to the reference timestamp, determine the next sequence number in sequence of the reference sequence number as the access sequence number.

[0079] Determine the access sequence number in the locked mode through the above three comparison cases of the current timestamp and the reference timestamp.

[0080] In a possible implementation manner, the method further includes:

[0081] If the access request is the first request, both the reference timestamp and the reference sequence number are 0; if the access request is not the first request, the reference timestamp is the previous timestamp, and the reference sequence number is the previous sequence number.

[0082] Next, the timing data processing method provided by the embodiments of the present application will be introduced in detail with reference to the accompanying drawings.

[0083] In the first stage, determine the unique primary key based on different timing databases.

[0084] Different time series databases support different lengths of timestamps. The mainstream time series databases (such as InfluxDB and TDEngine, etc.) support timestamp accuracy up to the nanosecond level. Then, the same data source can support generating 100 million pieces of data per second, which is generally sufficient for the time series database to use. Duplicate tags can be not used to ensure the uniqueness of timestamps. Therefore, the method provided in the embodiments of this application takes the time series database that supports the nanosecond level as an example.

[0085] In the second stage, according to the data generation method of the production end corresponding to the access request, select a matching target timestamp sequence generation mode from at least two pre-deployed timestamp sequence generation modes in the time series database. The target timestamp sequence generation mode includes using a segmented lock scheme or a lock-free scheme.

[0086] In a distributed environment, data can be stored in segments, and a segmented lock is assigned to each segment of data. When a thread occupies the segmented lock to access the corresponding data, the data in other segments can also be accessed by other threads.

[0087] In a specific application, the target timestamp generation rule of the segmented lock mode has applicability. The target timestamp generation rule of the lock-free mode is allocated according to the maximum number of threads in the thread pool and cannot be used if not allocated. Selecting different rules according to different modes is more efficient.

[0088] In the third stage, splice the current timestamp, the access sequence number, the preset index and parameters of the target timestamp generation rule to obtain the timestamp sequence corresponding to the access request.

[0089] The timestamp sequence includes the current timestamp, the access sequence number, and the preset index of the target timestamp generation rule. The current timestamp refers to the timestamp corresponding to the access request. The parameter is determined according to the magnitude corresponding to the target timestamp sequence generation mode.

[0090] In the segmented lock scheme provided in the embodiments of this application, select a target thread that executes the access request from a preset multiple threads; determine a target timestamp generation rule (timestamp generator) corresponding to the target thread from the time series database. Obtain the current timestamp, as well as the reference timestamp and reference sequence number saved in the timestamp generation rule based on the timestamp generation rule; determine the access sequence number according to the current timestamp, the reference timestamp and the reference sequence number; generate the timestamp sequence corresponding to the access request according to the current timestamp, the access sequence number, the preset index and parameters of the timestamp generation rule.

[0091] Figure 2The figure shows a schematic diagram of a segmented lock provided by an embodiment of the present application. One millisecond is equal to one million nanoseconds. One millisecond is expressed as an array in nanoseconds. The array is divided into a set number of groups, and the set number of groups is set according to requirements. The larger the set number of groups, the smaller the granularity of the segmented lock. Each group corresponds to a timestamp generation rule. For example, if the set number of groups is 100, then a total of one million serial numbers are divided into one hundred groups, and each group is managed by a timestamp generation rule.

[0092] Regarding the selection of the segmented lock, query whether there is an unoccupied segmented lock among the set number of segmented locks according to the access request. If so, randomly select one of the unoccupied segmented locks as the first segmented lock; or, obtain any random number within the set number range, and use the segmented lock corresponding to the random number as the first segmented lock. Each segmented lock within the set number range corresponds to an identifier.

[0093] The first segmented lock is used to identify the permission of the target thread to execute the access request; determine the timestamp generation rule corresponding to the first segmented lock according to a pre-configured second correspondence relationship as the target timestamp generation rule; the second correspondence relationship includes the corresponding relationships between the multiple segmented locks and the timestamp generation rules respectively.

[0094] The first segmented lock is one of the set number of segmented locks. The set number of segmented locks, the set number of serial number arrays, and the set number of timestamp generation rules correspond to each other one by one. The serial number array corresponding to the first segmented lock is determined by grouping according to the timestamp magnitude.

[0095] When in the segmented lock mode, in order to determine the access serial number, first obtain the reference timestamp and the reference serial number saved in the target timestamp generation rule; determine the access serial number according to the current timestamp, the reference timestamp, and the reference serial number.

[0096] The specific method for determining the access serial number includes the following situations:

[0097] a. If the current timestamp is less than the reference timestamp, randomly generate a serial number within the serial number range corresponding to the target timestamp generation rule as the access serial number; the serial number range corresponding to the target timestamp generation rule is determined according to the magnitude corresponding to the target timestamp generation rule;

[0098] b. If the current timestamp is greater than the reference timestamp, determine the access serial number as 0;

[0099] c. If the current timestamp is equal to the reference timestamp, determine the next sequence number in the sequential arrangement of the reference sequence numbers as the access sequence number.

[0100] If the access request is the first request, both the reference timestamp and the reference sequence number are 0; if the access request is not the first request, the reference timestamp is the previous timestamp, and the reference sequence number is the previous sequence number.

[0101] Figure 3 The figure shows a schematic diagram of generating a segmented lock timestamp provided by an embodiment of the present application. First, obtain the reference timestamp and the reference sequence number, and enable the segmented lock. Further, obtain the current timestamp, and then compare it with the old timestamp (reference timestamp) previously saved in the generator. If the current timestamp is less than the old timestamp, it means that a clock rollback has occurred, and compensation logic needs to be performed, such as reserving a certain sequence number range to obtain a random number to get the newly allocated access sequence number; if the current timestamp is equal to the old timestamp, the reference sequence number will be incremented by one as the access sequence number; if the current timestamp is greater than the old timestamp, the access sequence number will be set to 0. Finally, set the current timestamp as the old timestamp, and then return the timestamp sequence corresponding to the access request obtained by splicing the current timestamp, the access sequence number, the number and parameters of the target timestamp generator.

[0102] Figure 2 It mentions the synchronized code block in [reference]. When two concurrent threads (thread1 and thread2) access the synchronized code block in the same object (syncThread), only one thread can be executed at the same moment, and the other thread is blocked and must wait for the current thread to execute this code block before it can execute the code block. Thread1 and thread2 are mutually exclusive because when executing the synchronized code block, the current object will be locked, and only after executing the code block can the object lock be released, and the next thread can execute and lock the object.

[0103] In the case of the lock-free mode, in order to determine the access sequence number, first obtain the reference sequence number saved in the target timestamp generation rule, and determine the next sequence number in the sequential arrangement of the reference sequence numbers as the access sequence number.

[0104] In order to determine the target timestamp generation rule (timestamp generator), according to the pre-configured first correspondence, obtain the timestamp generation rule corresponding to the target thread from the time series database as the target timestamp generation rule; the first correspondence includes the corresponding relationships between the multiple threads and the timestamp generation rules.

[0105] If the system at the production end produces data using thread pools respectively, a unique timestamp generator can be directly allocated based on the maximum number of threads in the thread pool. Each thread's thread-local variable is allocated a unique timestamp generator. Similar to the segmented lock scheme, each generator is responsible for generating serial numbers within a certain range of nanosecond timestamps.

[0106] Obtain the current timestamp corresponding to the access request and the reference serial number saved in the timestamp generation rule corresponding to the thread, and generate a timestamp sequence corresponding to the access request according to the current timestamp, the next serial number arranged in sequence with the reference serial number, and the preset index of the exclusive timestamp generation rule.

[0107] In the fourth stage, store the timestamp sequence as the primary key in the time-series database for query.

[0108] In summary, the embodiment of the present application provides a method for processing time-series data. By responding to the received access request, select a matching target timestamp sequence generation mode from at least two pre-deployed timestamp sequence generation modes in the time-series database; generate a timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode, the timestamp sequence includes a current timestamp and dynamic parameters, the current timestamp refers to the timestamp corresponding to the access request, and the dynamic parameters are obtained according to the current timestamp and the target timestamp sequence generation mode; store the timestamp sequence as the primary key in the time-series database for query. Generate a timestamp sequence corresponding to the access request through the current timestamp, access serial number, and timestamp generation rule, ensure the uniqueness of the timestamp sequence, and use it as the unique time primary key of the time-series database, supporting efficient insertion into the time-series database in various scenarios without losing data or adding extra data.

[0109] Based on the same technical concept, the embodiment of the present application also provides a time-series data processing system, as Figure 4 shown, the system includes:

[0110] A mode determination module 401, configured to select a matching target timestamp sequence generation mode from at least two pre-deployed timestamp sequence generation modes in the time-series database in response to the received access request;

[0111] A timestamp sequence generation module 402, configured to generate a timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode, the timestamp sequence includes a current timestamp and dynamic parameters, the current timestamp refers to the timestamp corresponding to the access request, and the dynamic parameters are obtained according to the current timestamp and the target timestamp sequence generation mode;

[0112] A processing module 403 is configured to store the timestamp sequence as a primary key in the time-series database for query.

[0113] An embodiment of the present application also provides an electronic device corresponding to the method provided in the foregoing embodiment. Please refer to Figure 5 , which shows a schematic diagram of an electronic device provided in some embodiments of the present application. The electronic device 20 may include: a processor 200, a memory 201, a bus 202, and a communication interface 203. The processor 200, the communication interface 203, and the memory 201 are connected through the bus 202. A computer program that can run on the processor 200 is stored in the memory 201. When the processor 200 runs the computer program, it executes the method provided in any of the foregoing embodiments of the present application.

[0114] Among them, the memory 201 may include a high-speed random access memory (RAM: Random Access Memory), and may also include a non-volatile memory, such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one physical port 203 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used.

[0115] The bus 202 may be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. Among them, the memory 201 is used to store a program. After receiving an execution instruction, the processor 200 executes the program. The method disclosed in any of the foregoing embodiments of the present application can be applied to the processor 200 or implemented by the processor 200.

[0116] The processor 200 may be an integrated circuit chip with the ability to process signals. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in the processor 200 or the instructions in the form of software. The above-mentioned processor 200 may be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it may 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 application. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present application can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software module may 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 201, and the processor 200 reads the information in the memory 201 and combines its hardware to complete the steps of the above method.

[0117] The electronic device provided in the embodiment of the present application and the method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the method adopted, run or implemented by it.

[0118] The embodiment of the present application also provides a computer-readable storage medium corresponding to the method provided in the foregoing embodiment. Please refer to Figure 6 , which shows that the computer-readable storage medium is an optical disc 30, on which a computer program (i.e., a program product) is stored. When the computer program is run by a processor, it will execute the method provided in any of the foregoing embodiments.

[0119] It should be noted that examples of the computer-readable storage medium may also include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other optical and magnetic storage media, which will not be elaborated here one by one.

[0120] The computer-readable storage medium provided in the above embodiment of the present application and the method provided in the embodiment of the present application are based on the same inventive concept and have the same beneficial effects as the method adopted, run or implemented by the application program stored in it.

[0121] It should be noted that:

[0122] The algorithms and displays provided herein are not inherently related to any particular computer, virtual apparatus, or other device. A variety of general-purpose apparatuses may also be used in conjunction with the teachings presented herein. The structure required to construct such apparatuses will be apparent from the above description. Additionally, the present application is not directed to any particular programming language. It should be understood that the content of the present application described herein can be implemented using a variety of programming languages, and the description of a particular language above is for the purpose of disclosing the best mode of the present application.

[0123] In the specification provided herein, a number of specific details are set forth. However, it is understood that embodiments of the present application may be practiced without these specific details. In some instances, well-known methods, structures, and techniques have not been shown in detail so as not to obscure the understanding of this specification.

[0124] Similarly, it should be understood that in order to streamline the present application and assist in understanding one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be construed as reflecting an intention that the claimed present application requires more features than are expressly recited in each claim. Rather, as reflected in the following claims, the inventive aspects lie in less than all the features of the single foregoing disclosed embodiment. Thus, the claims following the detailed description are hereby expressly incorporated into the detailed description, with each claim standing on its own as a separate embodiment of the present application.

[0125] Those skilled in the art will appreciate that the modules in the devices in the embodiments can be adaptively changed and disposed in one or more devices different from the embodiments. The modules or units or components in the embodiments can be combined into one module or unit or component, and in addition, they can be divided into multiple sub-modules or sub-units or sub-components. Except for the fact that at least some of such features and / or processes or units are mutually exclusive, any combination can be used to combine all the features disclosed in this specification (including the accompanying claims, abstract, and drawings) and all the processes or units of any method or device so disclosed. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstract, and drawings) can be replaced by an alternative feature that provides the same, equivalent, or similar purpose.

[0126] In addition, those skilled in the art can understand that although some embodiments described herein include certain features included in other embodiments rather than other features, the combination of features of different embodiments means that it is within the scope of this application and forms different embodiments. For example, in the following claims, any one of the claimed embodiments can be used in any combination.

[0127] Each component embodiment of this application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) can be used in practice to implement some or all of the functions of some or all of the components in the virtual machine creation device according to the embodiments of this application. This application can also be implemented as a device or device program (such as a computer program and a computer program product) for executing part or all of the methods described herein. Such a program implementing this application can be stored on a computer-readable medium, or can be in the form of one or more signals. Such signals can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0128] It should be noted that the above embodiments illustrate rather than limit this application, and those skilled in the art can design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in the claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. This application can be implemented by means of hardware including several different elements and by means of a suitably programmed computer. In the unit claims listing several devices, several of these devices can be embodied by the same item of hardware. The use of the words first, second, and third, etc. does not denote any order. These words can be interpreted as names.

[0129] As described above, the above are only the preferred specific embodiments of this application, but the protection scope of this application is not limited thereto. Any changes or substitutions that can be easily thought of by those skilled in the art within the technical scope disclosed in this application should be covered by the protection scope of this application. Therefore, the protection scope of this application shall be subject to the protection scope of the said claims.

[0130] The above are only the preferred embodiments of the present invention, and do not thereby limit the patent scope of the present invention. Any equivalent structural transformation made under the concept of the present invention by using the content of the specification and drawings of the present invention, or any direct / indirect application in other related technical fields, is included in the patent protection scope of the present invention.

Claims

1. A method for processing time-series data, characterized in that, the method includes: responding to a received access request, and selecting a matching target timestamp sequence generation pattern from at least two pre-deployed timestamp sequence generation patterns in a time-series database; generating a timestamp sequence corresponding to the access request according to the target timestamp sequence generation pattern, where the timestamp sequence includes a current timestamp and dynamic parameters, the current timestamp refers to the timestamp corresponding to the access request, and the dynamic parameters are obtained according to the current timestamp and the target timestamp sequence generation pattern; storing the timestamp sequence as a primary key in the time-series database for query.

2. The method according to claim 1, characterized in that, before generating the timestamp sequence corresponding to the access request according to the target timestamp sequence generation pattern, it further includes: selecting a target thread for executing the access request from a preset plurality of threads; determining a target timestamp generation rule corresponding to the target thread from the time-series database; determining an access sequence number and a preset index of the target timestamp generation rule according to the target timestamp generation rule, and the access sequence number and the preset index of the target timestamp generation rule constitute the dynamic parameters.

3. The method according to claim 2, characterized in that, the target timestamp sequence generation pattern is a lock-free pattern or a locked pattern, and determining the target timestamp generation rule corresponding to the target thread from the time-series database includes: in the case of the lock-free pattern, obtaining, according to a pre-configured first correspondence, a timestamp generation rule corresponding to the target thread from the time-series database as the target timestamp generation rule; the first correspondence includes the correspondences between the plurality of threads and the timestamp generation rules respectively; in the case of the locked pattern, allocating a corresponding first segment lock for the access request from a pre-configured set number of segment locks according to a set rule; the first segment lock is used to identify the permission for the target thread to execute the access request; determining the timestamp generation rule corresponding to the first segment lock according to a pre-configured second correspondence as the target timestamp generation rule; the second correspondence includes the correspondences between the plurality of segment locks and the timestamp generation rules respectively.

4. The method according to claim 3, characterized in that, allocating a corresponding first segment lock for the access request from a pre-configured set number of segment locks according to a set rule includes: querying whether there is an unoccupied segment lock among the set number of segment locks according to the access request, if so, randomly selecting one segment lock from the unoccupied segment locks as the first segment lock; or, obtaining any random number within the set number range, and using the segment lock corresponding to the random number as the first segment lock, and each segment lock within the set number range corresponds to an identifier.

5. The method according to claim 2, characterized in that, determining the access sequence number and the preset index of the target timestamp generation rule according to the target timestamp generation rule includes: When in the lock-free mode, obtain the reference serial number saved in the target timestamp generation rule, and determine the next serial number in the sequential arrangement of the reference serial numbers as the access serial number; When in the locked mode, obtain the reference timestamp and the reference serial number saved in the target timestamp generation rule; determine the access serial number according to the current timestamp, the reference timestamp, and the reference serial number.

6. The method according to claim 5, wherein, the determining the access serial number according to the current timestamp, the reference timestamp, and the reference serial number includes: if the current timestamp is less than the reference timestamp, randomly generate a serial number within the serial number range corresponding to the target timestamp generation rule as the access serial number; the serial number range corresponding to the target timestamp generation rule is determined according to the magnitude corresponding to the target timestamp generation rule; if the current timestamp is greater than the reference timestamp, determine the access serial number as 0; if the current timestamp is equal to the reference timestamp, determine the next serial number in the sequential arrangement of the reference serial numbers as the access serial number.

7. The method according to claim 5, wherein, the method further includes: if the access request is the first request, both the reference timestamp and the reference serial number are 0; if the access request is not the first request, the reference timestamp is the previous timestamp, and the reference serial number is the previous serial number.

8. The method according to claim 2, wherein, the generating the timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode includes: obtaining the timestamp sequence corresponding to the access request by splicing the current timestamp, the access serial number, the preset index of the target timestamp generation rule, and the parameter; the parameter is determined according to the magnitude corresponding to the target timestamp sequence generation mode.

9. A time-series data processing system, wherein, the system includes: a mode determination module, configured to select a matching target timestamp sequence generation mode from at least two timestamp sequence generation modes pre-deployed in a time-series database in response to an received access request; a timestamp sequence generation module, configured to generate a timestamp sequence corresponding to the access request according to the target timestamp sequence generation mode, the timestamp sequence including a current timestamp and a dynamic parameter, where the current timestamp refers to the timestamp corresponding to the access request, and the dynamic parameter is obtained according to the current timestamp and the target timestamp sequence generation mode; a processing module, configured to store the timestamp sequence as a primary key into the time-series database for query.

10. An electronic device, including: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein when the processor runs the computer program, the method according to any one of claims 1-8 is implemented.

11. A computer-readable storage medium, wherein, Computer-readable instructions are stored thereon, and the computer-readable instructions can be executed by a processor to implement the method according to any one of claims 1-8.