Data processing method, apparatus, device, and computer-readable medium
By monitoring and asynchronously generating verification codes, combined with table partitioning and database transaction mechanisms, the uniqueness problem of verification codes is solved, achieving stability and scalability in high-concurrency scenarios, and improving the operational and storage efficiency of verification codes.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- BEIJING WODONG TIANJUN INFORMATION TECH CO LTD
- Filing Date
- 2026-05-12
- Publication Date
- 2026-07-31
AI Technical Summary
The uniqueness of verification codes in existing technologies is difficult to guarantee, which cannot meet the stability and scalability requirements of verification codes in high-concurrency and high-availability business scenarios.
By monitoring the number of unused verification codes in the active verification code master table, verification codes are generated asynchronously when the number falls below a preset threshold. A partitioned storage architecture and database transaction mechanism are used, combined with message queues and thread pools, to achieve batch generation and locking of verification codes, ensuring the uniqueness and efficient retrieval of verification codes.
It improves the stability and scalability of verification code operations, reduces the impact on normal business operations, and supports reliable retrieval and storage efficiency in high-concurrency scenarios.
Smart Images

Figure CN122489607A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a data processing method, apparatus, device, and computer-readable medium. Background Technology
[0002] In various online and offline business scenarios, the verification code serves as the core carrier for order verification, rights redemption, and voucher verification. Its generation, verification, and storage directly affect the stability of the business system.
[0003] In the process of realizing this invention, the inventors discovered that the prior art has at least the following problems: due to the difficulty in guaranteeing the uniqueness of the verification code, it is impossible to meet the stability and scalability requirements of operating the verification code in high-concurrency and high-availability business scenarios. Summary of the Invention
[0004] In view of this, embodiments of the present invention provide a data processing method, apparatus, device, and computer-readable medium that can improve the stability and scalability of verification code operations.
[0005] To achieve the above objectives, according to one aspect of the present invention, a data processing method is provided, comprising: The system monitors the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than the preset master table capacity threshold, verification codes are generated asynchronously based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. In response to a request to retrieve a verification code, a preset number of unused verification codes are locked in the active verification code master table. The status of the locked verification codes is updated within a database transaction, and the preset number of verification codes are retrieved after the database transaction is committed.
[0006] The asynchronous generation of verification codes based on preset verification code encoding conditions includes: The verification code is generated asynchronously based on the batch number, check code, and random sequence generated based on the batch number in the verification code encoding conditions. The batch number is an incrementing identifier when generating a new batch verification code, and the check code is generated based on the batch number and the random sequence.
[0007] When the number of unused verification codes is lower than a preset main table capacity threshold, verification codes are asynchronously generated based on preset verification code encoding conditions, and the generated verification codes are written in batches to the active verification code main table, including: When the number of unused verification codes is lower than the preset main table capacity threshold, a verification code generation task is pushed through the message queue. Multiple threads in the thread pool retrieve the task to generate verification codes from the message queue and asynchronously generate verification codes. The generated verification codes are then written in batches to the active verification code master table. After the verification codes for the current batch are written, the current batch number is updated.
[0008] The process of locking a preset number of unused verification codes in the active verification code master table, updating the status of the locked verification codes within a database transaction, and retrieving the preset number of verification codes after committing the database transaction includes: A row-level lock is applied to a preset number of unused verification codes in the active verification code master table to lock the data records of the unused verification codes; In the database transaction, update the status of the locked verification codes and the data record, commit the database transaction to release the row-level lock, and return to retrieve the preset number of verification codes; If an exception occurs during the execution of the database transaction, the database transaction is rolled back, the data records with unused verification codes remain unchanged, and row-level locks are applied again to the preset number of unused verification codes.
[0009] The method further includes: Based on a preset archiving period, scan the active redemption code master table for used redemption codes that meet the archiving conditions, batch migrate the used redemption codes and their associated data to the historical redemption code archive table for storage, and delete the migrated data in the active redemption code master table to achieve separate storage of active data and historical data.
[0010] The preset archiving period is a low-business-load period set based on the scheduled task framework. The archiving conditions include the verification code being in use and the verification code being retrieved earlier than the preset time for archiving execution.
[0011] The active redemption code master table adopts a partitioned storage architecture to store unused redemption codes and unarchived used redemption codes; The historical verification code archive table is stored in partitions according to the archiving time, and is used to store archived and used verification codes.
[0012] According to a second aspect of the present invention, a data processing apparatus is provided, comprising: The generation module is used to monitor the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than the preset master table capacity threshold, verification codes are generated asynchronously based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. The update module is used to respond to a verification code retrieval request, lock a preset number of unused verification codes in the active verification code master table, update the status of the locked verification codes within a database transaction, and retrieve the preset number of verification codes after the database transaction is committed.
[0013] According to a third aspect of the present invention, a data processing electronic device is provided, comprising: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors perform the methods described above.
[0014] According to a fourth aspect of the present invention, a computer-readable medium is provided having a computer program stored thereon, which, when executed by a processor, implements the method as described above.
[0015] One embodiment of the above invention has the following advantages or beneficial effects: It monitors the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than a preset master table capacity threshold, it asynchronously generates verification codes based on preset verification code encoding conditions and writes the generated verification codes into the active verification code master table in batches. In response to a verification code retrieval request, it locks a preset number of unused verification codes in the active verification code master table, updates the status of the locked verification codes within a database transaction, and retrieves the preset number of verification codes after committing the database transaction. Asynchronous generation of verification codes from the active verification code master table reduces the impact on normal business operations, and locking unused verification codes meets the stability and scalability requirements of operating verification codes in high-concurrency, high-availability business scenarios.
[0016] The further effects of the aforementioned unconventional alternative methods will be explained below in conjunction with specific implementation methods. Attached Figure Description
[0017] The accompanying drawings are provided to better understand the invention and are not intended to unduly limit the scope of the invention. Wherein: Figure 1 This is a schematic diagram of the main flow of the data processing method according to an embodiment of the present invention; Figure 2 This is a schematic diagram of the process for asynchronously generating a verification code including a batch number and a random sequence according to an embodiment of the present invention; Figure 3 This is a schematic diagram of the process for obtaining a verification code according to an embodiment of the present invention; Figure 4 This is a schematic diagram of the main structure of a data processing apparatus according to an embodiment of the present invention; Figure 5This is an exemplary system architecture diagram in which embodiments of the present invention can be applied; Figure 6 This is a schematic diagram of the structure of a computer system suitable for implementing terminal devices or servers of the present invention. Detailed Implementation
[0018] The following description, in conjunction with the accompanying drawings, illustrates exemplary embodiments of the present invention, including various details to aid understanding. These details should be considered merely exemplary. Therefore, those skilled in the art will recognize that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the invention. Similarly, for clarity and brevity, descriptions of well-known functions and structures are omitted in the following description.
[0019] The verification code scheme, using a Universally Unique Identifier (UUID) as the core generation source and combined with Elasticsearch (ES) for availability verification, is as follows: When generating the verification code, underscore characters are first removed from the UUID. The resulting hexadecimal string is then converted to a decimal value, and a specified number of digits is extracted to form the final verification code. Before the verification code is used, ES compares the verification code to be used with all business data, filtering out verification codes not bound to orders for user access. Verification codes already bound to orders are marked as unavailable. There is no need to distinguish between active and historical verification codes; all verification codes and associated business data are stored together.
[0020] However, the above-mentioned solution has revealed the following technical shortcomings in practical applications. First, regarding the uniqueness of the verification code, the UUID value after conversion to decimal is too long, making it prone to duplication when truncating a specified number of digits. Furthermore, the lack of effective control over the generation of multiple batches of UUIDs exacerbates the risk of duplication. Second, regarding retrieval efficiency, each retrieval requires comparison with the entire business data via Elasticsearch (ES). As the data volume increases, the comparison time increases exponentially, easily leading to response delays during peak periods. Third, regarding concurrency security, the operation of querying verification codes and bound orders via ES can easily lead to duplicate binding of the same verification code when multiple terminals retrieve it simultaneously. Additionally, the data storage layer does not distinguish between active and historical data, resulting in high storage capacity pressure, low traceability query efficiency, and a lack of automated archiving mechanisms. Finally, the distribution of verification codes is uneven. Due to the characteristics of the original UUID encoding and the truncation operation, they tend to concentrate in specific value ranges, which is detrimental to hierarchical management and load balancing of batch operations. Therefore, because the uniqueness of the verification code is difficult to guarantee, it cannot meet the stability and scalability requirements of operating verification codes in high-concurrency, high-availability business scenarios.
[0021] To address the inability to meet the stability and scalability requirements of operation verification codes in high-concurrency and high-availability business scenarios, the following technical solutions from the embodiments of the present invention can be adopted.
[0022] See Figure 1 , Figure 1 This is a schematic diagram of the main flow of a data processing method according to an embodiment of the present invention. Specifically, it includes the following steps: S101. Monitor the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than the preset master table capacity threshold, asynchronously generate verification codes based on the preset verification code encoding conditions, and write the generated verification codes into the active verification code master table in batches.
[0023] In embodiments of the present invention, a master table of active verification codes is used to store verification codes. As verification codes in the master table of active verification codes are used, the number of unused verification codes gradually decreases. Verification code generation is supported by configuring verification code encoding conditions and a master table capacity threshold for the active verification code master table.
[0024] The coding conditions for verification codes include the structure and verification method of the verification code. For example, the verification code includes a preset number of digits and a check digit. The coding conditions for verification codes also include the batch number associated with the batch. For example, the batch number is used as the primary key, and the uniqueness constraint of the primary key avoids the generation of duplicate batches, ensuring that the batch number used each time a new batch generation task is started can accurately increment and does not duplicate historical batches.
[0025] The main table capacity threshold is a control parameter that triggers the asynchronous generation of verification codes. For example, the default main table capacity threshold is 30% of the maximum capacity of the active verification code main table, which is 15 million records. The active verification code main table uses a partitioned storage architecture, with a maximum storage capacity of 50 million records per table. The main table capacity threshold can be dynamically adjusted according to actual business needs. When the number of unused verification codes in the active verification code main table falls below the main table capacity threshold, verification code generation will be triggered to ensure the continuity of verification code supply.
[0026] The verification code encoding conditions and the main table capacity threshold of the active verification code master table are stored in a single MySQL table. The structure of this single MySQL table includes fields such as batch number, master table capacity threshold, code length, verification rules, and update time. Parameters can be dynamically modified and synchronized in real time. The single table is named in the format `verification_code_main_XXX`, where XXX is the table sub-number. After configuration, it provides the verification code encoding conditions and the current batch number for verification code generation. After a new batch of verification codes is generated and written, it receives the corresponding batch number update notification to maintain consistency between configuration and data status.
[0027] If the number of unused verification codes in the active verification code master table falls below the master table's capacity threshold, it is determined that new verification codes need to be added. Verification codes, including batch numbers and random sequences, are generated asynchronously according to the verification code encoding conditions. Through an asynchronous write mechanism, the generation and storage of verification codes are completed in the background, without blocking or affecting the response speed of real-time business operations such as front-end verification code retrieval.
[0028] S102. In response to the verification code retrieval request, lock a preset number of unused verification codes in the active verification code master table, update the status of the locked verification codes within the database transaction, and retrieve the preset number of verification codes after committing the database transaction.
[0029] In embodiments of the present invention, a standardized HTTP interface is used to respond to verification code retrieval requests and send verification codes. For example, it supports retrieving 10,000 verification codes at once, with a response time of ≤500ms. External terminals (such as offline store systems, e-commerce platforms, etc.) can obtain available verification codes in batches by calling the standardized HTTP interface and inputting necessary parameters such as terminal identifiers.
[0030] To address concurrency conflicts caused by the non-atomic nature of Elasticsearch queries and verification code binding operations, a database transaction mechanism is employed to achieve atomic operations, with the transaction isolation level set to READ_COMMITTED. Within a single transaction, query locking, status updates, and result return operations are executed sequentially. After committing the database transaction, a successfully retrieved verification code is returned.
[0031] exist Figure 1 In this embodiment, the number of unused verification codes in the active verification code master table of the database is monitored. When the number of unused verification codes is lower than a preset master table capacity threshold, verification codes are asynchronously generated based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. In response to a verification code retrieval request, a preset number of unused verification codes in the active verification code master table are locked. The status of the locked verification codes is updated within a database transaction, and the preset number of verification codes are retrieved after the database transaction is committed. Asynchronous generation of verification codes from the active verification code master table reduces the impact on normal business operations, and locking unused verification codes meets the stability and scalability requirements of verification code operation in high-concurrency and high-availability business scenarios.
[0032] See Figure 2 , Figure 2 This is a schematic diagram illustrating the process of asynchronously generating a verification code including a batch number and a random sequence according to an embodiment of the present invention. Specifically, it includes the following steps: S201. When the number of unused verification codes is lower than the preset main table capacity threshold, a verification code generation task is pushed through the message queue.
[0033] When the number of unused verification codes in the active verification code master table storage falls below the master table capacity threshold, a verification code generation task is triggered via a message queue. Specifically, a statistics thread is set up to scan the number of unused verification codes in the active verification code master table storage every 5 minutes and compare the scan results with the master table capacity threshold. When the number of unused verification codes falls below the master table capacity threshold, it is determined that new verification codes need to be added, and a verification code generation task is then pushed through the message queue.
[0034] S202. Multiple threads in the thread pool obtain the task of generating verification codes from the message queue and asynchronously generate verification codes. The generated verification codes are then written in batches to the active verification code master table. After the verification codes for the current batch are written, the current batch number is updated.
[0035] Upon receiving the verification code task, asynchronous verification code generation is initiated. The verification code encoding conditions are retrieved, and the verification code is generated asynchronously. Specifically, the batch number, checksum, and random sequence generated based on the batch number are retrieved from the verification code encoding conditions. The verification code is generated asynchronously based on the batch number, checksum, and random sequence generated based on the batch number. The batch number is an incrementing identifier used when generating a new batch of verification codes, and the checksum is generated based on the batch number and the random sequence.
[0036] Based on the batch number, a 10-digit random sequence is generated using a uniform random number algorithm to ensure balanced distribution. After concatenating the batch number, a 2-digit CRC checksum is calculated using a verification algorithm to form an 18-digit verification code.
[0037] For example: If the current batch number is a 6-digit incrementing number 000001, the verification code encoding conditions are: 6-digit batch number + 10-digit uniform random sequence + 2-digit CRC check code, and the verification algorithm is CRC-16.
[0038] Specifically, the process first generates the current batch number as a prefix; then, a uniform random number generator is called to generate a 10-digit sequence based on the batch number. This random sequence is uniformly distributed in the numerical space, effectively solving the problem of the verification code being concentrated in a specific range due to the UUID truncation scheme; finally, a CRC-16 operation is performed on the 16-digit string obtained by concatenating the batch number and the random sequence to generate a 2-digit check code, which is then appended to the end to form a complete 18-digit verification code.
[0039] After the verification code task is pushed to the message queue system (RabbitMQ), multiple background threads write it to the active verification code master table in batches. Through the asynchronous write mechanism, the generation and storage of verification codes are completed in the background, which will not block or affect the response speed of real-time business such as front-end verification code retrieval.
[0040] After a new batch of verification codes is written, the batch number increments by 1. For example, if the current batch number is 000001, after all verification codes for this batch are generated and written, the batch number will be updated to 000002, preparing for the next batch generation task. The incremental uniqueness constraint of the batch number enables global deduplication of verification codes across batches.
[0041] exist Figure 2 In the embodiment, the generation of verification codes adopts a combination of main table capacity threshold triggering and asynchronous decoupling to ensure the continuity of verification code supply, while avoiding the generation process from affecting the main business response.
[0042] See Figure 3 , Figure 3 This is a schematic diagram of the process for obtaining a verification code according to an embodiment of the present invention. Specifically, it includes the following steps: S301. Apply a row-level lock to a preset number of unused verification codes in the active verification code master table to lock the data records of the unused verification codes.
[0043] After a database transaction starts, the first step within the transaction is to perform a locking operation on queries that do not use checksums. Specifically, this involves executing a SELECT statement. The statement `FROM main table WHERE status=0 LIMIT 10000 FOR UPDATE` sets the default value to 10000, locking 10000 data records for each verification code using row-level locking.
[0044] The above SQL statement filters the active redemption codes in the master table by selecting codes with a status field value of 0, indicating unused redemption codes, and limits the number of rows returned to a preset quantity using the LIMIT clause. The FOR UPDATE clause applies row-level locks to the rows matched by the query. When the database transaction isolation level is set to READ_COMMITTED, row-level locks can precisely lock the selected specific rows, rather than locking the entire data page or table.
[0045] Data records with row-level locks cannot be modified or re-locked by other concurrent transactions until the current transaction commits or rolls back. This achieves exclusive access to a preset number of verification codes and effectively avoids concurrent conflicts caused by multiple terminals simultaneously accessing the same verification code.
[0046] S302. In the database transaction, update the status and data records of the locked verification codes, commit the database transaction to release the row-level lock, and return to retrieve the preset number of verification codes.
[0047] Update the status of the locked verification code to "used", update the data record and commit the transaction. If an exception occurs during the execution of the transaction, it will be automatically rolled back. After the transaction is rolled back, the status of the corresponding verification code remains unchanged for subsequent retrieval.
[0048] After successfully locking an unused verification code, the database transaction immediately performs a status update operation. Specifically: `UPDATE main_table SET status=1, take_time=NOW(), terminal_identifier=? WHERE verification_code IN (query_result)`. This update statement changes the status field of the locked verification code from 0 to 1, indicating that the verification code has been taken and entered the used state. Simultaneously, `take_time=NOW()` records the current database system time as a timestamp for taking the code, and the terminal_identifier parameter passed from the external request is written to the corresponding field for subsequent tracking of the verification code.
[0049] After the status update operation is completed, the database transaction executes a COMMIT operation. After the transaction is committed, a list of 10,000 verification codes is returned to the requesting terminal, and the applied row-level locks are released. The status change of the verification codes officially takes effect and becomes visible externally. Simultaneously, the list of successfully retrieved verification codes is returned to the requesting party as response data for subsequent business processes, such as issuing to users and binding orders.
[0050] S303. If an exception occurs during the execution of a database transaction, the database transaction is rolled back. Data records without used check codes remain unchanged, and row-level locks are applied again to the preset number of unused check codes.
[0051] If any abnormal situation occurs during transaction execution, such as database connection interruption, update statement execution failure, constraint conflict, etc., an automatic rollback will be performed. All operations executed within the transaction will be automatically undone, including releasing applied row-level locks and restoring locked checksum records to their unused state before the transaction began. After the transaction rollback, the corresponding checksum data records remain unchanged for subsequent retrieval, ensuring data consistency and integrity and avoiding data inconsistencies such as partial updates or loss of checksums due to abnormalities. Then, S301 is re-executed.
[0052] exist Figure 3 In this embodiment, the combination of row-level locks within database transactions and the rollback mechanism enables atomic processing of the verification code retrieval operation, ensuring conflict-free concurrent retrieval from multiple terminals and supporting hundreds of retrieval requests per second. Even in high-concurrency scenarios, it can effectively schedule the access order of data rows by each concurrent transaction, ensuring retrieval reliability and overall throughput.
[0053] In one embodiment of the present invention, based on a preset archiving period, the used verification codes that meet the archiving conditions in the active verification code master table are scanned, and the used verification codes and their associated data are migrated in batches to the historical verification code archive table for storage. The migrated data is then deleted from the active verification code master table to achieve separate storage of active data and historical data.
[0054] Driven by a scheduled task framework. Based on the Quartz scheduled task framework, the default low-load period is 2:00-4:00 AM daily, which can be preset by configuration. That is, the preset archiving period is based on the low-load period set by the scheduled task framework. Selecting off-peak hours to execute archiving tasks can minimize the read / write pressure on the main business database during data migration operations, ensuring timely response during peak business hours.
[0055] The task is not a one-time migration of all used redemption codes in the active redemption code master table, but rather a filtering process based on preset archiving criteria. Archiving criteria include that the redemption code is in a used state and that the redemption code was retrieved before the current archiving time by a preset duration.
[0056] Used verification codes that meet the archiving criteria are those whose status is "used" and whose retrieval time is earlier than the preset time before the current archiving execution time. Specifically, query the main table for used verification codes where status=1 and take_time<00:00 of the previous day. The purpose of setting the retrieval time to be earlier than 00:00 of the previous day is to reserve the business processing cycle for verification codes retrieved on the current day, such as order confirmation, return and exchange processes, etc., and to avoid verification codes that are currently associated with active business being migrated to the historical verification code archive table too early, which would lead to difficulties in subsequent tracing.
[0057] Specifically, paginated batch migration is used to reduce the instantaneous load pressure on the database for a single operation.
[0058] The system queries the active redemption code master table for used redemption codes that meet the archiving criteria. After the archiving task starts, it first performs a query on the active redemption code master table according to the archiving criteria to obtain a set of data records that meet the migration conditions. Due to the large amount of data in the active redemption code master table, the query operation is optimized using an index, leveraging a combined index on the status field and the usage time field to accelerate retrieval.
[0059] Data is batch-inserted into the archive table using a paginated approach (1000 records per page), with the archive time recorded. Query result sets are processed batch-wise in a paginated manner, retrieving 1000 records per page. For each page, a database insert operation is performed, writing the verification code and associated business data to the historical verification code archive table, recording the current system time as the archive time field value during the write operation. The historical verification code archive table is a MySQL table partitioned by date, with the partition key being the archive time. This facilitates efficient tracing and querying of historical records by time range and also supports setting the data retention period according to business needs, such as 1 year, to clean up expired data and achieve continuous optimization of storage capacity.
[0060] After the migration is complete, the corresponding records in the active verification code master table are deleted in batches to free up storage space. Once it is confirmed that the data for the current page has been successfully written to the historical verification code archive table, the corresponding record for that page is then deleted from the active verification code master table. Through the execution of migration and deletion, the complete transfer of data is ensured while the storage space of the active verification code master table is released in a timely manner.
[0061] To ensure the reliability of the archiving process, logs are recorded during migration. If a batch migration fails, the next task will automatically retry to ensure no data loss. Specifically, an execution identifier is generated for each archiving task, and the processing status of each page of data is recorded. If a database exception or failure occurs during batch migration or deletion, the processing status of that batch of data is marked as failed. When the next scheduled task starts, it will automatically scan for batches that failed to process and re-execute the migration and deletion operations until all data is successfully archived. This effectively avoids data omissions or backlogs caused by the failure of a single task.
[0062] In the above embodiments, physical storage separation of active and historical verification codes is achieved. The active verification code master table adopts a partitioned storage architecture to store unused verification codes and unarchived used verification codes. This effectively reduces the data volume of a single active verification code master table and improves the query efficiency of verification code generation and retrieval. The historical verification code archive table is stored in partitions according to archiving time and is used to store archived used verification codes. This provides an independent query channel for scenarios such as business auditing and data traceability, avoiding interference with the active verification code master table.
[0063] The system employs a dual-table storage approach, consisting of a master table for active redemption codes and an archive table for historical redemption codes. This approach reduces the load on a single table at the architectural level and improves query and retrieval efficiency.
[0064] See Figure 4 , Figure 4 This is a schematic diagram of the main structure of a data processing apparatus according to an embodiment of the present invention. The data processing apparatus can implement a data processing method, and specifically includes: The generation module 401 is used to monitor the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than the preset master table capacity threshold, verification codes are generated asynchronously based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. The update module 402 is used to respond to a verification code retrieval request, lock a preset number of unused verification codes in the active verification code master table, update the status of the locked verification codes within a database transaction, and retrieve the preset number of verification codes after the database transaction is committed.
[0065] In one embodiment of the present invention, the generation module 401 is used to asynchronously generate the verification code according to the batch number, the check code and the random sequence generated based on the batch number in the verification code encoding conditions, wherein the batch number is an incrementing identifier when generating a new batch verification code, and the check code is generated based on the batch number and the random sequence.
[0066] In one embodiment of the present invention, the generation module 401 is used to push a task to generate a verification code through a message queue when the number of unused verification codes is lower than a preset main table capacity threshold. Multiple threads in the thread pool retrieve the task to generate verification codes from the message queue and asynchronously generate verification codes. The generated verification codes are then written in batches to the active verification code master table. After the verification codes for the current batch are written, the current batch number is updated.
[0067] In one embodiment of the present invention, the update module 402 is used to apply a row-level lock to a preset number of unused verification codes in the active verification code master table to lock the data records of the unused verification codes; In the database transaction, update the status of the locked verification codes and the data record, commit the database transaction to release the row-level lock, and return to retrieve the preset number of verification codes; If an exception occurs during the execution of the database transaction, the database transaction is rolled back, the data records with unused verification codes remain unchanged, and row-level locks are applied again to the preset number of unused verification codes.
[0068] In one embodiment of the present invention, the update module 402 is used to scan the used verification codes that meet the archiving conditions in the active verification code master table based on a preset archiving period, batch migrate the used verification codes and their associated data to the historical verification code archive table for storage, and delete the migrated data in the active verification code master table to achieve separate storage of active data and historical data.
[0069] In one embodiment of the present invention, the preset archiving period is a low-load period set based on a scheduled task framework; The archiving conditions include the verification code being in use and the verification code being retrieved earlier than the preset time for archiving execution.
[0070] In one embodiment of the present invention, the active redemption code master table adopts a partitioned storage architecture to store unused redemption codes and unarchived used redemption codes; The historical verification code archive table is stored in partitions according to the archiving time, and is used to store archived and used verification codes.
[0071] Figure 5 An exemplary system architecture 500 is shown that can be applied to the data processing method or data processing apparatus of the present invention.
[0072] like Figure 5 As shown, system architecture 500 may include terminal devices 501, 502, and 503, a network 504, and a server 505. Network 504 serves as the medium for providing communication links between terminal devices 501, 502, and 503 and server 505. Network 504 may include various connection types, such as wired or wireless communication links, or fiber optic cables, etc.
[0073] Users can use terminal devices 501, 502, and 503 to interact with server 505 via network 504 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 501, 502, and 503, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social media platform software, etc. (for example only).
[0074] Terminal devices 501, 502, and 503 can be various electronic devices with displays that support web browsing, including but not limited to smartphones, tablets, laptops, and desktop computers.
[0075] Server 505 can be a server that provides various services, such as a backend management server that supports shopping websites browsed by users using terminal devices 501, 502, and 503 (for example only). The backend management server can analyze and process data such as received product information query requests, and feed back the processing results (such as target push information and product information - for example only) to the terminal devices.
[0076] It should be noted that the data processing method provided in the embodiments of the present invention is generally executed by server 505, and correspondingly, the data processing device is generally located in server 505.
[0077] It should be understood that Figure 5The number of terminal devices, networks, and servers shown is merely illustrative. Depending on implementation needs, any number of terminal devices, networks, and servers can be included.
[0078] The following is for reference. Figure 6 It shows a schematic diagram of the structure of a computer system 600 suitable for implementing a terminal device of the present invention. Figure 6 The terminal device shown is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of the present invention.
[0079] like Figure 6 As shown, the computer system 600 includes a central processing unit (CPU) 601, which can perform various appropriate actions and processes based on programs stored in read-only memory (ROM) 602 or programs loaded from storage section 608 into random access memory (RAM) 603. The RAM 603 also stores various programs and data required for the operation of the system 600. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.
[0080] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to I / O interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on drive 610 as needed so that computer programs read from it can be installed into storage section 608 as needed.
[0081] In particular, according to the embodiments disclosed in this invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this invention include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit (CPU) 601, it performs the functions defined above in the system of this invention.
[0082] It should be noted that the computer-readable medium shown in this invention can be a computer-readable signal medium or a computer-readable storage medium, or any combination thereof. A computer-readable storage medium can be, for example,—but not limited to—an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this invention, a computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this invention, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying computer-readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to: wireless, wire, optical fiber, RF, etc., or any suitable combination thereof.
[0083] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present invention. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0084] The modules described in the embodiments of the present invention can be implemented in software or hardware. The described modules can also be housed in a processor; for example, a processor can be described as including a generation module and an update module. The names of these modules do not necessarily limit the module itself. For example, the generation module can also be described as "monitoring the number of unused verification codes in the active verification code master table of the database; when the number of unused verification codes is lower than a preset master table capacity threshold, asynchronously generating verification codes based on preset verification code encoding conditions, and batch writing the generated verification codes into the active verification code master table."
[0085] In another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiments; or it may exist independently and not assembled into the device. The computer-readable medium carries one or more programs, which, when executed by the device, cause the device to include: The system monitors the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than the preset master table capacity threshold, verification codes are generated asynchronously based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. In response to a request to retrieve a verification code, a preset number of unused verification codes are locked in the active verification code master table. The status of the locked verification codes is updated within a database transaction, and the preset number of verification codes are retrieved after the database transaction is committed.
[0086] According to the technical solution of this invention, the number of unused verification codes in the active verification code master table of the database is monitored. When the number of unused verification codes is lower than a preset master table capacity threshold, verification codes are asynchronously generated based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. In response to a verification code retrieval request, a preset number of unused verification codes in the active verification code master table are locked. The status of the locked verification codes is updated within a database transaction, and the preset number of verification codes are retrieved after the database transaction is committed. Asynchronous generation of verification codes from the active verification code master table reduces the impact on normal business operations, and locking unused verification codes meets the stability and scalability requirements of verification code operation in high-concurrency and high-availability business scenarios.
[0087] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can occur depending on design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention. It should be noted that the acquisition, storage, and application of user personal information involved in the technical solutions of this disclosure comply with relevant laws and regulations and do not violate public order and good morals.
Claims
1. A data processing method, characterized by, include: The system monitors the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than the preset master table capacity threshold, verification codes are generated asynchronously based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. In response to a request to retrieve a verification code, a preset number of unused verification codes are locked in the active verification code master table. The status of the locked verification codes is updated within a database transaction, and the preset number of verification codes are retrieved after the database transaction is committed.
2. The data processing method of claim 1, wherein, The asynchronous generation of verification codes based on preset verification code encoding conditions includes: The verification code is generated asynchronously based on the batch number, check code, and random sequence generated based on the batch number in the verification code encoding conditions. The batch number is an incrementing identifier when generating a new batch verification code, and the check code is generated based on the batch number and the random sequence.
3. The data processing method of claim 1, wherein, When the number of unused verification codes is lower than a preset main table capacity threshold, verification codes are asynchronously generated based on preset verification code encoding conditions, and the generated verification codes are written in batches to the active verification code main table, including: When the number of unused verification codes is lower than the preset main table capacity threshold, a verification code generation task is pushed through the message queue. Multiple threads in the thread pool retrieve the task to generate verification codes from the message queue and asynchronously generate verification codes. The generated verification codes are then written in batches to the active verification code master table. After the verification codes for the current batch are written, the current batch number is updated.
4. The data processing method of claim 1, wherein, The process of locking a preset number of unused verification codes in the active verification code master table, updating the status of the locked verification codes within a database transaction, and retrieving the preset number of verification codes after committing the database transaction includes: A row-level lock is applied to a preset number of unused verification codes in the active verification code master table to lock the data records of the unused verification codes; In the database transaction, update the status of the locked verification code and the data record, commit the database transaction to release the row-level lock, and return to retrieve the preset number of verification codes; If an exception occurs during the execution of the database transaction, the database transaction is rolled back, the data records with unused verification codes remain unchanged, and row-level locks are applied again to the preset number of unused verification codes.
5. The data processing method according to claim 1, characterized in that, The method further includes: Based on a preset archiving period, scan the active redemption code master table for used redemption codes that meet the archiving conditions, batch migrate the used redemption codes and their associated data to the historical redemption code archive table for storage, and delete the migrated data in the active redemption code master table to achieve separate storage of active data and historical data.
6. The data processing method according to claim 5, characterized in that, The preset archiving period is a low-business-load period set based on the scheduled task framework. The archiving conditions include the verification code being in use and the verification code being retrieved earlier than the preset time for archiving execution.
7. The data processing method according to claim 5, characterized in that, The active redemption code master table adopts a partitioned storage architecture to store unused redemption codes and unarchived used redemption codes; The historical verification code archive table is stored in partitions according to the archiving time, and is used to store archived and used verification codes.
8. A data processing apparatus, characterized in that, include: The generation module is used to monitor the number of unused verification codes in the active verification code master table of the database. When the number of unused verification codes is lower than the preset master table capacity threshold, verification codes are generated asynchronously based on preset verification code encoding conditions, and the generated verification codes are written to the active verification code master table in batches. The update module is used to respond to a verification code retrieval request, lock a preset number of unused verification codes in the active verification code master table, update the status of the locked verification codes within a database transaction, and retrieve the preset number of verification codes after the database transaction is committed.
9. A data processing electronic device, characterized in that, include: One or more processors; Storage device for storing one or more programs. When the one or more programs are executed by the one or more processors, the one or more processors implement the method as described in any one of claims 1-7.
10. A computer-readable medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the method as described in any one of claims 1-7.