Disclosure of Invention
The present invention is directed to solving at least one of the problems of the prior art. Therefore, the invention provides a real-time data ID generation method of a distribution automation system, which can meet the requirement of the distribution automation system on the real-time data ID.
The invention further provides a real-time data ID generation system of the power distribution automation system.
The invention also provides a computer readable storage medium for implementing the method.
A real-time data ID generation method of a distribution automation system according to an embodiment of a first aspect of the present invention includes: setting a plurality of marks, wherein the related information of each mark comprises a mark number, expiration time and current ID (identity), and storing the related information in a real-time database; starting ID generation service, reading corresponding expiration time according to the mark sequence, and detecting the availability of the mark according to the expiration time; the first mark is any one of the marks, if the first mark is detected to be available, the current ID of the first mark is read, a target ID is obtained through calculation according to the current ID of the first mark, and the target ID is written back to the real-time database as the current ID of the first mark; the ID generation service updates the expiration time of the first marker in a timed manner.
According to some embodiments of the invention, the method of detecting the availability of the marker in dependence of the expiry time comprises: and reading the expiration time and obtaining the current time, wherein the mark is available if the expiration time is less than the current time.
According to some embodiments of the invention, the method for the ID generation service to update the expiration time of the first marker comprises: the ID generation service updates the expiration time of the first marker stored in the real-time database at intervals of a first time interval, and adds the expiration time of the first marker to a second time interval; wherein the first time interval is less than the second time interval.
According to some embodiments of the invention, the current ID is of long type, 8 bytes in length; one byte of the highest position of the current ID is used for storing record type information, and the second byte of the highest position is used for storing a corresponding mark number.
According to some embodiments of the invention, the calculating the target ID from the current ID of the first tag comprises: and adding 1 to the current ID of the first mark to obtain a target ID.
According to some embodiments of the invention, the current ID includes record type information, a mark number, and increment information.
According to some embodiments of the invention, the method further comprises: if the first mark is detected to be unavailable, reading the expiration time of a second mark and detecting the availability of the second mark; wherein the mark number of the second mark is equal to the mark number of the first mark plus 1.
A real-time data ID generation system of a distribution automation system according to an embodiment of a second aspect of the present invention, the system includes: the system comprises a mark creating module, a real-time database and a marking module, wherein the mark creating module is used for setting a plurality of marks, the related information of each mark comprises a mark number, expiration time and a current ID, and the related information is stored in the real-time database; the availability detection module is used for reading the corresponding expiration time according to the sequence of the mark number and detecting the availability of the mark according to the expiration time; the target ID generating module is used for reading the current ID of the first mark, calculating the current ID of the first mark to obtain a target ID, and writing the target ID serving as the current ID of the first mark back to the real-time database; wherein the first marker is any one of the plurality of markers and the first marker is available; and the timing updating module is used for updating the expiration time of the first mark at a timing.
According to some embodiments of the invention, the system further comprises: and the current ID setting module is used for setting the current ID to be in a long type and 8 bytes in length, configuring one byte of the highest position of the current ID to store record type information, and storing a corresponding mark number in the second byte of the highest position.
A computer-readable storage medium according to an embodiment of the third aspect of the invention, having stored thereon a computer program which, when executed by a processor, performs the method of any of the embodiments of the first aspect of the invention.
The embodiment of the invention at least has the following beneficial effects: the real-time data ID generated by the method of the embodiment of the invention can support parallel service modes such as distributed service, micro service and the like; the method has the advantages that the method can be used without a timestamp, the time backspace problem and network card MAC address information, the requirement of information safety is met, and the number of IDs supported per millisecond is unlimited.
Additional aspects and advantages of the invention will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the invention.
Detailed Description
Reference will now be made in detail to embodiments of the present invention, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the accompanying drawings are illustrative only for the purpose of explaining the present invention, and are not to be construed as limiting the present invention.
In the description of the present invention, the meaning of a plurality of means is one or more, the meaning of a plurality of means is two or more, and more than, less than, more than, etc. are understood as excluding the present number, and more than, less than, etc. are understood as including the present number. If the first and second are described for the purpose of distinguishing technical features, they are not to be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated or implicitly indicating the precedence of the technical features indicated.
Referring to fig. 1, a real-time data ID generation method according to an embodiment of the present invention includes the following steps:
s1, setting a plurality of marks, wherein the related information of each mark comprises a mark number, expiration time and a current ID, and storing the related information in a real-time database;
s2, starting ID generation service, reading corresponding expiration time according to the sequence of the mark number, and detecting the availability of the mark according to the expiration time;
s3, if the first mark is detected to be available, reading the current ID of the first mark, calculating to obtain a target ID according to the current ID of the first mark, and writing the target ID serving as the current ID of the first mark back to the real-time database;
s4, the ID generation service updates the expiration time of the first flag at regular time.
In some embodiments, a method of detecting availability of a marker based on an expiration time includes: reading the expiration time and obtaining the current time, and if the expiration time is less than the current time, marking as available.
In some embodiments, the method for the ID generation service to periodically update the expiration time of the first marker comprises: the ID generation service updates the expiration time of the first mark stored in the real-time database at intervals of a first time interval, and adds the expiration time of the first mark to a second time interval; wherein the first time interval is less than the second time interval.
In some embodiments, the current ID is of long type, 8 bytes in length; the most significant byte of the current ID stores the record type information, and the second most significant byte stores the corresponding tag number.
In some embodiments, the method of calculating the target ID from the current ID of the first tag comprises: and adding 1 to the current ID of the first mark to obtain the target ID.
In some embodiments, the current ID includes record type information, a tag number, and increment information.
In some embodiments, the ID generation method further comprises: if the first mark is detected to be unavailable, reading the expiration time of the second mark and detecting the availability of the second mark; wherein the mark number of the second mark is equal to the mark number of the first mark plus 1.
Referring to fig. 2, a method of another embodiment of the present invention includes: starting a real-time data ID generation service, reading related information of a mark n (n is more than 1) from a Redis real-time database, and detecting whether the mark n is available; starting with a marker n (n-1), if the marker n is not available, incrementing n by 1; if the marker n is detected to be available, taking the marker n as a service marker of the ID generation service, and reading the current ID in the marker n; when a request for generating a target ID is received, the target ID is generated according to the current ID, and then the target ID is written back to an information area of a Redis database mark n; and timed (every 10 minutes) to update the expiration time (current time plus 30 minutes) of the marker n at the Redis database.
The generated real-time data ID is long, the length is 8 bytes, the highest byte of the ID stores record type information, the second byte of the highest byte stores related information of a current mark, the maximum number of 127 parallel ID generation services is supported, and the mark range is 1 to 127; the other bytes of the ID hold increment information, starting with 0.
The content of the information related to the markers stored in the Redis database is shown in the following table 1:
TABLE 1 Mark related information
The method of the embodiment supports parallel service modes such as distributed service and micro service, and the generated real-time data ID has the following advantages: the ID occupies small space and does not influence the retrieval performance; the ID is provided with record type information, and the record types can be distinguished according to the ID; no timestamp, no time backoff issue; MAC address information without a network card meets the information security; there is no limit to the number of IDs supported per millisecond; and the requirement of the distribution automation system on the ID is met.
Referring to fig. 3, the system of the embodiment of the present invention includes: the system comprises a mark creating module, a real-time database and a marking module, wherein the mark creating module is used for setting a plurality of marks, the related information of each mark comprises a mark number, expiration time and a current ID, and the related information is stored in the real-time database; the availability detection module is used for reading the corresponding expiration time according to the sequence of the mark number and detecting the availability of the mark according to the expiration time; the target ID generating module is used for reading the current ID of the first mark, calculating the target ID according to the current ID of the first mark, and writing the target ID serving as the current ID of the first mark back to the real-time database; wherein the first marker is any one of a plurality of markers and the first marker is available; and the timing updating module is used for updating the expiration time of the first mark in a timing mode.
In some embodiments, the system further comprises: and the current ID setting module is used for setting the current ID to be in a long type and 8 bytes in length, configuring one byte of the highest position of the current ID to store record type information, and storing a corresponding mark number in the second byte of the highest position.
Although specific embodiments have been described herein, those of ordinary skill in the art will recognize that many other modifications or alternative embodiments are equally within the scope of this disclosure. For example, any of the functions and/or processing capabilities described in connection with a particular device or component may be performed by any other device or component. In addition, while various illustrative implementations and architectures have been described in accordance with embodiments of the present disclosure, those of ordinary skill in the art will recognize that many other modifications of the illustrative implementations and architectures described herein are also within the scope of the present disclosure.
Certain aspects of the present disclosure are described above with reference to block diagrams and flowchart illustrations of systems, methods, systems, and/or computer program products according to example embodiments. It will be understood that one or more blocks of the block diagrams and flowchart illustrations, and combinations of blocks in the block diagrams and flowchart illustrations, respectively, can be implemented by executing computer-executable program instructions. Also, according to some embodiments, some blocks of the block diagrams and flow diagrams may not necessarily be performed in the order shown, or may not necessarily be performed in their entirety. In addition, additional components and/or operations beyond those shown in the block diagrams and flow diagrams may be present in certain embodiments.
Accordingly, blocks of the block diagrams and flowchart illustrations support combinations of means for performing the specified functions, combinations of elements or steps for performing the specified functions and program instruction means for performing the specified functions. It will also be understood that each block of the block diagrams and flowchart illustrations, and combinations of blocks in the block diagrams and flowchart illustrations, can be implemented by special purpose hardware-based computer systems that perform the specified functions, elements or steps, or combinations of special purpose hardware and computer instructions.
Program modules, applications, etc. described herein may include one or more software components, including, for example, software objects, methods, data structures, etc. Each such software component may include computer-executable instructions that, in response to execution, cause at least a portion of the functionality described herein (e.g., one or more operations of the illustrative methods described herein) to be performed.
The software components may be encoded in any of a variety of programming languages. An illustrative programming language may be a low-level programming language, such as assembly language associated with a particular hardware architecture and/or operating system platform. Software components that include assembly language instructions may need to be converted by an assembler program into executable machine code prior to execution by a hardware architecture and/or platform. Another exemplary programming language may be a higher level programming language, which may be portable across a variety of architectures. Software components that include higher level programming languages may need to be converted to an intermediate representation by an interpreter or compiler before execution. Other examples of programming languages include, but are not limited to, a macro language, a shell or command language, a job control language, a scripting language, a database query or search language, or a report writing language. In one or more exemplary embodiments, a software component containing instructions of one of the above programming language examples may be executed directly by an operating system or other software component without first being converted to another form.
The software components may be stored as files or other data storage constructs. Software components of similar types or related functionality may be stored together, such as in a particular directory, folder, or library. Software components may be static (e.g., preset or fixed) or dynamic (e.g., created or modified at execution time).
The embodiments of the present invention have been described in detail with reference to the accompanying drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge of those skilled in the art without departing from the gist of the present invention.