SN number segment high-speed printing anti-duplicate method, computer equipment and storage medium
By using the redis cache database as a data verification node in industrial production systems, the data inconsistency and duplicate printing problems during high-speed printing of SN segments under the database master-slave architecture and read-write separation technology are solved, and data consistency and efficient printing process are achieved.
Patent Information
- Application Number
- CN202211384163.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-07
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2042-11-07
AI Technical Summary
In industrial production systems, the database master-slave architecture and read-write separation technology have data synchronization delays, resulting in inconsistent data during high-speed printing of SN segments, and the problem of repeated printing occurs.
The redis cache database is used as the data verification node, and its single-threaded feature is used to judge the data consistency when the SN segment print data acquisition speed is higher than the synchronization speed of read and write databases to prevent repeated printing.
Effectively prevent repeated printing of SN segment data, solving the problem of data inconsistency during high-speed printing of SN segments under read and write separation.
Smart Images

Figure CN115687381B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of SN number segment high-speed printing in the field of industrial production, and in particular to an SN number segment high-speed printing anti-duplicate method, computer equipment and storage medium. Background Art
[0002] The master-slave replication of the master-slave architecture of the database is an asynchronous replication process. It means that one or more databases (slave) replicate the logs from another database (master), then parse the logs and apply them to themselves, and finally make the data of the slave consistent with the data of the master. It seems that there is no problem in stand-alone application, but in the production environment of an enterprise, there will be replication delay problems in many cases. For example:
[0003] 1) In some deployment environments, the performance of the machine where the slave database is located is worse than that of the machine where the master database is located. In this case, if the resources of the machine are insufficient, the efficiency of slave database synchronization will be affected;
[0004] 2) The slave database acts as the master database. Generally, the main writing pressure is on the master database, so the slave database will provide some reading pressure. If the query pressure of the slave database is too high, the query of the slave database consumes a lot of CPU resources, which will inevitably affect the synchronization speed.
[0005] 3) Execution of large transactions: If a transaction in the master database takes 10 minutes to execute, and the writing of binlog must wait until the transaction is completed before it is transferred to the slave database, then the execution will be delayed at the beginning;
[0006] 4) When the TPS concurrency of the main database is very high and the number of DDLs generated exceeds the range that a thread can handle, delays may also occur.
[0007] These situations will cause data inconsistency between the master and slave databases within a specific period of time.
[0008] The database architecture of an industrial production system may use a master-slave architecture and read-write separation technology. In high-concurrency scenarios, the above four situations may occur while data is being written at high speed, especially in situation 4) where the TPS concurrency is very high, resulting in data synchronization delays. Summary of the invention
[0009] In order to solve the problems raised in the above background technology, the purpose of the present invention is to provide a method for preventing duplication of SN number segments in high-speed printing, a computer device and a storage medium, adopt the single-threaded characteristics of the redis cache database, use the redis cache database as a data verification node, and judge whether the master and slave databases are consistent, so as to solve the problem of duplication of SN number segments in high-speed printing in the master-slave architecture of the database in the read-write separation state in the industrial production system from the business logic level.
[0010] To achieve the above object, the present invention provides the following technical solutions:
[0011] A method for preventing duplicate printing of SN segments at high speed is implemented in a read-write separation architecture, and the specific steps are as follows:
[0012] Step S100: After the SN segment is printed, the completed data is written into the cache database;
[0013] Step S200: After writing into the cache database successfully, write into the write database;
[0014] Step S300: database synchronization, the write database synchronizes the printed data to the read database;
[0015] Step S400: SN segment printing request query reads unprinted data in the database;
[0016] Step S500: Read the database and return the unprinted data;
[0017] Step S600: Unprinted data consistency judgment: after reading the database and returning the unprinted data, compare it with the data in the redis cache database to determine whether the unprinted data returned by reading the database has been printed;
[0018] Step S700: Process the returned result. If it has not been printed, execute the printing task; if it has been printed, the system prompts to return to print to prevent duplicate printing.
[0019] A further technical solution is: the cache database is a redis cache database.
[0020] A further technical solution is:
[0021] A computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned SN number segment high-speed printing anti-duplication method are implemented.
[0022] A further technical solution is:
[0023] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of the above-mentioned SN number segment high-speed printing anti-duplicate method.
[0024] Compared with the prior art, the present invention has the following beneficial effects:
[0025] The present invention utilizes the single-threaded technical feature of the redis cache database. When the SN segment printing data acquisition speed is higher than the reading and writing database synchronization speed, the redis cache database is used as a verification node to verify whether the data is the latest, which can effectively prevent the SN segment data from being printed repeatedly. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 This is a flow chart of a traditional SN number segment high-speed printing method in an embodiment of the present invention;
[0027] Figure 2 This is an example diagram of a conventional SN number segment high-speed printing method used in an embodiment of the present invention;
[0028] Figure 3 This is a flow chart of a method for high-speed printing of SN segments in an embodiment of the present invention;
[0029] Figure 4 This is an example diagram of a method for high-speed printing of SN number segments in an embodiment of the present invention. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] In one embodiment, a conventional SN segment high-speed printing method, when an industrial production system performs an SN segment high-speed printing service, performs steps such as Figure 1 As shown:
[0032] Step 1: After the SN segment is printed, write the completed data into the database;
[0033] Step 2: Database synchronization, the write database synchronizes the printed data to the read database;
[0034] Step 3: SN segment printing request query reads the unprinted data in the database;
[0035] Step 4: Read the database and return unprinted data;
[0036] Step 5: Process the returned results, execute the printing task for the unprinted items, and give a system prompt for the printed items.
[0037] In a specific embodiment, a conventional SN segment high-speed printing method in the above embodiment is used, such as Figure 2 As shown:
[0038] In the read-write separation architecture, the M database is the write database and the N database is the read database.
[0039] The data requested by A (printing of the 0-100 segment) is written into the M database. Assuming that it takes 10ms for the data written into the M database to be synchronized to the N database, during the database synchronization process, B requests to query the N database (whether the 0-100 segment is printed) due to the read-write separation technology. At this time, the data in the M database (printing of the 0-100 segment) has not been fully synchronized to the N database, resulting in B's request not querying the latest data (printing of the 0-100 segment), but the old data (unprinted 0-100 segment). In this case, label reprinting occurs.
[0040] In general business scenarios, if data delays occur, you can repeatedly request refreshes to solve the business problem. However, if the label barcode is printed repeatedly, it is like a person's ID number is repeated and cannot be uniquely confirmed. This will cause the product to be unable to be uniquely identified, which is a very serious accident in production.
[0041] There are various ways to reduce latency in the industry, which can be solved in the following ways:
[0042] a1) The persistence layer of the business adopts a database-splitting architecture, which allows different business requests to be distributed to different database services, thus dispersing the pressure on a single machine;
[0043] a2) Use better hardware equipment, such as CPU, SSD, etc. However, this method is generally not acceptable to companies for the simple reason that it will increase the company's costs;
[0044] a3) Modify relevant configuration parameters from the library configuration to improve data synchronization efficiency or prevent data loss.
[0045] However, these methods only reduce or shorten the delay time of data synchronization, but do not completely eliminate the data synchronization delay. In addition, in some cases, the cost of upgrading the system hardware is very high, which may affect the data storage of other business scenarios, and the performance testing of the entire system is required.
[0046] In another optimized embodiment, Figure 3 As shown, a method for preventing duplicate printing of SN segments at high speed is implemented in a read-write separation architecture, and the specific steps are as follows:
[0047] Step S100: After the SN segment is printed, the completed data is written into the redis cache database;
[0048] Step S200: After successfully writing into the redis cache database, write into the write database;
[0049] Step S300: database synchronization, the write database synchronizes the printed data to the read database;
[0050] Step S400: SN segment printing request query reads unprinted data in the database;
[0051] Step S500: Read the database and return the unprinted data;
[0052] Step S600: Unprinted data consistency judgment: after reading the database and returning the unprinted data, compare it with the data in the redis cache database to determine whether the unprinted data returned by reading the database has been printed;
[0053] Step S700: Process the returned result. If it has not been printed, execute the printing task; if it has been printed, the system prompts to return to print to prevent duplicate printing.
[0054] To make the purpose, technical solution, method and advantages of the present invention clearer, the following Figure 4 A method for high-speed printing and anti-duplication of SN number segments in the above embodiment is applied.
[0055] Similarly, in the read-write separation architecture, the M database is the write database and the N database is the read database.
[0056] The data requested by A (the 0-100 segment has been printed) is first written into the redis cache database, and then written into the M database after the data is successfully written into the redis cache database. Assuming that it takes 10ms for the data written into the M database to be synchronized to the N database, during the data synchronization process, B requests to send a query request (whether the 0-100 segment is printed), and first reads the latest data in the redis cache database. At the same time, B requests to query the N database due to the read-write separation technology. At this time, if the data in the M database (the 0-100 segment has been printed) has not been fully synchronized to the N database. As a result, B's request does not query the latest data (the 0-100 segment has been printed), but the old data (the 0-100 segment has not been printed). When the data in the N database is returned, the data consistency judgment will be performed, and the data in the redis cache database will be compared with the data obtained from the N database. If there is inconsistency, it means that the data in the N database is not the latest, and an abnormal information is returned, so the segment label can be prevented from being reprinted.
[0057] The redis cache database is used as a data verification node to solve the problem of temporary data inconsistency caused by the delay in reading and writing data synchronization, which leads to repeated printing of SN segments. This problem only occurs when the SN segment is printed at high speed in the read-write separation state, and does not exist in the low-speed printing state.
[0058] In one possible embodiment, a computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of the above-mentioned SN number segment high-speed printing anti-duplication method are implemented.
[0059] In one possible embodiment, a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a method for high-speed printing and anti-duplication of SN number segments are implemented.
[0060] The present invention utilizes the single-threaded technical feature of the redis cache database. When the SN segment printing data acquisition speed is higher than the reading and writing database synchronization speed, the redis cache database is used as a verification node to verify whether the data is the latest, which can effectively prevent the SN segment data from being printed repeatedly.
[0061] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for preventing duplicate printing of SN segments at high speed, implemented in a read-write separation architecture, characterized in that: The specific steps are as follows: Step S100: After the SN segment is printed, the completed data is written into the cache database; Step S200: After writing into the cache database successfully, write into the write database; Step S300: database synchronization, the write database synchronizes the printed data to the read database; Step S400: SN segment printing request query reads unprinted data in the database; Step S5 00: Reading the database returns unprinted data; Step S6 00: No data consistency judgment is printed; After the unprinted data is returned from the database, it is compared with the data in the cache database to determine whether the unprinted data returned by the database has been printed; Step S700: Process the returned result. If it is not printed, execute the printing task; If it has been printed, the system will prompt to return to print to prevent duplicate printing.
2. According to claim 1, a method for preventing duplicate printing of SN segments at high speed, characterized in that: The cache database is a redis cache database.
3. A computer device, characterized in that: It includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps of a method for high-speed printing and anti-duplication of SN number segments as described in claim 1 or 2 are implemented.
4. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of a method for high-speed printing and anti-duplication of SN number segments as described in claim 1 or 2 are implemented.
Citation Information
Patent Citations
Method and device for deleting duplicated data and system
CN104077380A
Serial number acquisition method, device and system, electronic equipment and storage medium
CN110515956A