CN110727698A - Database access method and device, computer equipment and storage medium - Google Patents

Database access method and device, computer equipment and storage medium Download PDF

Info

Publication number
CN110727698A
CN110727698A CN201910849276.XA CN201910849276A CN110727698A CN 110727698 A CN110727698 A CN 110727698A CN 201910849276 A CN201910849276 A CN 201910849276A CN 110727698 A CN110727698 A CN 110727698A
Authority
CN
China
Prior art keywords
database
data
identifier
request
read
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
CN201910849276.XA
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.)
Weikun Shanghai Technology Service Co Ltd
Original Assignee
Lujiazui Shanghai International Financial Assets Market Ltd By Share Ltd
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 Lujiazui Shanghai International Financial Assets Market Ltd By Share Ltd filed Critical Lujiazui Shanghai International Financial Assets Market Ltd By Share Ltd
Priority to CN201910849276.XA priority Critical patent/CN110727698A/en
Publication of CN110727698A publication Critical patent/CN110727698A/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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • 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

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)
  • Computational Linguistics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The present application relates to the field of data security, and in particular, to a database access method, apparatus, computer device, and storage medium. The method comprises the following steps: receiving an access request sent by a terminal, and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is subjected to operation separation; when the database is determined not to be operated and separated according to the database state identification, a standby database is obtained; extracting a data reading identifier corresponding to the standby database, and extracting a request operation identifier corresponding to the access request; judging whether the request operation identifier is a data reading identifier or not; when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal. By adopting the method, the access stability of the database can be improved.

Description

Database access method and device, computer equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a database access method, apparatus, computer device, and storage medium.
Background
In the field of data processing, different databases are generally established to store data, and for example, by establishing a database, data writing and data reading operations can be realized.
Conventionally, a primary database and a backup database may be provided, and the backup database may synchronize related data of the primary database, but the backup database is only used for backing up related data of the primary database, and database access operations such as reading or writing are still performed in the primary database, so that when the primary database crashes, the database access operations may fail, resulting in poor database access stability.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a database access method, an apparatus, a computer device, and a storage medium capable of improving stability of database access.
A database access method, the method comprising:
receiving an access request sent by a terminal, and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is operated and separated;
when the database is determined not to be operated and separated according to the database state identification, a standby database is obtained;
extracting a data reading identifier corresponding to the standby database, and extracting a request operation identifier corresponding to the access request;
judging whether the request operation identifier is a data reading identifier;
when the request operation identifier is not a data reading identifier, sending rejection information to the terminal;
and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal.
In one embodiment, after querying the database status identifier according to the access request, the method includes:
when the operation separation of the database is determined according to the database state identifier, extracting a request operation identifier corresponding to the access request;
and acquiring a database to be accessed according to the request operation identifier, and accessing the database to be accessed according to the access request.
In one embodiment, the obtaining the database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request includes:
when the request operation identifier is a data reading identifier, taking the standby database as a database to be accessed;
acquiring a main database corresponding to the standby database, inquiring whether the main database carries an update identifier or not, and acquiring a data cache library when the main database does not carry the update identifier;
and querying the data cache library according to the data reading identification to obtain data to be read so as to access the database to be accessed.
In one embodiment, the obtaining the database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request includes:
when the request operation identifier is a data writing identifier, taking the main database as a database to be accessed;
storing write data corresponding to the request to be accessed to the master database;
and adding an updating identifier to a master database storing the written data.
In one embodiment, the adding of the update identifier to the master database storing the write data includes;
querying the data volume of the written data stored in the master database added with the update identification;
when the data volume does not exceed a preset value, acquiring a data cache library, and storing the written data to the data cache library;
when feedback information fed back by the data cache library and successfully stored is received, deleting the updating identification added by the main database;
and storing the write-in data stored in the data cache library to a standby database.
In one of the embodiments, the first and second electrodes are,
before reading the data to be read from the standby database, the method also comprises the following steps;
acquiring a data cache library, and inquiring data to be read corresponding to the access request from the data cache library;
and when the data to be read is not inquired, reading the data to be read from the standby database.
A database access apparatus, the apparatus comprising:
the receiving module is used for receiving an access request sent by a terminal and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is operated and separated;
the available database query module is used for acquiring a standby database when the database is determined not to be operated and separated according to the database state identifier;
the first extraction module is used for extracting a data reading identifier corresponding to the standby database and extracting a request operation identifier corresponding to the access request;
the judging module is used for judging whether the request operation identifier is a data reading identifier;
the first access module is used for sending rejection information to the terminal when the request operation identifier is not a data reading identifier; and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal.
In one embodiment, the apparatus further comprises:
the second extraction module is used for extracting a request operation identifier corresponding to the access request when the database is determined to be operated and separated according to the database state identifier;
and the second access module is used for acquiring the database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request.
A computer device comprising a memory storing a computer program and a processor implementing the steps of any of the methods described above when the processor executes the computer program.
A computer-readable storage medium, on which a computer program is stored which, when being executed by a processor, carries out the steps of the method of any of the above.
In the database access method, the database access device, the computer equipment and the storage medium, when an access request sent by a terminal is received, a database state identifier can be inquired according to the access request, and when the database state identifier indicates that the database is not operated and separated, a standby database is inquired according to the database state identifier, a data reading identifier of the standby database is further extracted, a request operation identifier corresponding to the access request is extracted, and whether the request operation identifier is a data reading identifier is judged; when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; when the request operation identifier is a data reading identifier, the data to be read is read from the standby database, and the read data to be read is fed back to the terminal, so that the database access failure when the main database crashes is avoided, namely, the data access failure when the database is not separated by operation is avoided, and the stability of database access can be improved.
Drawings
FIG. 1 is a diagram illustrating an example of an application scenario for a database access method;
FIG. 2 is a schematic flow chart diagram illustrating a database access method in one embodiment;
FIG. 3 is a block diagram showing the structure of a database access device according to one embodiment;
FIG. 4 is a diagram illustrating an internal structure of a computer device according to an embodiment.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The method provided by the application can be applied to the application environment shown in FIG. 1. The terminal 102 communicates with the server 104 via a network. The server communicates with the main database 106 and the standby database 108, wherein the server 104 firstly queries the status identifier of the database after receiving an access request sent by the terminal 102, and when the identifier database is not operated and separated, i.e. is in an abnormal state, the server queries the standby database according to the status identifier of the database, extracts the data reading identifier corresponding to the standby data, extracts the request operation identifier corresponding to the access request, and judges whether the request operation identifier is the data reading identifier; when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding the read data to be read back to the terminal, so that the stability of the database is ensured. The terminal 102 may be, but is not limited to, various personal computers, notebook computers, smart phones, tablet computers, and portable wearable devices, the service server 104 may be implemented by an independent server or a server cluster formed by a plurality of servers, and the rule server 106 may be implemented by an independent server or a server cluster formed by a plurality of servers.
In one embodiment, as shown in fig. 2, an interface calling method is provided, which is described by taking the method as an example applied in fig. 1, and includes the following steps:
s202: and receiving an access request sent by the terminal, and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is operated and separated.
Specifically, the server receives an access request sent by the terminal, wherein the access request is used for requesting the server to read data in the database or write data in the database. The database state identifier is an identifier for identifying whether the database is separated in operation, and may indicate that the database is separated in reading and writing, that is, the database is in a normal state, or indicate that the database is not separated in reading and writing, that is, the database is in an abnormal state.
The main database is provided with corresponding processing code segments for writing data and processing code segments for reading data in a gathering mode in the development process, the standby database is only provided with processing code segments for reading data, namely the main database can write data and read data, and the standby database can only read data. When the database is in a normal state, the server writes data in through the main database and reads data through the standby database, so that the pressure of the database can be reduced.
The server receives an access request sent by the terminal, and then the server directly queries a corresponding database state identifier in the memory, wherein the database state identifier can be whether to enter a read-write separation mode, namely whether the database is normal or not, and when the server queries that the database state identifier is abnormal, the read-write separation is not performed.
S204: and when the database is determined not to be operated and separated according to the database state identifier, acquiring a standby database.
S206: and extracting a data reading identifier corresponding to the standby database, and extracting a request operation identifier corresponding to the access request.
Specifically, when the database is normal, the primary database may perform both a read operation and a write operation, and when the database is abnormal, the primary database may not work and the backup database may perform a read operation.
Specifically, when the database state identifier is not subjected to operation separation, the server queries a database without abnormality, that is, a standby database, from the data operation identifiers, extracts the operation identifier of the database without abnormality, that is, obtains a data reading identifier of the standby database, and further analyzes a request operation identifier included in the data request, that is, queries an operation of data writing or data reading corresponding to the data request.
S208: and judging whether the request operation identifier is a data reading identifier.
S210: when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal.
Specifically, the server judges whether the request operation identifier is a data reading identifier, that is, compares the request operation identifier with a data reading identifier of the standby database to obtain a comparison result, performs corresponding operation when the comparison is successful, that is, the request operation identifier is the data reading identifier, and cannot perform data operation corresponding to the data request when the comparison is unsuccessful, that is, the request operation identifier is not the data reading identifier, so that the server feeds back feedback information of request failure to the terminal. For example, when the request operation identifier included in the data analysis request is the data reading identifier, the data reading operation can be performed, and the server feeds back the data reading result to the terminal; in addition, when the data operation identifier is a data reading identifier and the request operation identifier is a data writing identifier, the server cannot perform the operation, and the server feeds back the feedback information of the failed request to the terminal. The standby database also performs related data operation, reduces the working pressure of a single database, and can judge the working states of different databases, thereby improving the accuracy of database operation.
In the database access method, when an access request sent by a terminal is received, a database state identifier can be inquired according to the access request, and when the database state identifier indicates that the database is not operated and separated, a standby database is inquired according to the database state identifier, so that a data reading identifier of the standby database is extracted, a request operation identifier corresponding to the access request is extracted, and whether the request operation identifier is a data reading identifier is judged; when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; when the request operation identifier is a data reading identifier, the data to be read is read from the standby database, and the read data to be read is fed back to the terminal, so that the database access failure when the main database crashes is avoided, namely, the data access failure when the database is not separated by operation is avoided, and the stability of database access can be improved.
In one embodiment, after querying the database status identifier according to the access request, the method includes: when the operation separation of the database is determined according to the database state identifier, extracting a request operation identifier corresponding to the access request; and acquiring the database to be accessed according to the request operation identifier, and accessing the database to be accessed according to the access request.
In one embodiment, the acquiring a database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request includes: when the request operation identifier is a data reading identifier, taking the standby database as a database to be accessed; acquiring a main database corresponding to the standby database, inquiring whether the main database carries an update identifier or not, and acquiring a data cache library when the main database does not carry the update identifier; and querying the data cache library according to the data reading identification to obtain the data to be read so as to complete the access of the database to be accessed.
In one embodiment, the acquiring a database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request includes: when the request operation identifier is a data writing identifier, taking the main database as a database to be accessed; storing write-in data corresponding to the request to be accessed to a main database; and adding an updating identification to a master database storing the written data.
In one embodiment, after adding the update identification to the master database storing the write data, the method comprises the following steps of; inquiring the data volume of the written data stored in the master database added with the update identification; when the data volume does not exceed the preset value, acquiring a data cache library, and storing the written data into the data cache library; when feedback information fed back by the data cache library and successfully stored is received, deleting the updating identification added by the main database; and storing the write data stored in the data cache library to the standby database.
Specifically, when the database state identifier indicates that the database is to be operated and separated, that is, the database may enter a read-write separation operation, that is, the database is working normally, the server may extract an interface to be accessed from the data access request, and further query the request operation identifier corresponding to the interface to be accessed, so that the server determines whether the request operation identifier is data write or data read, and further obtains the corresponding database to be accessed according to the request operation identifier, and performs data access. Namely, when the main database and the standby database both work normally, the server can acquire the corresponding database to perform data writing or reading operation, so that the required database can be quickly inquired, and the inquiry efficiency is improved.
When the operation request identifier is a data reading identifier, the database to be accessed is a standby database, and in order to ensure the integrity of data, the server may first query whether a main database corresponding to the standby database carries an update identifier, when the main database carries the update identifier, the identifier just completes the operation of writing data in the main database, so as to avoid that the main database does not update the updated data to the standby database, directly query the standby database to cause data missing in the query, directly query the corresponding data from the main database, when the main database does not carry the update identifier, the main database does not have the updated data, first query the corresponding data cache database, i.e. redis cache, when the corresponding data is queried from the cache, the standby database does not need to be obtained again, so that resources are saved, and when the data corresponding to the data request is not queried from the data cache database, then the standby database is called again to inquire the data corresponding to the data request.
When the request operation identifier is a data write identifier, the server takes the main database as a database to be accessed, so that the written data can be directly stored in the main database, and in order to ensure the integrity of the data, an update identifier is added to the main database in which new data is just written, so that, after the update identifier is added to the main database by the server, the data of the main database can be updated to the corresponding data cache library and the standby database, when the server writes the data into the main database, the updated data of the main database needs to be updated to the standby database, and during updating, the data can be selected to be backed up to the data cache library firstly or to be backed up to the standby database directly aiming at different data, namely aiming at the data with larger data volume, in order to ensure the accuracy and speed of backup, the data can be backed up to the standby database directly, and for a small data volume, the data is backed up to the data cache library first, so that the backup efficiency can be ensured, the efficiency can be improved by subsequently inquiring the data, and then the subsequent server backs up the newly added data in the data cache library to the standby database.
In one embodiment, before reading the data to be read from the standby database, the method further comprises the following steps; acquiring a data cache library, and inquiring data to be read corresponding to the access request from the data cache library; and when the data to be read is not inquired, reading the data to be read from the standby database.
In this embodiment, when the operation separation is not performed, when the database queried by the server is the standby database, since the standby database can only perform a data reading operation, that is, when the server finds that the database is the standby database, whether the data access request is read data is determined, when the data access request is not read data, that is, when the data access request is write data, the server feeds back error information to the terminal, and when the data access request is the read data, the data can be read from the standby database.
In the above embodiment, when an access request sent by a terminal is received, a database state identifier may be queried according to the access request, and when the database state identifier indicates that the database is not separated by operation, a standby database is queried according to the database state identifier, so as to extract a data reading identifier of the standby database, extract a request operation identifier corresponding to the access request, and determine whether the request operation identifier is a data reading identifier; when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; when the request operation identifier is a data reading identifier, the data to be read is read from the standby database, and the read data to be read is fed back to the terminal, so that the database access failure when the main database crashes is avoided, namely, the data access failure when the database is not separated by operation is avoided, and the stability of database access can be improved.
The following provides a complete embodiment of a database access method: in the embodiment, a terminal firstly sends a data access request to a server, so that the server inquires a database state identifier according to the data access request, when the database state identifier indicates that operation separation is not performed, the server inquires an available database and extracts a data operation identifier of the available database and a request operation identifier corresponding to the access request; when the available database is a standby database, the data operation identifier is a read data identifier, so that when the request operation identifier is a read data identifier, the server normally reads data in the standby database to feed back the data to the terminal, and when the request operation identifier is a write data identifier, the server feeds back access failure information to the terminal. When the available database is the main database, the server operates according to the request operation identifier, such as reading data or writing data.
When the database state identification indicates that operation separation is performed, the server extracts a request operation identification corresponding to the access request, when the request operation identification is a data reading identification, the server can read data from the standby database, in order to guarantee the integrity of the data, the server firstly inquires whether the main database carries the updating identification, when the updating identification is carried, the server acquires a data cache library, and reads the data to be read from the data cache library and the standby database so as to complete the reading of the whole data. And when the request operation identifier is a data writing identifier, taking the main database as a database to be accessed, writing the written data into the main database according to the access request, and adding an updating identifier to the main database so as to write the written data into the standby database. When data is written into the standby database, the backup can be selected to be performed to the data cache library firstly or to be performed to the standby database directly according to different data, that is, according to data with a large data volume, the backup can be performed to the standby database directly in order to ensure the accuracy and speed of the backup, and for a small data volume, the backup is performed to the data cache library firstly, so that the backup efficiency can be ensured, the efficiency can be improved when data is inquired subsequently, and then the newly added data in the data cache library is backed up to the standby database by the subsequent server.
It should be understood that, although the steps in the flowchart of fig. 2 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a portion of the steps in fig. 2 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
In one embodiment, as shown in fig. 3, there is provided a database access apparatus including: a receiving module 100, an available database query module 200, a first extraction module 300, a judgment module 400, and a first access module 500, wherein:
the receiving module 100 is configured to receive an access request sent by a terminal, and query a database status identifier according to the access request, where the database status identifier is an identifier used to identify whether the database is separated from the operation.
The available database query module 200 is configured to obtain a standby database when it is determined that the database is not operation-separated according to the database status identifier.
The first extraction module 300 is configured to extract a data reading identifier corresponding to the standby database, and extract a request operation identifier corresponding to the access request.
The determining module 400 is configured to determine whether the request operation identifier is a data reading identifier.
A first access module 500, configured to send rejection information to the terminal when the request operation identifier is not the data reading identifier; and when the requested operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal.
In one embodiment, the apparatus further comprises:
and the second extraction module is used for extracting the request operation identifier corresponding to the access request when the database is determined to be operated and separated according to the database state identifier.
And the second access module is used for acquiring the database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request.
In one embodiment, the second access module comprises:
and the first database selection unit is used for taking the standby database as the database to be accessed when the request operation identifier is the data reading identifier.
And the data cache bank selecting unit is used for acquiring a main database corresponding to the standby database, inquiring whether the main database carries the updating identification or not, and acquiring the data cache bank when the main database does not carry the updating identification.
And the access unit is used for inquiring the data cache library according to the data reading identification to obtain the data to be read so as to complete the access of the database to be accessed.
In one embodiment, the second access module comprises:
and the second database selection unit is used for taking the main database as the database to be accessed when the request operation identifier is the data writing identifier.
And the writing unit is used for storing the written data corresponding to the request to be accessed to the main database.
And the identification updating unit is used for adding an updating identification to the master database storing the written data.
In one embodiment, the apparatus further comprises;
and the data volume query module is used for querying the data volume of the write data stored in the master database added with the update identification.
And the writing module is used for acquiring the data cache library and storing the written data to the data cache library when the data volume does not exceed the preset value.
And the identifier deleting module is used for deleting the updating identifier added by the main database when receiving the feedback information of successful storage fed back by the data cache database.
And the storage module is used for storing the write-in data stored in the data cache library to the standby database.
In one embodiment, the apparatus further includes:
and the first data reading module is used for acquiring a data cache library and inquiring data to be read corresponding to the access request from the data cache library.
And the second data reading module is used for reading the data to be read from the standby database when the data to be read is not inquired.
For specific limitations of the database access device, reference may be made to the above limitations of the database access method, which are not described herein again. The modules in the database access device can be wholly or partially implemented by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server, the internal structure of which may be as shown in fig. 3. The computer device includes a processor, a memory, a network interface, and a database connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used for storing data. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a database access method.
Those skilled in the art will appreciate that the architecture shown in fig. 4 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, there is provided a computer device comprising a memory storing a computer program and a processor implementing the following steps when the processor executes the computer program: receiving an access request sent by a terminal, and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is subjected to operation separation; when the database is determined not to be operated and separated according to the database state identification, a standby database is obtained; extracting a data reading identifier corresponding to the standby database, and extracting a request operation identifier corresponding to the access request; judging whether the request operation identifier is a data reading identifier or not; when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal.
In one embodiment, after the querying the database state identifier according to the access request, the processor, implemented when executing the computer program, includes: when the operation separation of the database is determined according to the database state identifier, extracting a request operation identifier corresponding to the access request; and acquiring the database to be accessed according to the request operation identifier, and accessing the database to be accessed according to the access request.
In one embodiment, the obtaining of the database to be accessed according to the request operation identifier and the accessing of the database to be accessed according to the access request, which are implemented when the processor executes the computer program, includes: when the request operation identifier is a data reading identifier, taking the standby database as a database to be accessed; acquiring a main database corresponding to the standby database, inquiring whether the main database carries an update identifier or not, and acquiring a data cache library when the main database does not carry the update identifier; and querying the data cache library according to the data reading identification to obtain the data to be read so as to complete the access of the database to be accessed.
In one embodiment, the obtaining of the database to be accessed according to the request operation identifier and the accessing of the database to be accessed according to the access request, which are implemented when the processor executes the computer program, includes: when the request operation identifier is a data writing identifier, taking the main database as a database to be accessed; storing write-in data corresponding to the request to be accessed to a main database; and adding an updating identification to a master database storing the written data.
In one embodiment, the adding of the update identification to the master database storing the write data, as implemented by the processor when executing the computer program, comprises; inquiring the data volume of the written data stored in the master database added with the update identification; when the data volume does not exceed the preset value, acquiring a data cache library, and storing the written data into the data cache library; when feedback information fed back by the data cache library and successfully stored is received, deleting the updating identification added by the main database; and storing the write data stored in the data cache library to the standby database.
In one embodiment, the reading of the data to be read from the standby database when the processor executes the computer program further comprises; acquiring a data cache library, and inquiring data to be read corresponding to the access request from the data cache library; and when the data to be read is not inquired, reading the data to be read from the standby database.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of: receiving an access request sent by a terminal, and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is subjected to operation separation; when the database is determined not to be operated and separated according to the database state identification, a standby database is obtained; extracting a data reading identifier corresponding to the standby database, and extracting a request operation identifier corresponding to the access request; judging whether the request operation identifier is a data reading identifier or not; when the request operation identifier is not the data reading identifier, transmitting rejection information to the terminal; and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal. In one embodiment, the computer program when executed by a processor, when implemented to query a database state identifier in response to an access request, comprises: when the operation separation of the database is determined according to the database state identifier, extracting a request operation identifier corresponding to the access request; and acquiring the database to be accessed according to the request operation identifier, and accessing the database to be accessed according to the access request.
In one embodiment, the obtaining of the database to be accessed according to the request operation identifier and the accessing of the database to be accessed according to the access request, which are implemented when the computer program is executed by the processor, includes: when the request operation identifier is a data reading identifier, taking the standby database as a database to be accessed; acquiring a main database corresponding to the standby database, inquiring whether the main database carries an update identifier or not, and acquiring a data cache library when the main database does not carry the update identifier; and querying the data cache library according to the data reading identification to obtain the data to be read so as to complete the access of the database to be accessed.
In one embodiment, the obtaining of the database to be accessed according to the request operation identifier and the accessing of the database to be accessed according to the access request, which are implemented when the computer program is executed by the processor, includes: when the request operation identifier is a data writing identifier, taking the main database as a database to be accessed; storing write-in data corresponding to the request to be accessed to a main database; and adding an updating identification to a master database storing the written data.
In one embodiment, the computer program, when executed by the processor, is implemented to perform the following steps of adding an update identification to a master database storing write data; inquiring the data volume of the written data stored in the master database added with the update identification; when the data volume does not exceed the preset value, acquiring a data cache library, and storing the written data into the data cache library; when feedback information fed back by the data cache library and successfully stored is received, deleting the updating identification added by the main database; and storing the write data stored in the data cache library to the standby database.
In one embodiment, the reading of the data to be read from the backup database, which is realized when the computer program is executed by the processor, further comprises; acquiring a data cache library, and inquiring data to be read corresponding to the access request from the data cache library; and when the data to be read is not inquired, reading the data to be read from the standby database.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A database access method, the method comprising:
receiving an access request sent by a terminal, and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is operated and separated;
when the database is determined not to be operated and separated according to the database state identification, a standby database is obtained;
extracting a data reading identifier corresponding to the standby database, and extracting a request operation identifier corresponding to the access request;
judging whether the request operation identifier is a data reading identifier;
when the request operation identifier is not a data reading identifier, sending rejection information to the terminal;
and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal.
2. The method of claim 1, wherein after querying the database status identifier according to the access request, the method further comprises:
when the operation separation of the database is determined according to the database state identifier, extracting a request operation identifier corresponding to the access request;
and acquiring a database to be accessed according to the request operation identifier, and accessing the database to be accessed according to the access request.
3. The method according to claim 2, wherein the obtaining the database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request comprises:
when the request operation identifier is a data reading identifier, taking the standby database as a database to be accessed;
acquiring a main database corresponding to the standby database, inquiring whether the main database carries an update identifier or not, and acquiring a data cache library when the main database does not carry the update identifier;
and querying the data cache library according to the data reading identification to obtain data to be read so as to access the database to be accessed.
4. The method according to claim 2, wherein the obtaining the database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request comprises:
when the request operation identifier is a data writing identifier, taking the main database as a database to be accessed;
storing write data corresponding to the request to be accessed to the master database;
and adding an updating identifier to a master database storing the written data.
5. The method of claim 4, wherein the adding of the update identification to the master database storing the write data comprises;
querying the data volume of the written data stored in the master database added with the update identification;
when the data volume does not exceed a preset value, acquiring a data cache library, and storing the written data to the data cache library;
when feedback information fed back by the data cache library and successfully stored is received, deleting the updating identification added by the main database;
and storing the write-in data stored in the data cache library to a standby database.
6. The method according to claim 1, wherein before reading the data to be read from the backup database, further comprising;
acquiring a data cache library, and inquiring data to be read corresponding to the access request from the data cache library;
and when the data to be read is not inquired, reading the data to be read from the standby database.
7. A database access apparatus, the apparatus comprising:
the receiving module is used for receiving an access request sent by a terminal and inquiring a database state identifier according to the access request, wherein the database state identifier is an identifier used for identifying whether the database is operated and separated;
the available database query module is used for acquiring a standby database when the database is determined not to be operated and separated according to the database state identifier;
the first extraction module is used for extracting a data reading identifier corresponding to the standby database and extracting a request operation identifier corresponding to the access request;
the judging module is used for judging whether the request operation identifier is a data reading identifier;
the first access module is used for sending rejection information to the terminal when the request operation identifier is not a data reading identifier; and when the request operation identifier is a data reading identifier, reading the data to be read from the standby database, and feeding back the read data to be read to the terminal.
8. The apparatus of claim 7, further comprising:
the second extraction module is used for extracting a request operation identifier corresponding to the access request when the database is determined to be operated and separated according to the database state identifier;
and the second access module is used for acquiring the database to be accessed according to the request operation identifier and accessing the database to be accessed according to the access request.
9. A computer device comprising a memory and a processor, the memory storing a computer program, wherein the processor implements the steps of the method of any one of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 6.
CN201910849276.XA 2019-09-09 2019-09-09 Database access method and device, computer equipment and storage medium Pending CN110727698A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910849276.XA CN110727698A (en) 2019-09-09 2019-09-09 Database access method and device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910849276.XA CN110727698A (en) 2019-09-09 2019-09-09 Database access method and device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN110727698A true CN110727698A (en) 2020-01-24

Family

ID=69217995

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910849276.XA Pending CN110727698A (en) 2019-09-09 2019-09-09 Database access method and device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110727698A (en)

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112115166A (en) * 2020-08-11 2020-12-22 苏宁云计算有限公司 Data caching method and device, computer equipment and storage medium
CN112800047A (en) * 2021-03-03 2021-05-14 百果园技术(新加坡)有限公司 User associated data processing method, device, equipment and storage medium
CN113282581A (en) * 2021-05-17 2021-08-20 广西南宁天诚智远知识产权服务有限公司 Database data calling method and device
CN113297203A (en) * 2020-07-15 2021-08-24 阿里巴巴集团控股有限公司 Data query and write-in method and device, computer storage medium and electronic equipment
CN114595245A (en) * 2022-03-18 2022-06-07 上海哔哩哔哩科技有限公司 Data processing method and device

Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102402596A (en) * 2011-11-07 2012-04-04 北京搜狗科技发展有限公司 Reading and writing method and system of master slave separation database
CN102591964A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Implementation method and device for data reading-writing splitting system
CN102629903A (en) * 2011-12-21 2012-08-08 奇智软件(北京)有限公司 System and method for disaster recovery in internet application
CN104504145A (en) * 2015-01-05 2015-04-08 浪潮(北京)电子信息产业有限公司 Method and device capable of achieving database reading and writing separation
CN105608229A (en) * 2016-01-29 2016-05-25 锐达互动科技股份有限公司 System and method for synchronizing master-slave databases
CN105991565A (en) * 2015-02-05 2016-10-05 阿里巴巴集团控股有限公司 Reading and writing separation method and system and database agent server
CN106649857A (en) * 2016-12-30 2017-05-10 北京恒华伟业科技股份有限公司 Reading and writing separation-based database operation method and apparatus
CN107122357A (en) * 2016-02-24 2017-09-01 阿里巴巴集团控股有限公司 Data base read-write separation method, device and system
CN107656937A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for realizing read-write data consistency
CN108038157A (en) * 2017-12-05 2018-05-15 北京星河星云信息技术有限公司 Master-slave database reading/writing method, system, storage device and server
CN109213827A (en) * 2017-07-03 2019-01-15 阿里巴巴集团控股有限公司 A kind of data processing system, method, router and from database

Patent Citations (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102402596A (en) * 2011-11-07 2012-04-04 北京搜狗科技发展有限公司 Reading and writing method and system of master slave separation database
CN102629903A (en) * 2011-12-21 2012-08-08 奇智软件(北京)有限公司 System and method for disaster recovery in internet application
CN102591964A (en) * 2011-12-30 2012-07-18 北京新媒传信科技有限公司 Implementation method and device for data reading-writing splitting system
CN104504145A (en) * 2015-01-05 2015-04-08 浪潮(北京)电子信息产业有限公司 Method and device capable of achieving database reading and writing separation
CN105991565A (en) * 2015-02-05 2016-10-05 阿里巴巴集团控股有限公司 Reading and writing separation method and system and database agent server
CN105608229A (en) * 2016-01-29 2016-05-25 锐达互动科技股份有限公司 System and method for synchronizing master-slave databases
CN107122357A (en) * 2016-02-24 2017-09-01 阿里巴巴集团控股有限公司 Data base read-write separation method, device and system
CN107656937A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for realizing read-write data consistency
CN106649857A (en) * 2016-12-30 2017-05-10 北京恒华伟业科技股份有限公司 Reading and writing separation-based database operation method and apparatus
CN109213827A (en) * 2017-07-03 2019-01-15 阿里巴巴集团控股有限公司 A kind of data processing system, method, router and from database
CN108038157A (en) * 2017-12-05 2018-05-15 北京星河星云信息技术有限公司 Master-slave database reading/writing method, system, storage device and server

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
58沈剑: "究竟先操作缓存,还是数据库", 《微信公众平台》 *

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113297203A (en) * 2020-07-15 2021-08-24 阿里巴巴集团控股有限公司 Data query and write-in method and device, computer storage medium and electronic equipment
CN112115166A (en) * 2020-08-11 2020-12-22 苏宁云计算有限公司 Data caching method and device, computer equipment and storage medium
CN112800047A (en) * 2021-03-03 2021-05-14 百果园技术(新加坡)有限公司 User associated data processing method, device, equipment and storage medium
CN112800047B (en) * 2021-03-03 2024-04-05 百果园技术(新加坡)有限公司 User associated data processing method, device, equipment and storage medium
CN113282581A (en) * 2021-05-17 2021-08-20 广西南宁天诚智远知识产权服务有限公司 Database data calling method and device
CN114595245A (en) * 2022-03-18 2022-06-07 上海哔哩哔哩科技有限公司 Data processing method and device

Similar Documents

Publication Publication Date Title
CN110727698A (en) Database access method and device, computer equipment and storage medium
CN110647438B (en) Event monitoring method and device, computer equipment and storage medium
CN108829781B (en) Client information query method, device, computer equipment and storage medium
CN109542961B (en) Data storage method, device, computer equipment and storage medium
CN110750267B (en) Service information updating method, device, computer equipment and storage medium
CN108897638B (en) Data backup method and device, computer equipment and storage medium
CN110602169B (en) Service calling method and device, computer equipment and storage medium
CN108959385B (en) Database deployment method, device, computer equipment and storage medium
CN110795171B (en) Service data processing method, device, computer equipment and storage medium
CN109902272B (en) Electronic form data processing method, electronic form data processing device, computer equipment and storage medium
CN109460252B (en) Configuration file processing method and device based on git and computer equipment
CN108965383B (en) File synchronization method and device, computer equipment and storage medium
CN110633160A (en) Interface calling method and device, computer equipment and storage medium
CN110781214A (en) Database reading and writing method and device, computer equipment and storage medium
CN108255576B (en) Virtual machine live migration exception handling method and device and storage medium
CN110659297A (en) Data processing method, data processing device, computer equipment and storage medium
CN110674145A (en) Data consistency detection method and device, computer equipment and storage medium
CN113626218A (en) Data processing method, data processing device, storage medium and computer equipment
CN112070585A (en) Order state unified management method and device, computer equipment and storage medium
CN113010306A (en) Service data processing method and device, computer equipment and storage medium
CN110457614B (en) Data increment updating method and device for reducing data concurrency and computer equipment
CN115277677A (en) Batch archive hooking method and device, computer equipment and storage medium
CN112783866A (en) Data reading method and device, computer equipment and storage medium
CN113626240A (en) Cluster fault recovery method and device, computer equipment and storage medium
CN112765126A (en) Database transaction management method and device, computer equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20200122

Address after: 200120 floor 15, 1333 Lujiazui Ring Road, China (Shanghai) pilot Free Trade Zone, Pudong New Area, Shanghai

Applicant after: Weikun (Shanghai) Technology Service Co.,Ltd.

Address before: 13th Floor, 1333 Lujiazui Ring Road, Shanghai Free Trade Pilot Area, 200120

Applicant before: SHANGHAI LUJIAZUI INTERNATIONAL FINANCIAL ASSETS TRANSACTION MARKET CO.,LTD.

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
WD01 Invention patent application deemed withdrawn after publication
WD01 Invention patent application deemed withdrawn after publication

Application publication date: 20200124