CN114547019A - Database reading and writing method, device, server and medium - Google Patents

Database reading and writing method, device, server and medium Download PDF

Info

Publication number
CN114547019A
CN114547019A CN202011332493.0A CN202011332493A CN114547019A CN 114547019 A CN114547019 A CN 114547019A CN 202011332493 A CN202011332493 A CN 202011332493A CN 114547019 A CN114547019 A CN 114547019A
Authority
CN
China
Prior art keywords
server
data
data record
reading
data partition
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.)
Pending
Application number
CN202011332493.0A
Other languages
Chinese (zh)
Inventor
潘洪安
刘佩增
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
NetsUnion Clearing Corp
Original Assignee
NetsUnion Clearing Corp
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by NetsUnion Clearing Corp filed Critical NetsUnion Clearing Corp
Priority to CN202011332493.0A priority Critical patent/CN114547019A/en
Publication of CN114547019A publication Critical patent/CN114547019A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/278Data partitioning, e.g. horizontal or vertical partitioning

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application provides a database reading and writing method, a device, a server and a medium, wherein the method is applied to a first server in a plurality of servers for execution, the plurality of servers further comprise at least one second server different from the first server, target application programs are deployed in the first server and the second server, and the method comprises the following steps: and monitoring the write operation of the target application program on the target database table, if the data record pointed by the write operation is stored in a first data partition of the target database table, executing the write operation on the data record, and if the data record pointed by the write operation is stored in a second data partition of the target database table, refusing to execute the write operation. Therefore, the first server can acquire the data records stored by other servers, and the fact that each server has the read-write operation capacity is achieved.

Description

Database reading and writing method, device, server and medium
Technical Field
The present application relates to the field of database technologies, and in particular, to a database read-write method, apparatus, server, and medium.
Background
The current multi-server application architecture usually adopts a one-master multi-slave mode, namely only one server has read-write capability, other servers synchronize data from a master server, and the applications of other servers can only read data and cannot write data.
The existing master-slave architecture scheme aims to ensure that the multiple servers achieve final consistency in data writing. However, when the database of the writable server fails, another server becomes the writable server, and the master-slave relationship topology of the database changes, so that each application side depending on the database needs to sense which server is writable and which server is readable. It can be seen that strong coupling relationships exist between databases of multiple servers, and between applications and databases, which are not favorable for read-write operations between databases.
Disclosure of Invention
The present application is directed to solving, at least to some extent, one of the technical problems in the related art.
Therefore, the application provides a database read-write method to realize that each server in a plurality of servers has read-write operation capability.
An embodiment of a first aspect of the present application provides a database reading and writing method, where the method is performed by a first server in a plurality of servers, where the plurality of servers further include at least one second server different from the first server, and a target application is deployed in each of the first server and the second server, and the method includes:
monitoring the write operation of the target application program to a target database table;
if the data record pointed by the write operation is stored in the first data partition of the target database table, executing the write operation on the data record; wherein the first data partition corresponds to the first server;
if the data record pointed by the write operation is stored in a second data partition of the target database table, refusing to execute the write operation; wherein the second data partition corresponds to the second server.
Optionally, before monitoring the write operation of the target application program to the target database table, the method further includes:
periodically reading a first data record stored locally at the first server and obtaining a second data record from the second server;
writing the first data record into a first data partition corresponding to the first server in the target database table according to a preset data partition rule, and writing the second data record into a second data partition corresponding to the second server in the target database table; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
Optionally, before the monitoring the write operation of the target application program to the target database table, the method further includes:
monitoring the reading operation of the target application program on the target database table;
if the data record pointed by the read operation is stored in a first data partition of the target database table, locally reading the data record pointed by the read operation from the first server;
if the data record pointed by the reading operation is stored in a second data partition of the target database table, acquiring the data record pointed by the reading operation from a second server corresponding to the second data partition according to a preset data partition rule; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
Optionally, the periodically reading a first data record stored locally at the first server and obtaining a second data record from the second server, further includes:
synchronously starting the target application program with each second server;
reading a first data record locally stored in the first server when the target application program is monitored to be started;
sending a first acquisition request to the second server to acquire a second data record stored by the second server;
storing the first data record and the second data record in a cache of the first server.
Optionally, after storing the first data record and the second data record in the cache of the first server, the method further includes:
receiving a second acquisition request from a second server;
sending the requested first data record or the second data record to the second server.
Optionally, when a plurality of second servers are included in the plurality of servers, the sending a first obtaining request to the second server to obtain a second data record stored by the second server includes:
sequentially sending the first acquisition requests to the plurality of second servers in a set sequence;
the first acquisition request comprises an identifier of a second data record which fails to be acquired and/or an identifier of a second data record to be acquired.
Optionally, the obtaining, from a second server corresponding to the second data partition, the data record pointed to by the read operation includes:
determining a corresponding second server according to the second data partition;
sending an acquisition request to a second server corresponding to the second data partition according to the reading operation;
receiving an acquisition response sent by a second server corresponding to the second data partition;
and responding to the read operation according to the data record carried in the acquisition response.
Optionally, after the monitoring the write operation of the target application program to the target database table, the method further includes:
determining the sequence number of the data record pointed by the write operation;
reading configuration information, wherein the configuration information is used for representing a sequence number range configured for each data partition in the target database table; if the sequence number belongs to the sequence number range of the first data partition recorded by the configuration information, determining that the data record pointed by the write operation is stored in the first data partition;
and if the sequence number does not belong to the range of the sequence number of the first data partition recorded by the configuration information, determining that the data record pointed by the write operation is stored in the second data partition.
Optionally, the method further comprises:
and when the servers are online or offline, updating the configuration information.
Optionally, the sequence number range configured for the ith data partition in the target database table is [ (i-1) × N, i × N ], where i is a positive integer whose value is less than or equal to the total number of data partitions, and N is determined according to the total number of data records contained in the target database table.
According to the database reading and writing method, the writing operation of a target application program on a target database table is monitored, and if the data record pointed by the writing operation is stored in a first data partition of the target database table, the writing operation is executed on the data record; and if the data record pointed by the write operation is stored in the second data partition of the target database table, refusing to execute the write operation. Therefore, the first server can read the locally stored database table, can execute writing operation on records in the locally stored database table, and can acquire the database tables stored by other servers, so that each server in the plurality of servers has the reading and writing operation capability.
An embodiment of a second aspect of the present application provides a database read-write apparatus, which is applied to a first server in a plurality of servers for execution, where the plurality of servers further include at least one second server different from the first server, and target applications are deployed in both the first server and the second server, and the apparatus includes:
the monitoring module is used for monitoring the write operation of the target application program to the target database table;
the first processing module is used for executing the write operation on the data record if the data record pointed by the write operation is stored in a first data partition of the target database table; wherein the first data partition corresponds to the first server;
the second processing module is used for refusing to execute the write operation if the data record pointed by the write operation is stored in a second data partition of the target database table; wherein the second data partition corresponds to the second server.
The database reading and writing device of the embodiment of the application monitors the writing operation of a target application program on a target database table, and if the data record pointed by the writing operation is stored in a first data partition of the target database table, the writing operation is executed on the data record; and if the data record pointed by the write operation is stored in the second data partition, refusing to execute the write operation. Therefore, the first server can read the locally stored database table, can execute writing operation on records in the locally stored database table, and can acquire the database tables stored by other servers, so that each server in the plurality of servers has the reading and writing operation capability.
An embodiment of a third aspect of the present application provides a server, including a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor executes the computer program to implement the database reading and writing method according to the embodiment of the first aspect.
A fourth aspect of the present application provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the database reading and writing method described in the first aspect of the present application.
Additional aspects and advantages of the present application will be set forth in part in the description which follows and, in part, will be obvious from the description, or may be learned by practice of the present application.
Drawings
The foregoing and/or additional aspects and advantages of the present application will become apparent and readily appreciated from the following description of the embodiments, taken in conjunction with the accompanying drawings of which:
fig. 1 is a schematic flowchart of a database read-write method according to an embodiment of the present disclosure;
fig. 2 is a schematic flowchart of another database reading and writing method according to an embodiment of the present disclosure;
fig. 3 is a schematic flowchart of another database reading and writing method according to an embodiment of the present application;
fig. 4 is a schematic flowchart of another database reading and writing method according to an embodiment of the present disclosure;
FIG. 5 is a schematic flowchart illustrating a process for determining a storage location of a record to be written according to an embodiment of the present application;
fig. 6 is an exemplary diagram of a database read/write method according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a database read/write apparatus according to an embodiment of the present disclosure;
fig. 8 is a schematic structural diagram of a server according to an embodiment of the present application.
Detailed Description
Reference will now be made in detail to embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are exemplary and intended to be used for explaining the present application and should not be construed as limiting the present application.
A database read/write method, apparatus, server, and medium according to embodiments of the present application are described below with reference to the accompanying drawings.
Fig. 1 is a schematic flowchart of a database read-write method according to an embodiment of the present disclosure.
As shown in fig. 1, the database read-write method is performed by a first server in a plurality of servers, the plurality of servers further includes at least one second server different from the first server, and a target application is deployed in each of the first server and the second server, and the database read-write method may include the following steps:
step 101, monitoring the write operation of the target application program to the target database table.
The write operation refers to an operation of writing data performed on a data record of the target database table. For example, the write operation may be to modify the age of the user in the target database table.
In the embodiment of the application, the first server executes the target application program to perform data processing on the target database table, and can monitor the write operation of the target application program on the target database table in real time to determine whether to execute the write operation according to the record storage position in the target database table.
And 103, if the data record pointed by the write operation is stored in the first data partition of the target database table, executing the write operation on the data record.
And 105, if the data record pointed by the write operation is stored in the second data partition of the target database table, refusing to execute the write operation.
It will be appreciated that each server can only write to records stored in the data partition stored locally and cannot write to records stored in data partitions stored by other servers.
It can be understood that, after the first server monitors the write operation of the target application program to the target database table, if it is determined that the data record pointed by the write operation is stored in the first data partition of the target database table, the write operation may be performed on the data record.
It should be noted that the first data partition of the target database table corresponds to the first server.
However, after the first server monitors the write operation of the target application program to the target database table, it is determined that the data record pointed by the write operation is stored in the second data partition of the target database table, and then the first server refuses to execute the write operation. Wherein the second data partition corresponds to a second server.
Because the first data partition corresponds to the first server and the second data partition corresponds to the second server, when the first server executes the database reading and writing method and determines that the data record pointed by the write operation is stored in the second data partition of the target database table, the write operation is refused to be executed.
For example, if the first server determines that the data record pointed to by the write operation is stored in the first data partition a1 after monitoring the write operation performed by the target application on the data record in the target database table, perform a corresponding write operation on the data record in the first data partition a 1; if it is determined that the data record to which the write operation is directed is stored in the second data partition B1 or B2, the write operation is denied. According to the database reading and writing method, the writing operation of a target application program on a target database table is monitored, and if the data record pointed by the writing operation is stored in a first data partition, the writing operation is executed on the data record; and if the data record pointed by the write operation is stored in the second data partition, refusing to execute the write operation. Therefore, the first server can acquire the data stored by the other servers, and each server in the multiple servers has the read-write operation capability.
As a possible situation of the embodiment of the application, the first server may also periodically read a first data record locally stored by the first server, and obtain a second data record from the second server, so as to write the first data record and the second data record into corresponding data partitions in the target database table, respectively, so that when the first server monitors a read operation of the target application program on the target data table, the first server may determine the target server according to the data partition in which the data record pointed by the read operation is stored in the target database table, so as to send a data acquisition request to the target server, and acquire the data record pointed by the read operation from the corresponding data partition. For a specific implementation process, reference may be made to fig. 2, and fig. 2 is a schematic flowchart of another database reading and writing method provided in the embodiment of the present application.
As shown in fig. 2, the database reading and writing method may further include the following steps:
step 201, periodically reading a first data record stored locally at a first server, and obtaining a second data record from a second server.
The first data record refers to data stored in a database table local to the first server, and the second data record refers to data stored in a database table of the second server.
In this embodiment of the application, a target application deployed in a first server may periodically read a first data record stored in a database table local to the first server, and obtain a second data record from a database table of a second server. Therefore, the target application program can acquire the full amount of data stored in the databases of the first server and the second server, and data consistency is achieved.
Step 203, writing the first data record into a first data partition corresponding to the first server in the target database table according to a preset data partition rule, and writing the second data record into a second data partition corresponding to the second server in the target database table.
The preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
For example, a first data partition in the target database table corresponds to a first server and a second data partition corresponds to a second server.
In the embodiment of the application, after a target application deployed in a first server acquires a first data record and a second data record from the first server and a second server, according to a corresponding relation between a data partition in a target database table and each server in a plurality of servers, the first data record is written into a first data partition corresponding to the first server in the target database table, and the second data record is written into a second data partition corresponding to the second server in the target database table.
In the database reading and writing method of the embodiment of the application, a target application program periodically reads a first data record stored locally in a first server, acquires a second data record from a second server, writes the first data record into a first data partition corresponding to the first server in a target database table according to a preset data partition rule, and writes the second data record into a second data partition corresponding to the second server in the target database table. Therefore, the target application program can read the data records of each server, and data consistency is achieved.
As a possible situation of the embodiment of the present application, the target application may further perform a read operation on the target database table, determine the target server according to the data partition where the data record pointed by the read operation is stored in the target database table, send a data acquisition request to the target server, and respond to the read operation to acquire the data record pointed by the read operation from the target server. Referring to fig. 3, a specific implementation process is shown, and fig. 3 is a schematic flowchart of another database reading and writing method provided in the embodiment of the present application.
As shown in fig. 3, the database reading and writing method may further include the following steps:
step 301, monitoring the reading operation of the target application program on the target database table.
The reading operation refers to an operation of reading data performed on a data record of the target database table. For example, the read operation may be to read user information in the target database table to obtain the user information in the target database table in response to the read operation.
In the embodiment of the application, the first server executes the target application program, so that when data processing is performed on the target database table, the reading operation of the target application program on the target database table can be monitored in real time, the storage position of the data record pointed by the reading operation stored in the target database table is determined, the target server for acquiring the data record pointed by the reading operation is determined, and then the data record pointed by the reading operation is read from the target server.
Step 303, if the data record pointed to by the read operation is stored in the first data partition of the target database table, the data record pointed to by the read operation is locally read from the first server.
Step 305, if the data record pointed by the read operation is stored in the second data partition of the target database table, acquiring the data record pointed by the read operation from the second server corresponding to the second data partition according to a preset data partition rule.
The preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
In a possible case, after monitoring the read operation of the target application program on the target database table, the first server determines that the data record pointed by the read operation is stored in the first data partition in the target database table, and then reads the data record pointed by the read operation from the local database of the first server.
In another possible situation, after monitoring the read operation of the target application program on the target database table, the first server determines that the data record pointed by the read operation is stored in the second data partition of the target database table, and then determines the second server corresponding to the second data partition according to a preset data partition rule, so as to obtain the data record pointed by the read operation from the second server corresponding to the second data partition.
According to the database reading and writing method, reading operation of a target application program on a target database table is monitored, and if data records pointed by the reading operation are stored in a first data partition of the target database table, the data records pointed by the reading operation are locally read from a first server; and if the data record pointed by the reading operation is stored in a second data partition of the target database table, acquiring the data record pointed by the reading operation from a second server corresponding to the second data partition according to a preset data partition rule. Therefore, the data record pointed by the reading operation is determined to be obtained from the first server or the second server according to the storage position of the data record pointed by the reading operation of the target database, and the data obtaining efficiency is improved.
As a possible situation of the embodiment of the present application, when a plurality of servers are started, each server may first read a database table stored locally, and then obtain database tables stored by other servers, so as to store the database table stored locally in a local cache and the database tables obtained from other servers. As an example, the first server may first read a first database table locally stored by the first server, and then after acquiring a second database table stored by the second server, store the first database table and the second database table in a buffer of the first server. Fig. 4 may be referred to in a specific implementation process, and fig. 4 is a schematic flowchart of another database reading and writing method provided in the embodiment of the present application.
As shown in fig. 4, the database reading and writing method may further include the following steps:
and step 401, starting the target application program synchronously with each second server.
In the embodiment of the application, when the second server is started, the target application program can be synchronously started with each second server.
In step 403, if it is monitored that the target application program is started, a first data record locally stored in the first server is read.
In the embodiment of the application, after the first server is started, the first data record stored locally in the first server is read first, so that the capability of the first server for reading data from the first data partition is realized.
For example, the first server locally stores the first data partition a1, and after the first server is started, the data records in the first data partition a1 may be read.
Step 405, sending a first obtaining request to a second server to obtain a second data record stored by the second server.
In this embodiment of the application, when acquiring the second data record stored in the second server, the first server may send a first acquisition request to the second server, and after receiving the first acquisition request sent by the first server to acquire the second data record, the second server may send the stored second data record to the first server, so that the first server acquires the second data record stored in the second server.
As a possible case, when the plurality of servers includes a plurality of second servers, the first server may sequentially send the first acquisition request to the plurality of second servers in a set order to acquire the second data records stored by the respective second servers. The first acquisition request comprises an identifier of a second data record which fails to be acquired and/or an identifier of a second data record to be acquired.
The set sequence is determined according to the identification of the second data record with acquisition failure contained in the first acquisition request and/or the identification of the second data record to be acquired.
As an example, when a first server needs to obtain second data records stored in two second servers with numbers 1 and 2 after reading a first data record locally stored in the first server, a first obtaining request may be sent to the second servers with numbers 1 and 2 according to a storage sequence of an identifier of the second data record to be obtained, so as to obtain the second data records stored in the second servers with numbers 1 and 2.
For example, if the first server fails to obtain the second data record from the second server with the number 1 when obtaining the second data records stored in the two second servers with the numbers 1 and 2, the first obtaining request sent to the second server with the number 2 includes the identifier of the second data record stored in the second server with the number 1 that failed to obtain, and the identifier of the second data record stored in the second server with the number 2 to be obtained. Since the cache of the second server with the number 2 stores the second data record stored by the second server with the number 1, the first server can obtain the second data record stored by the second server with the number 1 and the second data record stored by the second server with the number 2 from the second server with the number 2.
Step 407, store the first data record and the second data record in the cache of the first server.
In the embodiment of the application, after the first server reads the first data record locally stored in the first server and acquires the second data record stored in the second server, the first data record and the second data record can be stored in the cache of the first server, so that the functions that the first server can read the data record stored in the server and the data records stored in other servers are realized.
Step 409, receiving a second obtaining request from the second server.
Step 411, sending the requested first data record or second data record to the second server.
In a possible scenario, after the first data record and the second data record are stored in the cache of the first server, a second obtaining request sent by the second server to obtain the first data record or the second data record stored by the first server may be received. After receiving the second acquisition request, the first server may send the requested first data record or second data record to a second server that sent the second acquisition request.
It can be understood that, when the second server needs to obtain the second data records stored by other second servers, if the second server fails to obtain the second data records from other second servers, the second server may obtain the second data records stored in the cache of the first server from the first server. For example, the second server may send the second acquisition request to the first server, and after receiving the second acquisition request sent by the second server, the first server may send the requested second data record to the second server that sent the second acquisition request.
When the second server needs to acquire the first data record stored by the first server, a second acquisition request may be sent to the first server, and when the first server receives the second acquisition request, the requested first data record may be sent to the second server that sent the second acquisition request.
In the database reading and writing method of the embodiment of the application, the target application program is started synchronously with each second server, and the start of the target application program is monitored, so that the first server reads and stores a first data record local to the first server, sends a first acquisition request to the second server to acquire a second data record stored by the second server, stores the first data record and the second data record in a cache of the first server, receives a second acquisition request from the second server, and sends the requested first data record or the requested second data record to the second server. Therefore, the read first data record stored in the first server and the second data record stored in each second server are stored in the cache of the first server, so that each server can obtain the data records stored in other servers, and the consistency of the data records in each server is realized.
As a possible implementation manner of the embodiment of the present application, after monitoring that the target application program writes to the target database table, the first server may determine, according to whether the sequence number of the data record pointed by the write belongs to the sequence number range recorded in the configuration information of the first data partition, that the record to be subjected to the write is stored in the first data partition or the second data partition. The above process is described in detail with reference to fig. 5, and fig. 5 is a schematic flowchart of determining a storage location of a record to be written according to an embodiment of the present application.
As shown in fig. 5, after the step 101, the following steps may be further included:
step 501, determine the sequence number of the data record pointed by the write operation.
In the embodiment of the application, the data records pointed by the write operation of the target database table are respectively stored in the positions corresponding to the different serial numbers in the data partition, and the first server can determine the storage position of the data record pointed by the write operation according to the position of the data record pointed by the write operation of the target application program to the target database table after monitoring the write operation of the target application program to the target database table.
As an example, if the sequence number corresponding to the first row and the fifth column in the target database table is 5, assuming that the first server monitors that the target application performs the write operation on the record in the first row and the fifth column in the target database table, it may be determined that the sequence number of the data record pointed to by the write operation to be performed is 5.
Step 503, reading the configuration information.
The configuration information is used for representing the sequence number range configured for each data partition in the target database table.
In the embodiment of the application, corresponding configuration information is preset in data partitions stored by a plurality of servers respectively, and a first server can read the configuration information of a first data partition stored by the first server so as to determine a sequence number range corresponding to a data record in the first data partition according to the configuration information of the first data partition.
As a possible scenario, the sequence number range allocated to the ith data partition in the target database table is [ (i-1) × N, i × N ], where i is a positive integer whose value is less than or equal to the total number of data partitions, and N is determined according to the total number of data records contained in the target database table.
As an example, as shown in fig. 6, a sequence number range corresponding to the configuration information of the first data partition stored by the first server may be 1-N, a sequence number range corresponding to the configuration information of the second data partition stored by the second server may be N-2N, and a sequence number range corresponding to the configuration information of the second data partition table stored by another second server may be 2N-3N.
It should be noted that the size of N can be determined according to the number of actual data records in the data partition, and when the number of tables is large, a large value N can be set, so that the sequence number range of all the tables can be reused, and the sequence number interval management of the database table can be simplified.
In the embodiment of the application, when a server exists in a plurality of servers, the servers which are already online need to acquire data stored in the data partition from the data partition stored in the servers which are already online, and in this case, configuration information of the data partition stored in each server needs to be updated, so that each server acquires the data from the data partition stored in the server which is already online and then stores the data in its own data partition.
In the embodiment of the application, when a server exists in a plurality of servers and is offline, the server which is still online needs to update the configuration information of the data partition stored in the server.
As an example, assuming that a certain second server is offline, the first server and other online second servers may update the configuration information of the data partitions stored by the first server and the other online second servers.
Step 505, determine whether the sequence number of the data record pointed by the write operation belongs to the sequence number range of the first data partition described in the configuration information.
In this embodiment of the application, the first server determines the sequence number of the data record pointed by the write operation, and after reading the sequence number range configured by the first data partition locally stored in the configuration information, further determines whether the sequence number of the data record pointed by the write operation belongs to the sequence number range of the first data partition recorded in the configuration information, so as to determine whether the data record pointed by the write operation is stored in the first data partition.
Step 507, if the sequence number belongs to the sequence number range of the first data partition recorded by the configuration information, determining that the data record pointed by the write operation is stored in the first data partition.
In step 509, if the sequence number does not fall within the sequence number range of the first data partition described in the configuration information, it is determined that the data record pointed by the write operation is stored in the second data partition.
As a possible case, the first server determines that the sequence number of the data record pointed to by the write operation belongs to the sequence number range of the first data partition described in the configuration information, and may determine that the data record pointed to by the write operation is stored in the first data partition.
As another possible case, the first server determines that the sequence number of the data record pointed to by the write operation does not belong to the range of sequence numbers of the first data partition described in the configuration information, and may determine that the data record pointed to by the write operation is stored in the second data partition.
As an example, assuming that the sequence number range of the first data partition described by the configuration information is 1-100, and the sequence number range of the second data partition is 101-200, if the first server determines that the sequence number of the data record pointed to by the write operation is 56, it may be determined that the data record pointed to by the write operation is stored in the first data partition.
In the embodiment of the application, after monitoring the write operation of a target application program to a target database table, a first server determines a sequence number of a data record pointed by the write operation, reads configuration information, determines that the data record pointed by the write operation is stored in a first data partition if the sequence number is determined to belong to a sequence number range of the first data partition recorded by the configuration information, and determines that the data record pointed by the write operation is stored in a second data partition if the sequence number is determined not to belong to the sequence number range of the first data partition recorded by the configuration information. Therefore, whether the sequence number of the data record pointed by the write operation belongs to the sequence number range of the first data partition described by the configuration information is determined to determine that the data record pointed by the write operation is stored in the first data partition or the second data partition, and further, whether the write operation is executed on the data record can be determined according to the storage position of the data record pointed by the write operation.
In order to implement the above embodiments, the present application further provides a database read/write apparatus.
Fig. 7 is a schematic structural diagram of a database writing device according to an embodiment of the present application.
As shown in fig. 7, the database writing apparatus 700 may be applied to a first server in a plurality of servers, the plurality of servers further includes at least one second server different from the first server, and the first server and the second server both have a target application deployed therein, and the database writing apparatus 700 may include: a listening module 710, a first processing module 730, and a second processing module 750.
The monitoring module 710 is configured to monitor a write operation of a target application program to a target database table.
The first processing module 730 is configured to, if the data record pointed by the write operation is stored in the first data partition of the target database table, perform the write operation on the data record. The first data partition corresponds to a first server.
A second processing module 550, configured to refuse to perform the write operation if the data record pointed by the write operation is stored in a second data partition of the target database table; wherein the second data partition corresponds to a second server.
As a possible case of the embodiment of the present application, the database writing apparatus 700 may further include:
the reading module is used for periodically reading the first data record stored locally in the first server and acquiring the second data record from the second server.
The writing module is used for writing the first data record into a first data partition corresponding to the first server in a target database table and writing the second data record into a second data partition corresponding to the second server in the target database table according to a preset data partition rule; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
As another possible case of the embodiment of the present application, the database writing apparatus 700 may further include:
the monitoring module is also used for monitoring the reading operation of the target application program on the target database table;
the third processing module is used for locally reading the data record pointed by the read operation from the first server if the data record pointed by the read operation is stored in the first data partition of the target database table;
the fourth processing module is used for acquiring the data record pointed by the read operation from a second server corresponding to a second data partition according to a preset data partition rule if the data record pointed by the read operation is stored in the second data partition of the target database table; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
As another possible case of the embodiment of the present application, the reading module may be further configured to:
synchronously starting the target application program with each second server; when the starting of the target application program is monitored, reading a first data record locally stored in a first server; sending a first acquisition request to a second server to acquire a second data record stored by the second server; the first data record and the second data record are stored in a cache of the first server.
As another possible case of the embodiment of the present application, the reading module may be further configured to:
receiving a second acquisition request from a second server; the requested first data record or second data record is sent to a second server.
As another possible case of the embodiment of the present application, when a plurality of servers includes a plurality of second servers, the reading module may further be configured to:
sequentially sending first acquisition requests to a plurality of second servers in a set sequence; the first acquisition request comprises an identifier of a second data record which fails to be acquired and/or an identifier of a second data record to be acquired.
As another possible case of the embodiment of the present application, the fourth processing module is further configured to:
determining a corresponding second server according to the second data partition; sending an acquisition request to a second server corresponding to the second data partition according to the reading operation; receiving an acquisition response sent by a second server corresponding to the second data partition; and responding to the read operation according to the data record carried in the acquisition response.
As another possible case of the embodiment of the present application, the database reading and writing apparatus 700 may further include:
and the determining module is used for determining the sequence number of the data record pointed by the write operation.
And the second reading module is used for reading the configuration information.
And the third processing module is used for determining that the data record pointed by the write operation is stored in the first data partition if the sequence number belongs to the sequence number range of the first data partition recorded by the configuration information.
And the fourth processing module is used for determining that the data record pointed by the write operation is stored in the second data partition if the sequence number does not belong to the sequence number range of the first data partition recorded by the configuration information.
As another possible case of the embodiment of the present application, the database reading and writing apparatus 700 may further include:
and the updating module is used for updating the configuration information when the servers are online or offline.
As another possible case of the embodiment of the present application, the sequence number range allocated to the ith data partition in the target database table is [ (i-1) × N, i × N ], where i is a positive integer whose value is less than or equal to the total number of data partitions, and N is determined according to the total number of data records contained in the target database table.
It should be noted that the explanation of the embodiment of the database reading and writing method is also applicable to the database reading and writing device of the embodiment, and is not repeated herein.
The database reading and writing device of the embodiment of the application monitors the writing operation of a target application program on a target database table, and if the data record pointed by the writing operation is stored in a first data partition, the writing operation is executed on the data record; and if the data record pointed by the write operation is stored in the second data partition, refusing to execute the write operation. Therefore, the first server can acquire the database tables stored by other servers, and each server in the multiple servers has the read-write operation capacity.
In order to implement the foregoing embodiments, the present application further provides a server, as shown in fig. 8, where the server 800 includes a memory 810, a processor 820, and a computer program that is stored in the memory 810 and is executable on the processor 820, and after the processor 820 acquires the computer program through the communication interface 830, when the computer program is executed, the database reading and writing method described in the foregoing embodiments is implemented.
In order to implement the above embodiments, the present application also proposes a non-transitory computer-readable storage medium on which a computer program is stored, which, when executed by a processor, implements the database read-write method described in the above embodiments.
In the description herein, reference to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the application. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
Furthermore, the terms "first", "second" and "first" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In the description of the present application, "plurality" means at least two, e.g., two, three, etc., unless specifically limited otherwise.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing steps of a custom logic function or process, and alternate implementations are included within the scope of the preferred embodiment of the present application in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the present application.
The logic and/or steps represented in the flowcharts or otherwise described herein, e.g., an ordered listing of executable instructions that can be considered to implement logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For the purposes of this description, a "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. If implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware related to instructions of a program, which may be stored in a computer readable storage medium, and when the program is executed, the program includes one or a combination of the steps of the method embodiments.
In addition, functional units in the embodiments of the present application may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium.
The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc. Although embodiments of the present application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present application, and that variations, modifications, substitutions and alterations may be made to the above embodiments by those of ordinary skill in the art within the scope of the present application.

Claims (22)

1. A database read-write method, wherein the method is performed by a first server of a plurality of servers, the plurality of servers further includes at least one second server different from the first server, and a target application is deployed in each of the first server and the second server, the method includes the following steps:
monitoring the write operation of the target application program to a target database table;
if the data record pointed by the write operation is stored in the first data partition of the target database table, executing the write operation on the data record; wherein the first data partition corresponds to the first server;
if the data record pointed by the write operation is stored in a second data partition of the target database table, refusing to execute the write operation; wherein the second data partition corresponds to the second server.
2. The database reading and writing method according to claim 1, wherein before the listening to the write operation of the target application program to the target database table, further comprises:
periodically reading a first data record stored locally at the first server and obtaining a second data record from the second server;
writing the first data record into a first data partition corresponding to the first server in the target database table according to a preset data partition rule, and writing the second data record into a second data partition corresponding to the second server in the target database table; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
3. The database reading and writing method according to claim 1, wherein before the listening to the write operation of the target application program to the target database table, further comprises:
monitoring the reading operation of the target application program on the target database table;
if the data record pointed by the read operation is stored in a first data partition of the target database table, locally reading the data record pointed by the read operation from the first server;
if the data record pointed by the reading operation is stored in a second data partition of the target database table, acquiring the data record pointed by the reading operation from a second server corresponding to the second data partition according to a preset data partition rule; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
4. The database read-write method of claim 2, wherein the periodically reading a first data record stored locally at the first server and retrieving a second data record from the second server comprises:
synchronously starting the target application program with each second server;
reading a first data record locally stored in the first server when the target application program is monitored to be started;
sending a first acquisition request to the second server to acquire a second data record stored by the second server;
storing the first data record and the second data record in a cache of the first server.
5. The database reading and writing method according to claim 4, further comprising, after storing the first data record and the second data record in the cache of the first server:
receiving a second acquisition request from a second server;
sending the requested first data record or the second data record to the second server.
6. The database reading and writing method according to claim 4, wherein when a plurality of second servers are included in the plurality of servers, the sending a first acquisition request to the second servers to acquire the second data records stored by the second servers comprises:
sequentially sending the first acquisition requests to the plurality of second servers in a set sequence;
the first acquisition request comprises an identifier of a second data record which fails to be acquired and/or an identifier of a second data record to be acquired.
7. The database reading and writing method according to claim 3, wherein the obtaining of the data record pointed to by the read operation from the second server corresponding to the second data partition includes:
determining a corresponding second server according to the second data partition;
sending an acquisition request to a second server corresponding to the second data partition according to the read operation;
receiving an acquisition response sent by a second server corresponding to the second data partition;
and responding to the read operation according to the data record carried in the acquisition response.
8. The database reading and writing method according to any one of claims 1 to 7, wherein after the listening to the write operation of the target application program to the target database table, the method further comprises:
determining the sequence number of the data record pointed by the write operation;
reading configuration information, wherein the configuration information is used for representing a sequence number range configured for each data partition in the target database table;
if the sequence number belongs to the sequence number range of the first data partition recorded by the configuration information, determining that the data record pointed by the write operation is stored in the first data partition;
and if the sequence number does not belong to the range of the sequence number of the first data partition recorded by the configuration information, determining that the data record pointed by the write operation is stored in the second data partition.
9. The database reading and writing method according to claim 8, further comprising:
and when the servers are online or offline, updating the configuration information.
10. The database reading and writing method according to claim 8, wherein the sequence number range allocated to the ith data partition in the target database table is [ (i-1) × N, i × N ], where i is a positive integer whose value is less than or equal to the total number of data partitions, and N is determined according to the total number of data records contained in the target database table.
11. A database read-write apparatus applied to a first server in a plurality of servers, wherein the plurality of servers further include at least one second server different from the first server, and target applications are deployed in both the first server and the second server, the apparatus comprising:
the monitoring module is used for monitoring the write operation of the target application program to the target database table;
the first processing module is used for executing the write operation on the data record if the data record pointed by the write operation is stored in a first data partition of the target database table; wherein the first data partition corresponds to the first server;
the second processing module is used for refusing to execute the write operation if the data record pointed by the write operation is stored in a second data partition of the target database table; wherein the second data partition corresponds to the second server.
12. The database reading and writing apparatus of claim 11, wherein the apparatus further comprises:
the reading module is used for periodically reading a first data record locally stored in the first server and acquiring a second data record from the second server;
a writing module, configured to write the first data record into a first data partition corresponding to the first server in the target database table according to a preset data partition rule, and write the second data record into a second data partition corresponding to the second server in the target database table; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
13. The database reading and writing apparatus of claim 11, wherein the apparatus further comprises:
the monitoring module is also used for monitoring the reading operation of the target application program on the target database table;
a third processing module, configured to locally read, from the first server, a data record pointed to by the read operation if the data record pointed to by the read operation is stored in the first data partition of the target database table;
the fourth processing module is configured to, if the data record pointed by the read operation is stored in a second data partition of the target database table, obtain the data record pointed by the read operation from a second server corresponding to the second data partition according to a preset data partition rule; the preset data partition rule is used for representing the corresponding relation between the data partition in the target database table and each server in the plurality of servers.
14. The database reading and writing apparatus of claim 12, wherein the reading module is further configured to:
synchronously starting the target application program with each second server;
reading a first data record locally stored in the first server when the target application program is monitored to be started;
sending a first acquisition request to the second server to acquire a second data record stored by the second server;
storing the first data record and the second data record in a cache of the first server.
15. The database reading and writing apparatus of claim 14, wherein the reading module is further configured to:
receiving a second acquisition request from a second server; sending the requested first data record or the second data record to the second server.
16. The database reading and writing apparatus according to claim 14, wherein when a plurality of second servers are included in the plurality of servers, the reading module is further configured to:
sequentially sending the first acquisition requests to the plurality of second servers in a set sequence;
the first acquisition request comprises an identifier of a second data record which fails to be acquired and/or an identifier of a second data record to be acquired.
17. The database reading-writing apparatus according to claim 13, wherein the fourth processing module is further configured to:
determining a corresponding second server according to the second data partition;
sending an acquisition request to a second server corresponding to the second data partition according to the reading operation;
receiving an acquisition response sent by a second server corresponding to the second data partition;
and responding to the read operation according to the data record carried in the acquisition response.
18. A database reading and writing apparatus according to any one of claims 11 to 17, wherein the apparatus further comprises:
the determining module is used for determining the sequence number of the data record pointed by the write operation;
the second reading module is used for reading configuration information, and the configuration information is used for representing the sequence number range configured for each data partition in the target database table;
a third processing module, configured to determine that the data record pointed by the write operation is stored in the first data partition if the sequence number belongs to a sequence number range of the first data partition recorded in the configuration information;
and the fourth processing module is configured to determine that the record of the data record pointed by the write operation is stored in the second data partition if the sequence number does not belong to the range of the sequence number of the first data partition recorded in the configuration information.
19. The database reading and writing apparatus of claim 18, wherein the apparatus further comprises:
and the updating module is used for updating the configuration information when the servers are online or offline.
20. The database reading and writing apparatus according to claim 18, wherein the sequence number range allocated to the ith data partition in the target database table is [ (i-1) × N, i × N ], where i is a positive integer whose value is less than or equal to the total number of data partitions, and N is determined according to the total number of data records contained in the target database table.
21. A server comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the database reading and writing method according to any one of claims 1 to 10 when executing the program.
22. A non-transitory computer-readable storage medium on which a computer program is stored, the computer program, when executed by a processor, implementing a database read-write method according to any one of claims 1 to 10.
CN202011332493.0A 2020-11-24 2020-11-24 Database reading and writing method, device, server and medium Pending CN114547019A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011332493.0A CN114547019A (en) 2020-11-24 2020-11-24 Database reading and writing method, device, server and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011332493.0A CN114547019A (en) 2020-11-24 2020-11-24 Database reading and writing method, device, server and medium

Publications (1)

Publication Number Publication Date
CN114547019A true CN114547019A (en) 2022-05-27

Family

ID=81660376

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011332493.0A Pending CN114547019A (en) 2020-11-24 2020-11-24 Database reading and writing method, device, server and medium

Country Status (1)

Country Link
CN (1) CN114547019A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114707147A (en) * 2022-06-05 2022-07-05 荣耀终端有限公司 Service request processing method and electronic equipment
CN115062092A (en) * 2022-08-10 2022-09-16 阿里云计算有限公司 Database access method, device, system and storage medium

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114707147A (en) * 2022-06-05 2022-07-05 荣耀终端有限公司 Service request processing method and electronic equipment
CN115062092A (en) * 2022-08-10 2022-09-16 阿里云计算有限公司 Database access method, device, system and storage medium
CN115062092B (en) * 2022-08-10 2023-02-03 阿里云计算有限公司 Database access method, device, system and storage medium

Similar Documents

Publication Publication Date Title
CN108235751B (en) Method and device for identifying sub-health of object storage equipment and data storage system
CN109597567B (en) Data processing method and device
US5504888A (en) File updating system employing the temporary connection and disconnection of buffer storage to extended storage
US20140025820A1 (en) Hybrid locking using network and on-disk based schemes
US7624230B2 (en) Information processing apparatus, information processing method and storage system using cache to reduce dynamic switching of mapping between logical units and logical devices
US8032784B2 (en) Duplication combination management program, duplication combination management apparatus, and duplication combination management method
JP2005018738A (en) Method and apparatus for backup and recovery using storage based journaling
CN104935654A (en) Caching method, write point client and read client in server cluster system
CN114547019A (en) Database reading and writing method, device, server and medium
CN106126374B (en) Method for writing data, method for reading data and device
CN108595119B (en) Data synchronization method and distributed system
CN113568582B (en) Data management method, device and storage equipment
CN114827178A (en) Data processing method, device and equipment and readable storage medium
CN113946291A (en) Data access method, device, storage node and readable storage medium
CN115756317A (en) Storage method, storage device, electronic equipment and storage medium of shingled magnetic disk
CN111857581A (en) Data storage processing method and system
CN116974489A (en) Data processing method, device and system, electronic equipment and storage medium
CN112083886B (en) Storage management method, system and device of NAS (network attached storage) equipment
US8191066B2 (en) Continuously loading series of data whether data is requested or not, in response to end command unloading the data in descendent order of reference probability
CN115562582A (en) Data migration method based on blue-ray disc library, server and blue-ray disc library
CN115599291A (en) Cloud storage system, disk management method thereof, cloud storage server and storage medium
US20170115918A1 (en) Maintaining access times in storage systems employing power saving techniques
CN110674079B (en) Log file recording method and device
JP6788188B2 (en) Control device and control program
CN114356232B (en) Data reading and writing method and device

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