CN113297228B - MySQL writing method, device, equipment and medium based on multiple live instances - Google Patents
MySQL writing method, device, equipment and medium based on multiple live instances Download PDFInfo
- Publication number
- CN113297228B CN113297228B CN202110850708.6A CN202110850708A CN113297228B CN 113297228 B CN113297228 B CN 113297228B CN 202110850708 A CN202110850708 A CN 202110850708A CN 113297228 B CN113297228 B CN 113297228B
- Authority
- CN
- China
- Prior art keywords
- target
- row
- version number
- instance
- lock
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/28—Databases characterised by their database models, e.g. relational or object models
- G06F16/284—Relational databases
Landscapes
- Engineering & Computer Science (AREA)
- Databases & Information Systems (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Debugging And Monitoring (AREA)
Abstract
The invention relates to the field of data processing, and provides a MySQL writing method, a device, equipment and a medium based on multiple active examples, which can select an initial row lock with a target row identifier and a target row version number from a database table of MySQL to be written, use the multiple active examples to contend for the initial row lock, reduce matching time by resetting the target row version number when the initial row lock is detected to be contended, obtain the target row lock by releasing the row lock so that the initial row lock can be used, use the multiple active examples to contend for the target row lock, obtain the row version number of the target example to be contended for the row lock, compare the row version number of the target example with the target row version number, use the target example to execute writing operation in the MySQL to be written when the row version number of the target example is the same as the target row version number, and further solve the deadlock problem in the execution process of the multiple active examples, and ensuring that the MySQL database can write data normally.
Description
Technical Field
The invention relates to the technical field of data processing, in particular to a MySQL writing method, a MySQL writing device, MySQL writing equipment and MySQL writing media based on multiple live instances.
Background
In a distributed system, the adoption of multiple live instances can ensure high reliability of the system.
However, in the operation process, if the instances need to read and write MySQL, because the working mode and the working content of each instance are completely the same, a deadlock phenomenon occurs with a high probability. Once the deadlock occurs, the system cannot operate normally.
Therefore, how to avoid the deadlock phenomenon in the running process of multiple active instances becomes a problem to be solved urgently.
Disclosure of Invention
In view of the above, it is necessary to provide a MySQL writing method, apparatus, device and medium based on multiple active instances, which can solve the deadlock problem in the execution process of multiple active instances and ensure that the MySQL database can write data normally.
A multi-live instance based MySQL writing method comprises the following steps:
creating a database table to be written in MySQL, wherein the database table comprises a row identifier and a row version number;
acquiring a multi-live example consisting of at least one example, and acquiring a target row identifier and a target row version number;
connecting to the MySQL to be written, selecting a row lock with the target row identification and the target row version number from the database table as an initial row lock, and using the multi-active instance to contend for the initial row lock;
when the initial row lock is detected to be robbed, resetting the target row version number, and releasing the initial row lock by using the example of the robbed initial row lock to obtain a target row lock;
the multi-live example is used for contending the target row lock, and an example which is contended to the target row lock is determined as a target example;
acquiring the row version number of the target instance, and comparing the row version number of the target instance with the target row version number;
and when the row version number of the target instance is the same as the target row version number, executing write operation in the MySQL to be written by using the target instance.
According to a preferred embodiment of the invention, each of the multiple live instances has the same execution parameters.
According to the preferred embodiment of the present invention, when the multi-live instance is used to contend for the target row lock, the method further comprises:
determining an instance of the multi-live instance that does not rob the target row lock as a candidate instance;
controlling the candidate instance to wait for a preset time;
and after the preset time length, continuously contending for the target row lock by using the candidate examples.
According to a preferred embodiment of the invention, the method further comprises:
after the target instance is utilized to execute the writing operation in the MySQL to be written, accumulating a first numerical value on the line version number of the target instance to obtain the current line version number;
updating the target row version number in the database table to the current row version number;
and releasing the target row lock.
According to a preferred embodiment of the invention, the method further comprises:
when the row version number of the target example is different from the target row version number, accumulating a second numerical value on the row version number of the target example;
and releasing the target row lock.
According to a preferred embodiment of the invention, the method further comprises:
and when the target instance is detected to be down, the candidate instance is utilized to contend for the target row lock.
A multi-live instance based MySQL writing apparatus comprising:
the system comprises a creating unit, a storing unit and a writing unit, wherein the creating unit is used for creating a database table to be written in MySQL, and the database table comprises a row identifier and a row version number;
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a multi-live example consisting of at least one example, and acquiring a target line identifier and a target line version number;
the contending and robbing unit is used for connecting to the MySQL to be written, selecting a row lock with the target row identifier and the target row version number from the database table as an initial row lock, and contending and robbing the initial row lock by using the multi-live example;
the releasing unit is used for resetting the target row version number when the initial row lock is detected to be robbed, and releasing the initial row lock by using the example of the robbed initial row lock to obtain a target row lock;
the contention unit is further configured to contend the target row lock by using the multi-live example, and determine an example of the target row lock as a target example;
the comparison unit is used for acquiring the row version number of the target example and comparing the row version number of the target example with the target row version number;
and the execution unit is used for executing the writing operation in the MySQL to be written by using the target instance when the row version number of the target instance is the same as the target row version number.
According to a preferred embodiment of the invention, each of the multiple live instances has the same execution parameters.
A computer device, the computer device comprising:
a memory storing at least one instruction; and
a processor that executes instructions stored in the memory to implement the multi-live instance based MySQL write method.
A computer-readable storage medium having stored therein at least one instruction for execution by a processor in a computer device to implement the multi-live instance based MySQL write method.
It can be seen from the above technical solutions that the present invention can create a database table to be written in MySQL, where the database table includes a row identifier and a row version number, obtains a multi-active instance composed of at least one instance, obtains a target row identifier and a target row version number, connects to the MySQL to be written, selects a row lock with the target row identifier and the target row version number from the database table as an initial row lock, and uses the multi-active instance to contend for the initial row lock, when it is detected that the initial row lock is contended, resets the target row version number, and uses the instance that is contended for the initial row lock to release the initial row lock, to obtain a target row lock, through resetting, reduces matching time, enables the initial row lock to be used by releasing the row lock, contends for the target row lock by using the multi-active instance, and determines the instance that is contended for the target row lock as a target instance, and acquiring the row version number of the target instance, comparing the row version number of the target instance with the target row version number, and executing write operation in the MySQL to be written by using the target instance when the row version number of the target instance is the same as the target row version number, so that the deadlock problem in the multi-active instance execution process is solved, and the MySQL database can be ensured to write data normally.
Drawings
FIG. 1 is a flow chart of the preferred embodiment of the MySQL write method based on multi-live example of the present invention.
FIG. 2 is a functional block diagram of a preferred embodiment of the MySQL write apparatus based on multiple live examples according to the invention.
FIG. 3 is a structural diagram of a computer device implementing the preferred embodiment of the MySQL write method based on multiple live instances according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
FIG. 1 is a flow chart of the MySQL write method based on multi-live example according to the preferred embodiment of the invention. The order of the steps in the flow chart may be changed and some steps may be omitted according to different needs.
The MySQL writing method based on multiple active instances is applied to one or more computer devices, which are devices capable of automatically performing numerical calculation and/or information processing according to preset or stored instructions, and the hardware thereof includes, but is not limited to, a microprocessor, an Application Specific Integrated Circuit (ASIC), a Programmable Gate Array (FPGA), a Digital Signal Processor (DSP), an embedded device, and the like.
The computer device may be any electronic product capable of performing human-computer interaction with a user, for example, a Personal computer, a tablet computer, a smart phone, a Personal Digital Assistant (PDA), a game machine, an interactive web Television (IPTV), an intelligent wearable device, and the like.
The computer device may also include a network device and/or a user device. The network device includes, but is not limited to, a single network server, a server group consisting of a plurality of network servers, or a Cloud Computing (Cloud Computing) based Cloud consisting of a large number of hosts or network servers.
The Network in which the computer device is located includes, but is not limited to, the internet, a wide area Network, a metropolitan area Network, a local area Network, a Virtual Private Network (VPN), and the like.
S10, creating a database table to be written in MySQL, wherein the database table comprises a row identifier and a row version number.
For example: an excel table may be created, where a row identifier and a row version number are stored in the excel table.
In this embodiment, the database table is equivalent to an authentication table, and is used for authenticating an instance to determine whether the instance has the right to perform the write operation on the MySQL to be written, and the write operation can be performed only by the instance passing the authentication, so that multiple instances are prevented from being written at the same time, and the deadlock phenomenon is avoided.
S11, obtaining the multi-live example composed of at least one example, and obtaining the target line identification and the target line version number.
In at least one embodiment of the invention, each instance of the multi-live instance has the same execution parameters.
Wherein the execution parameters include, but are not limited to, one or more of the following: working mode and working content.
In this embodiment, the target row identifier and the target row version number refer to a row identifier and a row version number corresponding to a row lock to be contended, and therefore, the contended row lock can be located through the target row identifier and the target row version number.
S12, connecting to the MySQL to be written, selecting the row lock with the target row identification and the target row version number from the database table as an initial row lock, and using the multi-active instance to contend for the initial row lock.
For example: a program statement "select version from tb where id = 0 for update" may be constructed using the target line identification and the target line version number to contend for a line lock.
Wherein tb represents the database table, id represents the target line identifier, and version represents the target line version number.
S13, when detecting that the initial row lock is robbed, resetting the target row version number, and releasing the initial row lock by using the example of the robbed initial row lock to obtain the target row lock.
In this embodiment, the resetting the target row version number includes:
and resetting the target row version number to a preset numerical value.
Wherein, the preset value may be 0.
It should be noted that, as the system runs, the row version numbers in the database table are gradually accumulated, and the row version numbers of the multi-live instances are equivalent to being always chased, so that when the row version numbers in the database table are successfully matched, a write operation is performed on the database table.
Therefore, when the row version number of the multi-live instance is added from 0, in order to ensure that the row version number of the instance can be quickly matched with the target row version number, that is, the multi-live instance can quickly catch up with the target row version number, and to avoid that the target row version number is difficult to match due to being added to a higher value in the running process, the present embodiment resets the target row version number when detecting that the initial row lock is preempted.
Further, in this embodiment, the instance that robs the original row lock is used to release the original row lock, so that the original row lock is in a state that can be used, and the multi-active instance can have control over the original row lock.
S14, the multi-live example is used for contending the target row lock, and the example contended to the target row lock is determined as the target example.
In at least one embodiment of the present invention, the instance robbed to the target row lock is the target instance, and as long as the authentication is passed, the instance will be given control over the target row lock.
In at least one embodiment of the invention, when the multi-live instance is utilized to contend for the target row lock, the method further comprises:
determining an instance of the multi-live instance that does not rob the target row lock as a candidate instance;
controlling the candidate instance to wait for a preset time;
and after the preset time length, continuously contending for the target row lock by using the candidate examples.
The preset time length can be configured by self-definition, such as 1 second.
Through the implementation mode, the instance without the robbing of the row lock continues to be robbed after sleeping for a period of time, and the influence on the system operation when the robbed instance cannot work normally can be effectively prevented.
S15, obtaining the row version number of the target example, and comparing the row version number of the target example with the target row version number.
In at least one embodiment of the present invention, by comparing the row version number of the target instance with the target row version number, authentication of the target instance can be achieved to determine whether the target instance really has write permission.
S16, when the row version number of the target instance is the same as the target row version number, executing write operation in the MySQL to be written by using the target instance.
In at least one embodiment of the present invention, when the row version number of the target instance is the same as the target row version number, it indicates that the target instance passes authentication, that is, the target instance is a primary working instance and has a write operation on the MySQL to be written, and since only one instance executes the write operation as the primary working instance, the deadlock problem of the MySQL to be written is effectively solved.
In at least one embodiment of the invention, the method further comprises:
after the target instance is utilized to execute the writing operation in the MySQL to be written, accumulating a first numerical value on the line version number of the target instance to obtain the current line version number;
updating the target row version number in the database table to the current row version number;
and releasing the target row lock.
The first value may be configured by a user, such as: 10.
through the implementation mode, after the target instance is determined to have the write-in authority, the target instance and the target row version number in the database table can be obviously higher than the version numbers of other instances by accumulating the first numerical value, so that the other instances are difficult to catch up with the target row version number in the database table, the situation that only one instance works at the same time is further ensured, and the generation of a deadlock phenomenon is effectively avoided.
In at least one embodiment of the invention, the method further comprises:
when the row version number of the target example is different from the target row version number, accumulating a second numerical value on the row version number of the target example;
and releasing the target row lock.
Wherein the second value can be configured by self-definition, such as 1.
In the foregoing embodiment, when the row version number of the target instance is different from the target row version number, it indicates that the target instance does not pass authentication, and is not a primary working instance, and at this time, the second value is accumulated on the row version number of the target instance, so that the non-primary working instance can stably chase up the row lock, and further continue to operate the database.
For example: the example A robs the target row lock, but after matching, the row version number of the example A is different from the target row version number, which indicates that the example A is not the main working example of the previous round (as the main working example of the previous round is the example B), but in order to enable the same example to work preferentially, so as to avoid the repeated execution of the work, therefore, the example A releases the target row lock, so that the main working example of the previous round can have a chance to continuously contend for the target row lock, and further work continuously, so as to effectively avoid the repeated work, and meanwhile, the row version number of the example A is added by 1, so that the example A can stably pursue the target row lock.
In at least one embodiment of the invention, the method further comprises:
and when the target instance is detected to be down, the candidate instance is utilized to contend for the target row lock.
In the above embodiment, because the target instance is down, at this time, in order to ensure that the system can normally operate, the candidate instance is used to contend for the target row lock, so that other instances in the multi-active instance are used to replace the target instance to continue working, and the normal operation of the system is prevented from being influenced.
It can be seen from the above technical solutions that the present invention can create a database table to be written in MySQL, where the database table includes a row identifier and a row version number, obtains a multi-active instance composed of at least one instance, obtains a target row identifier and a target row version number, connects to the MySQL to be written, selects a row lock with the target row identifier and the target row version number from the database table as an initial row lock, and uses the multi-active instance to contend for the initial row lock, when it is detected that the initial row lock is contended, resets the target row version number, and uses the instance that is contended for the initial row lock to release the initial row lock, to obtain a target row lock, through resetting, reduces matching time, enables the initial row lock to be used by releasing the row lock, contends for the target row lock by using the multi-active instance, and determines the instance that is contended for the target row lock as a target instance, and acquiring the row version number of the target instance, comparing the row version number of the target instance with the target row version number, and executing write operation in the MySQL to be written by using the target instance when the row version number of the target instance is the same as the target row version number, so that the deadlock problem in the multi-active instance execution process is solved, and the MySQL database can be ensured to write data normally.
Fig. 2 is a functional block diagram of a preferred embodiment of the MySQL writing apparatus based on multiple live instances according to the present invention. The MySQL writing device 11 based on multiple live instances comprises a creating unit 110, an acquiring unit 111, a contending unit 112, a releasing unit 113, a comparing unit 114 and an executing unit 115. The module/unit referred to in the present invention refers to a series of computer program segments that can be executed by the processor 13 and that can perform a fixed function, and that are stored in the memory 12. In the present embodiment, the functions of the modules/units will be described in detail in the following embodiments.
The creating unit 110 creates a database table to be written in MySQL, where the database table includes a row identifier and a row version number.
For example: an excel table may be created, where a row identifier and a row version number are stored in the excel table.
In this embodiment, the database table is equivalent to an authentication table, and is used for authenticating an instance to determine whether the instance has the right to perform the write operation on the MySQL to be written, and the write operation can be performed only by the instance passing the authentication, so that multiple instances are prevented from being written at the same time, and the deadlock phenomenon is avoided.
The obtaining unit 111 obtains a multi-live instance composed of at least one instance, and obtains a target row identification and a target row version number.
In at least one embodiment of the invention, each instance of the multi-live instance has the same execution parameters.
Wherein the execution parameters include, but are not limited to, one or more of the following: working mode and working content.
In this embodiment, the target row identifier and the target row version number refer to a row identifier and a row version number corresponding to a row lock to be contended, and therefore, the contended row lock can be located through the target row identifier and the target row version number.
The contending unit 112 is connected to the MySQL to be written, selects a row lock with the target row identifier and the target row version number from the database table as an initial row lock, and contends for the initial row lock by using the multi-active instance.
For example: a program statement "select version from tb where id = 0 for update" may be constructed using the target line identification and the target line version number to contend for a line lock.
Wherein tb represents the database table, id represents the target line identifier, and version represents the target line version number.
When detecting that the initial row lock is robed, the releasing unit 113 resets the target row version number, and releases the initial row lock by using the example of the initial row lock robed, so as to obtain the target row lock.
In this embodiment, the resetting the target row version number includes:
and resetting the target row version number to a preset numerical value.
Wherein, the preset value may be 0.
It should be noted that, as the system runs, the row version numbers in the database table are gradually accumulated, and the row version numbers of the multi-live instances are equivalent to being always chased, so that when the row version numbers in the database table are successfully matched, a write operation is performed on the database table.
Therefore, when the row version number of the multi-live instance is added from 0, in order to ensure that the row version number of the instance can be quickly matched with the target row version number, that is, the multi-live instance can quickly catch up with the target row version number, and to avoid that the target row version number is difficult to match due to being added to a higher value in the running process, the present embodiment resets the target row version number when detecting that the initial row lock is preempted.
Further, in this embodiment, the instance that robs the original row lock is used to release the original row lock, so that the original row lock is in a state that can be used, and the multi-active instance can have control over the original row lock.
The contending unit 112 contends for the target row lock by using the multi-live instance, and determines an instance contended for the target row lock as a target instance.
In at least one embodiment of the present invention, the instance robbed to the target row lock is the target instance, and as long as the authentication is passed, the instance will be given control over the target row lock.
In at least one embodiment of the present invention, when the multi-active instance is utilized to contend for the target row lock, an instance of the multi-active instance that is not contended for the target row lock is determined to be a candidate instance;
controlling the candidate instance to wait for a preset time;
and after the preset time length, continuously contending for the target row lock by using the candidate examples.
The preset time length can be configured by self-definition, such as 1 second.
Through the implementation mode, the instance without the robbing of the row lock continues to be robbed after sleeping for a period of time, and the influence on the system operation when the robbed instance cannot work normally can be effectively prevented.
Comparing unit 114 obtains the row version number of the target instance, and compares the row version number of the target instance with the target row version number.
In at least one embodiment of the present invention, by comparing the row version number of the target instance with the target row version number, authentication of the target instance can be achieved to determine whether the target instance really has write permission.
When the row version number of the target instance is the same as the target row version number, the execution unit 115 performs a write operation in the MySQL to be written using the target instance.
In at least one embodiment of the present invention, when the row version number of the target instance is the same as the target row version number, it indicates that the target instance passes authentication, that is, the target instance is a primary working instance and has a write operation on the MySQL to be written, and since only one instance executes the write operation as the primary working instance, the deadlock problem of the MySQL to be written is effectively solved.
In at least one embodiment of the present invention, after the target instance is used to execute the write operation in the MySQL to be written, a first numerical value is accumulated on the row version number of the target instance to obtain a current row version number;
updating the target row version number in the database table to the current row version number;
and releasing the target row lock.
The first value may be configured by a user, such as: 10.
through the implementation mode, after the target instance is determined to have the write-in authority, the target instance and the target row version number in the database table can be obviously higher than the version numbers of other instances by accumulating the first numerical value, so that the other instances are difficult to catch up with the target row version number in the database table, the situation that only one instance works at the same time is further ensured, and the generation of a deadlock phenomenon is effectively avoided.
In at least one embodiment of the present invention, when the row version number of the target instance is not the same as the target row version number, a second value is accumulated on the row version number of the target instance;
and releasing the target row lock.
Wherein the second value can be configured by self-definition, such as 1.
In the foregoing embodiment, when the row version number of the target instance is different from the target row version number, it indicates that the target instance does not pass authentication, and is not a primary working instance, and at this time, the second value is accumulated on the row version number of the target instance, so that the non-primary working instance can stably chase up the row lock, and further continue to operate the database.
For example: the example A robs the target row lock, but after matching, the row version number of the example A is different from the target row version number, which indicates that the example A is not the main working example of the previous round (as the main working example of the previous round is the example B), but in order to enable the same example to work preferentially, so as to avoid the repeated execution of the work, therefore, the example A releases the target row lock, so that the main working example of the previous round can have a chance to continuously contend for the target row lock, and further work continuously, so as to effectively avoid the repeated work, and meanwhile, the row version number of the example A is added by 1, so that the example A can stably pursue the target row lock.
In at least one embodiment of the invention, when the target instance is detected to be down, the candidate instance is utilized to contend for the target row lock.
In the above embodiment, because the target instance is down, at this time, in order to ensure that the system can normally operate, the candidate instance is used to contend for the target row lock, so that other instances in the multi-active instance are used to replace the target instance to continue working, and the normal operation of the system is prevented from being influenced.
It can be seen from the above technical solutions that the present invention can create a database table to be written in MySQL, where the database table includes a row identifier and a row version number, obtains a multi-active instance composed of at least one instance, obtains a target row identifier and a target row version number, connects to the MySQL to be written, selects a row lock with the target row identifier and the target row version number from the database table as an initial row lock, and uses the multi-active instance to contend for the initial row lock, when it is detected that the initial row lock is contended, resets the target row version number, and uses the instance that is contended for the initial row lock to release the initial row lock, to obtain a target row lock, through resetting, reduces matching time, enables the initial row lock to be used by releasing the row lock, contends for the target row lock by using the multi-active instance, and determines the instance that is contended for the target row lock as a target instance, and acquiring the row version number of the target instance, comparing the row version number of the target instance with the target row version number, and executing write operation in the MySQL to be written by using the target instance when the row version number of the target instance is the same as the target row version number, so that the deadlock problem in the multi-active instance execution process is solved, and the MySQL database can be ensured to write data normally.
Fig. 3 is a schematic structural diagram of a computer device according to a preferred embodiment of the present invention, which implements a MySQL writing method based on multiple live instances.
The computer device 1 may comprise a memory 12, a processor 13 and a bus, and may further comprise a computer program, such as a multi-live instance based MySQL writer, stored in the memory 12 and executable on the processor 13.
It will be understood by those skilled in the art that the schematic diagram is merely an example of the computer device 1, and does not constitute a limitation to the computer device 1, the computer device 1 may have a bus-type structure or a star-shaped structure, the computer device 1 may further include more or less other hardware or software than those shown, or different component arrangements, for example, the computer device 1 may further include an input and output device, a network access device, etc.
It should be noted that the computer device 1 is only an example, and other electronic products that are currently available or may come into existence in the future, such as electronic products that can be adapted to the present invention, should also be included in the scope of the present invention, and are included herein by reference.
The memory 12 includes at least one type of readable storage medium, which includes flash memory, removable hard disks, multimedia cards, card-type memory (e.g., SD or DX memory, etc.), magnetic memory, magnetic disks, optical disks, etc. The memory 12 may in some embodiments be an internal storage unit of the computer device 1, for example a removable hard disk of the computer device 1. The memory 12 may also be an external storage device of the computer device 1 in other embodiments, such as a plug-in removable hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), etc. provided on the computer device 1. Further, the memory 12 may also include both an internal storage unit and an external storage device of the computer device 1. The memory 12 can be used not only for storing application software installed in the computer device 1 and various types of data, such as code of MySQL writer based on multi-live instances, etc., but also for temporarily storing data that has been output or is to be output.
The processor 13 may be composed of an integrated circuit in some embodiments, for example, a single packaged integrated circuit, or may be composed of a plurality of integrated circuits packaged with the same or different functions, including one or more Central Processing Units (CPUs), microprocessors, digital Processing chips, graphics processors, and combinations of various control chips. The processor 13 is a Control Unit (Control Unit) of the computer device 1, connects various components of the entire computer device 1 by using various interfaces and lines, and executes various functions and processes data of the computer device 1 by running or executing programs or modules (for example, executing MySQL writer program based on multi-live instances, etc.) stored in the memory 12 and calling data stored in the memory 12.
The processor 13 executes the operating system of the computer device 1 and various installed application programs. The processor 13 executes the application program to implement the steps in each of the above embodiments of the multi-live instance based MySQL writing method, such as the steps shown in fig. 1.
Illustratively, the computer program may be divided into one or more modules/units, which are stored in the memory 12 and executed by the processor 13 to accomplish the present invention. The one or more modules/units may be a series of computer readable instruction segments capable of performing certain functions, which are used to describe the execution of the computer program in the computer device 1. For example, the computer program may be divided into a creation unit 110, an acquisition unit 111, a contention unit 112, a release unit 113, a comparison unit 114, an execution unit 115.
The integrated unit implemented in the form of a software functional module may be stored in a computer-readable storage medium. The software functional module is stored in a storage medium and includes several instructions to enable a computer device (which may be a personal computer, a computer device, or a network device) or a processor (processor) to execute a part of the MySQL writing method based on multiple live instances according to the embodiments of the present invention.
The integrated modules/units of the computer device 1 may be stored in a computer-readable storage medium if they are implemented in the form of software functional units and sold or used as separate products. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented.
Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U-disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), random-access Memory, or the like.
Further, the computer-readable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created according to the use of the blockchain node, and the like.
The block chain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, a consensus mechanism, an encryption algorithm and the like. A block chain (Blockchain), which is essentially a decentralized database, is a series of data blocks associated by using a cryptographic method, and each data block contains information of a batch of network transactions, so as to verify the validity (anti-counterfeiting) of the information and generate a next block. The blockchain may include a blockchain underlying platform, a platform product service layer, an application service layer, and the like.
The bus may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one line is shown in FIG. 3, but this does not mean only one bus or one type of bus. The bus is arranged to enable connection communication between the memory 12 and at least one processor 13 or the like.
Although not shown, the computer device 1 may further include a power supply (such as a battery) for supplying power to each component, and preferably, the power supply may be logically connected to the at least one processor 13 through a power management device, so that functions of charge management, discharge management, power consumption management and the like are realized through the power management device. The power supply may also include any component of one or more dc or ac power sources, recharging devices, power failure detection circuitry, power converters or inverters, power status indicators, and the like. The computer device 1 may further include various sensors, a bluetooth module, a Wi-Fi module, and the like, which are not described herein again.
Further, the computer device 1 may further include a network interface, and optionally, the network interface may include a wired interface and/or a wireless interface (such as a WI-FI interface, a bluetooth interface, etc.), which are generally used for establishing a communication connection between the computer device 1 and other computer devices.
Optionally, the computer device 1 may further comprise a user interface, which may be a Display (Display), an input unit, such as a Keyboard (Keyboard), and optionally a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch device, or the like. The display, which may also be referred to as a display screen or display unit, is suitable for displaying information processed in the computer device 1 and for displaying a visualized user interface.
It is to be understood that the described embodiments are for purposes of illustration only and that the scope of the appended claims is not limited to such structures.
Fig. 3 shows only the computer device 1 with the components 12-13, and it will be understood by a person skilled in the art that the structure shown in fig. 3 does not constitute a limitation of the computer device 1 and may comprise fewer or more components than shown, or a combination of certain components, or a different arrangement of components.
With reference to fig. 1, the memory 12 of the computer device 1 stores a plurality of instructions to implement a multi-live instance based MySQL writing method, and the processor 13 executes the plurality of instructions to implement:
creating a database table to be written in MySQL, wherein the database table comprises a row identifier and a row version number;
acquiring a multi-live example consisting of at least one example, and acquiring a target row identifier and a target row version number;
connecting to the MySQL to be written, selecting a row lock with the target row identification and the target row version number from the database table as an initial row lock, and using the multi-active instance to contend for the initial row lock;
when the initial row lock is detected to be robbed, resetting the target row version number, and releasing the initial row lock by using the example of the robbed initial row lock to obtain a target row lock;
the multi-live example is used for contending the target row lock, and an example which is contended to the target row lock is determined as a target example;
acquiring the row version number of the target instance, and comparing the row version number of the target instance with the target row version number;
and when the row version number of the target instance is the same as the target row version number, executing write operation in the MySQL to be written by using the target instance.
Specifically, the processor 13 may refer to the description of the relevant steps in the embodiment corresponding to fig. 1 for a specific implementation method of the instruction, which is not described herein again.
In the embodiments provided in the present invention, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is only one logical functional division, and other divisions may be realized in practice.
The modules described as separate parts may or may not be physically separate, and parts displayed as modules may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment.
In addition, functional modules in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional module.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential attributes thereof.
The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the present invention may also be implemented by one unit or means through software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.
Finally, it should be noted that the above embodiments are only for illustrating the technical solutions of the present invention and not for limiting, and although the present invention is described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications or equivalent substitutions may be made on the technical solutions of the present invention without departing from the spirit and scope of the technical solutions of the present invention.
Claims (10)
1. A MySQL writing method based on multi-live instances is characterized by comprising the following steps:
creating a database table to be written in MySQL, wherein the database table comprises a row identifier and a row version number;
acquiring a multi-live example consisting of at least one example, and acquiring a target row identifier and a target row version number;
connecting to the MySQL to be written, selecting a row lock with the target row identification and the target row version number from the database table as an initial row lock, and using the multi-active instance to contend for the initial row lock;
when the initial row lock is detected to be robbed, resetting the target row version number, and releasing the initial row lock by using the example of the robbed initial row lock to obtain a target row lock;
the multi-live example is used for contending the target row lock, and an example which is contended to the target row lock is determined as a target example;
acquiring the row version number of the target instance, and comparing the row version number of the target instance with the target row version number;
and when the row version number of the target instance is the same as the target row version number, executing write operation in the MySQL to be written by using the target instance.
2. The multi-live instance-based MySQL write method of claim 1, in which each of the multi-live instances has the same execution parameters.
3. The multi-live instance based MySQL write method of claim 1, wherein when using the multi-live instance to contend for the target row lock, the method further comprises:
determining an instance of the multi-live instance that does not rob the target row lock as a candidate instance;
controlling the candidate instance to wait for a preset time;
and after the preset time length, continuously contending for the target row lock by using the candidate examples.
4. The multi-live instance based MySQL write method of claim 1, further comprising:
after the target instance is utilized to execute the writing operation in the MySQL to be written, accumulating a first numerical value on the line version number of the target instance to obtain the current line version number;
updating the target row version number in the database table to the current row version number;
and releasing the target row lock.
5. The multi-live instance based MySQL write method of claim 1, further comprising:
when the row version number of the target example is different from the target row version number, accumulating a second numerical value on the row version number of the target example;
and releasing the target row lock.
6. The multi-live instance based MySQL write method of claim 3, further comprising:
and when the target instance is detected to be down, the candidate instance is utilized to contend for the target row lock.
7. A multi-live instance based MySQL writing apparatus, characterized in that the multi-live instance based MySQL writing apparatus comprises:
the system comprises a creating unit, a storing unit and a writing unit, wherein the creating unit is used for creating a database table to be written in MySQL, and the database table comprises a row identifier and a row version number;
the device comprises an acquisition unit, a processing unit and a processing unit, wherein the acquisition unit is used for acquiring a multi-live example consisting of at least one example, and acquiring a target line identifier and a target line version number;
the contending and robbing unit is used for connecting to the MySQL to be written, selecting a row lock with the target row identifier and the target row version number from the database table as an initial row lock, and contending and robbing the initial row lock by using the multi-live example;
the releasing unit is used for resetting the target row version number when the initial row lock is detected to be robbed, and releasing the initial row lock by using the example of the robbed initial row lock to obtain a target row lock;
the contention unit is further configured to contend the target row lock by using the multi-live example, and determine an example of the target row lock as a target example;
the comparison unit is used for acquiring the row version number of the target example and comparing the row version number of the target example with the target row version number;
and the execution unit is used for executing the writing operation in the MySQL to be written by using the target instance when the row version number of the target instance is the same as the target row version number.
8. The multi-live instance-based MySQL writing apparatus of claim 7, in which each of the multi-live instances has the same execution parameters.
9. A computer device, characterized in that the computer device comprises:
a memory storing at least one instruction; and
a processor executing instructions stored in the memory to implement the multi-live instance based MySQL write method of any of claims 1-6.
10. A computer-readable storage medium characterized by: the computer-readable storage medium having stored therein at least one instruction for execution by a processor in a computer device to implement the multi-live instance based MySQL write method according to any of claims 1 to 6.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110850708.6A CN113297228B (en) | 2021-07-27 | 2021-07-27 | MySQL writing method, device, equipment and medium based on multiple live instances |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110850708.6A CN113297228B (en) | 2021-07-27 | 2021-07-27 | MySQL writing method, device, equipment and medium based on multiple live instances |
Publications (2)
Publication Number | Publication Date |
---|---|
CN113297228A CN113297228A (en) | 2021-08-24 |
CN113297228B true CN113297228B (en) | 2021-10-08 |
Family
ID=77331321
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110850708.6A Active CN113297228B (en) | 2021-07-27 | 2021-07-27 | MySQL writing method, device, equipment and medium based on multiple live instances |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN113297228B (en) |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN108132831A (en) * | 2016-12-01 | 2018-06-08 | 阿里巴巴集团控股有限公司 | The processing method and processing unit of task |
CN109923534A (en) * | 2016-11-04 | 2019-06-21 | 易享信息技术有限公司 | To the Multi version concurrency control with the data-base recording for not submitting affairs |
US10430389B1 (en) * | 2016-09-30 | 2019-10-01 | EMC IP Holding Company LLC | Deadlock-free locking for consistent and concurrent server-side file operations in file systems |
CN112015713A (en) * | 2019-05-30 | 2020-12-01 | 阿里巴巴集团控股有限公司 | Database task processing method and device, electronic equipment and readable medium |
Family Cites Families (1)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US9037558B2 (en) * | 2012-05-25 | 2015-05-19 | International Business Machines Corporation | Management of long-running locks and transactions on database tables |
-
2021
- 2021-07-27 CN CN202110850708.6A patent/CN113297228B/en active Active
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10430389B1 (en) * | 2016-09-30 | 2019-10-01 | EMC IP Holding Company LLC | Deadlock-free locking for consistent and concurrent server-side file operations in file systems |
CN109923534A (en) * | 2016-11-04 | 2019-06-21 | 易享信息技术有限公司 | To the Multi version concurrency control with the data-base recording for not submitting affairs |
CN108132831A (en) * | 2016-12-01 | 2018-06-08 | 阿里巴巴集团控股有限公司 | The processing method and processing unit of task |
CN112015713A (en) * | 2019-05-30 | 2020-12-01 | 阿里巴巴集团控股有限公司 | Database task processing method and device, electronic equipment and readable medium |
Non-Patent Citations (2)
Title |
---|
OceanBase内存事务引擎;李 凯;《华东师范大学学报(自然科学版)》;20140930(第5期);第149-163页 * |
试析 MySQL 数据库性能的调优;王晓华;《电脑编程技巧与维护》;20161231;第48、82页 * |
Also Published As
Publication number | Publication date |
---|---|
CN113297228A (en) | 2021-08-24 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112559535B (en) | Multithreading-based asynchronous task processing method, device, equipment and medium | |
WO2021114877A1 (en) | Missing-number detection method, apparatus, electronic device, and storage medium | |
CN112396547B (en) | Course recommendation method, device, equipment and medium based on unsupervised learning | |
CN111767268A (en) | Database table partitioning method and device, electronic equipment and storage medium | |
CN111950621A (en) | Target data detection method, device, equipment and medium based on artificial intelligence | |
CN111949708A (en) | Multi-task prediction method, device, equipment and medium based on time sequence feature extraction | |
CN112015663A (en) | Test data recording method, device, equipment and medium | |
CN115118738B (en) | Disaster recovery method, device, equipment and medium based on RDMA | |
CN111858604B (en) | Data storage method and device, electronic equipment and storage medium | |
CN113240351A (en) | Business data consistency checking method and device, electronic equipment and medium | |
CN111563129B (en) | Distributed storage area block chain account book method | |
CN112700261A (en) | Suspicious community-based brushing behavior detection method, device, equipment and medium | |
CN113297228B (en) | MySQL writing method, device, equipment and medium based on multiple live instances | |
CN114675976B (en) | GPU (graphics processing Unit) sharing method, device, equipment and medium based on kubernets | |
CN112257078B (en) | Block chain encryption and decryption service security trusted system based on TEE technology | |
CN114626103A (en) | Data consistency comparison method, device, equipment and medium | |
CN113076069A (en) | Double-cache method and device, electronic equipment and computer readable storage medium | |
CN113342867A (en) | Data distribution and management method and device, electronic equipment and readable storage medium | |
CN114201466A (en) | Method, device and equipment for preventing cache breakdown and readable storage medium | |
CN112446781A (en) | Wind control data generation method, device, equipment and computer readable storage medium | |
CN110879743A (en) | Task elimination method, device, system and medium based on edge computing environment | |
CN113687834B (en) | Distributed system node deployment method, device, equipment and medium | |
CN113360267B (en) | Method, device, equipment and medium for task execution based on time axis | |
CN110716806A (en) | Edge node computing capacity determination method, electronic device, system and medium | |
CN114860349B (en) | Data loading method, device, equipment and medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant | ||
CP01 | Change in the name or title of a patent holder |
Address after: Room 2301, building 5, Shenzhen new generation industrial park, 136 Zhongkang Road, Meidu community, Meilin street, Futian District, Shenzhen, Guangdong 518000 Patentee after: Shenzhen Huarui Distributed Technology Co.,Ltd. Address before: Room 2301, building 5, Shenzhen new generation industrial park, 136 Zhongkang Road, Meidu community, Meilin street, Futian District, Shenzhen, Guangdong 518000 Patentee before: SHENZHEN ARCHFORCE FINANCIAL TECHNOLOGY Co.,Ltd. |
|
CP01 | Change in the name or title of a patent holder |