CN116401104A - Application data source switching method, device, equipment and medium - Google Patents

Application data source switching method, device, equipment and medium Download PDF

Info

Publication number
CN116401104A
CN116401104A CN202310391791.4A CN202310391791A CN116401104A CN 116401104 A CN116401104 A CN 116401104A CN 202310391791 A CN202310391791 A CN 202310391791A CN 116401104 A CN116401104 A CN 116401104A
Authority
CN
China
Prior art keywords
database
data source
user side
mysql database
sqllite
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
CN202310391791.4A
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.)
Guangdong Industrial Edge Intelligent Innovation Center Co ltd
Original Assignee
Guangdong Industrial Edge Intelligent Innovation Center Co 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 Guangdong Industrial Edge Intelligent Innovation Center Co ltd filed Critical Guangdong Industrial Edge Intelligent Innovation Center Co ltd
Priority to CN202310391791.4A priority Critical patent/CN116401104A/en
Publication of CN116401104A publication Critical patent/CN116401104A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/16Error detection or correction of the data by redundancy in hardware
    • G06F11/20Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements
    • G06F11/202Error detection or correction of the data by redundancy in hardware using active fault-masking, e.g. by switching out faulty elements or by switching in spare elements where processing functionality is redundant
    • G06F11/2023Failover techniques
    • G06F11/2033Failover techniques switching over of hardware resources
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3055Monitoring arrangements for monitoring the status of the computing system or of the computing system component, e.g. monitoring if the computing system is on, off, available, not available
    • 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/28Databases characterised by their database models, e.g. relational or object models
    • G06F16/284Relational databases
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The invention relates to the technical field of Internet, and provides an application data source switching method, device, equipment and medium, which can detect whether the access of a user side to a MySQL database is abnormal or not in real time so as to respond in time when the access abnormality is detected, acquire an SQLlite database deployed at the user side according to a data source switching instruction when the access abnormality of the user side to the MySQL database is detected, acquire a target database identifier of the SQLlite database, load a target configuration file according to the target database identifier, automatically switch the data source of the user side from the MySQL database to the SQLlite database according to the target configuration file, and further automatically and quickly switch the data source to the SQLlite database deployed locally at the user side when the access abnormality to the MySQL database is detected, so that the user side normally executes operation and realizes flexible switching of data sources.

Description

Application data source switching method, device, equipment and medium
Technical Field
The present invention relates to the field of internet technologies, and in particular, to a method, an apparatus, a device, and a medium for switching application data sources.
Background
The MySQL database is used as a main stream database, is free from open sources, has higher market utilization rate, and is especially preferred in most network hosting environments such as cloud hosts, servers and the like.
However, due to the dependence of the MySQL database on the cloud host, the server and the like, once no network or the cloud host, the server and the like have faults in the use process, the MySQL database cannot be accessed in a connection manner, and related business data are acquired for use.
Disclosure of Invention
In view of the above, it is necessary to provide a method, a device, and a medium for switching application data sources, which are aimed at solving the problem that the user cannot normally acquire and use data when accessing the MySQL database abnormally.
An application data source switching method, the application data source switching method comprising:
detecting whether the access of a user side to the MySQL database is abnormal or not in real time;
triggering a data source switching instruction of the user side when detecting that the user side accesses the MySQL database abnormally;
according to the data source switching instruction, acquiring an SQLlite database deployed at the user terminal, and acquiring a target database identifier of the SQLlite database;
loading a target configuration file according to the target database identifier;
and switching the data source of the user terminal from the MySQL database to the SQLlite database according to the target configuration file.
According to a preferred embodiment of the invention, the method further comprises:
when detecting that the access of the user side to the MySQL database is not abnormal, synchronizing the data of the user side stored in the MySQL database and the data of the user side stored in the SQLlite database at preset time intervals according to a preset data synchronization strategy.
According to a preferred embodiment of the present invention, the detecting whether the access of the user side to the MySQL database is abnormal in real time includes:
when detecting that the user side operates based on the MySQL database, detecting whether network connection of the MySQL database is abnormal or not in real time;
when detecting network connection abnormality of the MySQL database, determining that the access of the user side to the MySQL database is abnormal; or alternatively
When the network connection of the MySQL database is detected to be normal, a target time period is obtained by tracing back a preset time period from a current time point, the abnormal response times and average response time period of the request of the MySQL database in the target time period are obtained, a current scene is obtained, the time threshold and the time threshold corresponding to the target time period in the current scene are obtained, and when the abnormal response times are greater than the time threshold and/or the average response time period is greater than the time threshold, the abnormal access of the user side to the MySQL database is determined; or when the abnormal response times are smaller than or equal to the times threshold and the average response time is smaller than or equal to the time threshold, determining that the user side has normal access to the MySQL database;
The time threshold and the duration threshold are used for configuring historical access data of the MySQL database in different time periods according to different scenes.
According to a preferred embodiment of the present invention, the triggering the data source switching instruction to the user terminal includes:
acquiring the target database identifier of the SQLlite database deployed at the user terminal;
configuring a connection cutting instruction for the MySQL database;
and generating the data source switching instruction according to the target database identifier and the disconnection instruction.
According to a preferred embodiment of the present invention, the loading the target configuration file according to the target database identifier includes:
acquiring a plurality of configuration files stored in the user side;
acquiring a configuration file with the target database identifier from the plurality of configuration files as the target configuration file;
loading the target configuration file;
wherein the target profile includes a combination of one or more of the following information: the method comprises the steps of driving information of the SQLlite database, database connection information of the SQLlite database, a method for indicating package service logic processing of the SQLlite database and data attribute information.
According to a preferred embodiment of the present invention, after the switching the data source of the client from the MySQL database to the SQLlite database according to the target configuration file, the method further includes:
when the operation triggered on the user side is detected, performing read-write operation on the SQLlite database according to the detected operation.
According to a preferred embodiment of the present invention, after the switching the data source of the client from the MySQL database to the SQLlite database according to the target configuration file, the method further includes:
when the network connection of the MySQL database is detected to be recovered normally, generating a confirmation request whether to switch the data source of the user side from the SQLlite database to the MySQL database, sending the confirmation request to a configuration terminal, and when a confirmation signal fed back by the configuration terminal to the confirmation request is received, switching the data source of the user side from the SQLlite database to the MySQL database; or alternatively
When a request triggered by a user to restore and switch the data source of the user terminal from the SQLlite database to the MySQL database is received, restoring and switching the data source of the user terminal from the SQLlite database to the MySQL database.
An application data source switching apparatus, the application data source switching apparatus comprising:
the detection unit is used for detecting whether the access of the user side to the MySQL database is abnormal or not in real time;
the triggering unit is used for triggering a data source switching instruction of the user side when detecting that the user side accesses the MySQL database abnormally;
the acquisition unit is used for acquiring the SQLlite database deployed at the user terminal according to the data source switching instruction and acquiring a target database identifier of the SQLlite database;
the loading unit is used for loading the target configuration file according to the target database identifier;
and the switching unit is used for switching the data source of the user terminal from the MySQL database to the SQLlite database according to the target configuration file.
A computer device, the computer device comprising:
a memory storing at least one instruction; a kind of electronic device with high-pressure air-conditioning system
And the processor executes the instructions stored in the memory to realize the application data source switching method.
A computer-readable storage medium having stored therein at least one instruction for execution by a processor in a computer device to implement the application data source switching method.
According to the technical scheme, whether the access of the user side to the MySQL database is abnormal or not can be detected in real time, so that the user side can respond in time when the access abnormality is detected, when the access abnormality of the user side to the MySQL database is detected, the SQLlite database deployed at the user side is obtained according to the data source switching instruction, the target database identification of the SQLlite database is obtained, the target configuration file is loaded according to the target database identification, the data source of the user side is automatically switched to the SQLlite database from the MySQL database according to the target configuration file, and further the user side can automatically and quickly switch to the SQLlite database deployed locally at the user side when the access abnormality to the MySQL database is detected, so that the user side can normally execute operation, and flexible switching of the data source is realized.
Drawings
FIG. 1 is a flow chart of a preferred embodiment of the present invention for applying a data source switching method.
FIG. 2 is a functional block diagram of a preferred embodiment of the application data source switching device of the present invention.
Fig. 3 is a schematic structural diagram of a computer device implementing a preferred embodiment of the application data source switching method according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention will be described in detail with reference to the accompanying drawings and specific embodiments.
FIG. 1 is a flow chart of a preferred embodiment of the present invention for applying a data source switching method. The order of the steps in the flowchart may be changed and some steps may be omitted according to various needs.
The application data source switching method is applied to one or more computer devices, wherein the computer device is a device capable of automatically performing numerical calculation and/or information processing according to preset or stored instructions, and the hardware of the computer device comprises, but is not limited to, a microprocessor, an application specific integrated circuit (Application Specific Integrated Circuit, an ASIC), a programmable gate array (Field-Programmable Gate Array, FPGA), a digital processor (Digital Signal Processor, DSP), an embedded device and the like.
The computer device may be any electronic product that can interact with a user in a human-computer manner, such as a personal computer, tablet computer, smart phone, personal digital assistant (Personal Digital Assistant, PDA), game console, interactive internet protocol television (Internet Protocol Television, IPTV), smart wearable device, etc.
The computer device may also include a network device and/or a user device. Wherein the network device includes, but is not limited to, a single network server, a server group composed of a plurality of network servers, or a Cloud based Cloud Computing (Cloud Computing) composed of a large number of hosts or network servers.
The server may be an independent server, or may be a cloud server that provides cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and basic cloud computing services such as big data and artificial intelligence platforms.
Among these, artificial intelligence (Artificial Intelligence, AI) is the theory, method, technique and application system that uses a digital computer or a digital computer-controlled machine to simulate, extend and extend human intelligence, sense the environment, acquire knowledge and use knowledge to obtain optimal results.
Artificial intelligence infrastructure technologies generally include technologies such as sensors, dedicated artificial intelligence chips, cloud computing, distributed storage, big data processing technologies, operation/interaction systems, mechatronics, and the like. The artificial intelligence software technology mainly comprises a computer vision technology, a robot technology, a biological recognition technology, a voice processing technology, a natural language processing technology, machine learning/deep learning and other directions.
The network in which the computer device is located includes, but is not limited to, the internet, a wide area network, a metropolitan area network, a local area network, a virtual private network (Virtual Private Network, VPN), and the like.
S10, detecting whether the access of the user side to the MySQL database is abnormal or not in real time.
The MySQL database can be deployed in a network hosting environment such as a cloud host and a server, and the user side can be connected to the cloud host or the server so as to read data from the MySQL database.
In this embodiment, the detecting, in real time, whether the access of the user side to the MySQL database is abnormal includes:
when detecting that the user side operates based on the MySQL database, detecting whether network connection of the MySQL database is abnormal or not in real time;
when detecting network connection abnormality of the MySQL database, determining that the access of the user side to the MySQL database is abnormal; or alternatively
When the network connection of the MySQL database is detected to be normal, a target time period is obtained by tracing back a preset time period from a current time point, the abnormal response times and average response time period of the request of the MySQL database in the target time period are obtained, a current scene is obtained, the time threshold and the time threshold corresponding to the target time period in the current scene are obtained, and when the abnormal response times are greater than the time threshold and/or the average response time period is greater than the time threshold, the abnormal access of the user side to the MySQL database is determined; or when the abnormal response times are smaller than or equal to the times threshold and the average response time is smaller than or equal to the time threshold, determining that the user side has normal access to the MySQL database;
The time threshold and the duration threshold are used for configuring historical access data of the MySQL database in different time periods according to different scenes.
The user side can perform operations such as adding, deleting, checking and the like based on the MySQL database.
The network connection of the MySQL database can be detected in real time by adopting a manner of wirehark packet capturing and the like.
The preset duration may be configured according to actual requirements, for example: when the preset time is 5 minutes and the current time point is 9 points, tracing back for 5 minutes from the current time point 9 points, and obtaining the target time period of 8:55-9:00.
The time threshold and the duration threshold can be configured according to historical access data of the MySQL database in different time periods in different scenes, and different time thresholds and duration thresholds can be configured in different time periods in different scenes. For example: under the scene of high network bandwidth, because the network bandwidth directly influences the network delay length, different range sections to which the network bandwidth belongs correspond to different thresholds, and the corresponding thresholds can be determined according to dynamic matching of the scene in the current time section. In a high network bandwidth scenario, the access time can be divided into a plurality of time periods such as an access peak period, an access valley period, a normal access period and the like according to the height of the access amount, average abnormal response times and average response time in each time period are calculated, and the average abnormal response times and the average response time in each time period are determined as a time threshold and a time threshold corresponding to each time period.
The time threshold and the time threshold corresponding to each time period can be stored in the user side in a mapping table mode, so that the corresponding time period is directly utilized to match in the mapping table when the user side needs to use the user side, and the time threshold corresponding to the current time period can be obtained.
Through the embodiment, in the process of using the MySQL database, the network connection condition, the abnormal response times and the average response time are sequentially detected, so that whether the access of the user side to the MySQL database is abnormal or not can be automatically detected from multiple dimensions.
It can be understood that, in order to enable the user terminal to use the data normally after the switching, and not generate the situation of abnormal data access, a certain consistency needs to be maintained between the MySQL database and the data in the sqlite database.
Specifically, the method further comprises:
when detecting that the access of the user side to the MySQL database is not abnormal, synchronizing the data of the user side stored in the MySQL database and the data of the user side stored in the SQLlite database at preset time intervals according to a preset data synchronization strategy.
The SQLlite database is a lightweight relational database management system, is an SQL (Structured Query Language ) database engine without a server, and can be connected statically or dynamically according to the requirement of an application program, and can directly read and write storage files of the database. Therefore, even if no network or other abnormal conditions exist, the SQLlite database can be read and written.
The preset time interval can be configured in a self-defined manner.
Of course, when detecting that the specified data in the MySQL database changes, the changed data increment may be updated to the sql lite database.
The data synchronization policy may specify data to be synchronized, such as key service data, and may be specifically configured according to actual use requirements.
S11, triggering a data source switching instruction of the user side when detecting that the user side accesses the MySQL database abnormally.
In this embodiment, the data source switching instruction of the triggering to the user terminal includes:
acquiring the target database identifier of the SQLlite database deployed at the user terminal;
Configuring a connection cutting instruction for the MySQL database;
and generating the data source switching instruction according to the target database identifier and the disconnection instruction.
Wherein the SQLlite database can be uniquely marked by the target database identification.
And triggering a data source switching instruction to the user side, and cutting off the connection with the MySQL database so as to connect to the SQLlite database which has the target database identifier and is deployed locally at the user side.
S12, acquiring the SQLlite database deployed at the user terminal according to the data source switching instruction, and acquiring a target database identifier of the SQLlite database.
In this embodiment, the data source switching instruction may be parsed to obtain information carried by the data source switching instruction, and the sql lite database and the target database identifier may be obtained from the information carried by the data source switching instruction.
S13, loading the target configuration file according to the target database identification.
In this embodiment, the loading the target configuration file according to the target database identifier includes:
acquiring a plurality of configuration files stored in the user side;
Acquiring a configuration file with the target database identifier from the plurality of configuration files as the target configuration file;
loading the target configuration file;
wherein the target profile includes a combination of one or more of the following information: the method comprises the steps of driving information of the SQLlite database, database connection information of the SQLlite database, a method for indicating package service logic processing of the SQLlite database and data attribute information.
The configuration files are files which are written in advance and stored in the user side, and corresponding database identifiers can be marked for each configuration file in the storage process, so that matching and calling can be directly carried out according to the database identifiers in the subsequent use, and the efficiency of switching data sources is improved.
Wherein, the database connection information of the sqlite database may include, but is not limited to: database names, connection passwords, and the like of the sql lite database.
Wherein the data attribute information may include a data type, a data structure, and the like.
S14, switching the data source of the user terminal from the MySQL database to the SQLlite database according to the target configuration file.
It will be appreciated that the MySQL database is deployed on a cloud host or server, where the amount of data storage is large, but access to the MySQL database needs to rely on the cloud host or server. The SQLlite database is deployed locally on the user side, namely the SQLlite database is embedded into the user side local equipment for installation, is a lightweight database, and has small stored data volume. Therefore, the client is preferentially connected to the MySQL database.
However, when the access to the MySQL database is abnormal, the data source can be quickly switched from the MySQL database to the SQLlite database, so that the automatic switching of the data source is realized, and when the MySQL database cannot be accessed due to no network or cloud host, server faults and the like, no code is required to be modified, the local SQLlite database is accessed through direct connection of the client application, the problem that relevant service data cannot be acquired to perform data read-write operation when the MySQL database is abnormal is solved, and the application flexibility is improved.
In this embodiment, after the switching the data source of the client from the MySQL database to the SQLlite database according to the target configuration file, the method further includes:
When the operation triggered on the user side is detected, performing read-write operation on the SQLlite database according to the detected operation.
The operation triggered on the user terminal may include operations such as adding, deleting, checking, etc.
Through the embodiment, the data source of the user terminal can be automatically switched to the SQLlite database under the condition of abnormal access to the MySQL database or no server and the like, so that the problem that the user terminal application cannot normally operate is solved, the user terminal service is normally executed and is in seamless connection, and the application flexibility is improved.
It can be appreciated that, since the data volume of the MySQL database is higher than that of the sql lite database, in order to ensure that the application at the user end is used normally, it is also necessary to switch back to the connection with the MySQL database when the MySQL database is restored, so as to optimize access to data.
Specifically, after the switching the data source of the user terminal from the MySQL database to the SQLlite database according to the target configuration file, the method further includes:
when the network connection of the MySQL database is detected to be recovered to be normal, generating a confirmation request whether to recover and switch the data source of the user side from the SQLlite database to the MySQL database, sending the confirmation request to a configuration terminal, and when a confirmation signal fed back by the configuration terminal to the confirmation request is received, recovering and switching the data source of the user side from the SQLlite database to the MySQL database. For example: the configuration terminal can be terminal equipment of relevant staff, when the network connection of the MySQL database is detected to be recovered to be normal, the factor influencing whether the switching is successful is not only whether a network exists, so that the relevant staff can be further prompted to confirm whether the switching can be recovered to be connected to the MySQL database, and after an explicit confirmation signal is received, the switching is executed again, and switching failure is avoided.
Or when receiving a request triggered by a user to restore and switch the data source of the user terminal from the SQLlite database to the MySQL database, restoring and switching the data source of the user terminal from the SQLlite database to the MySQL database. For example: when the worker determines that the access to the MySQL database can be recovered, the worker actively triggers a request, and at the moment, the data source of the user side can be recovered and switched from the SQLlite database to the MySQL database.
By the embodiment, the automatic switching between the data sources can be realized, and the flexibility of the data source access is improved.
According to the technical scheme, whether the access of the user side to the MySQL database is abnormal or not can be detected in real time, so that the user side can respond in time when the access abnormality is detected, when the access abnormality of the user side to the MySQL database is detected, the SQLlite database deployed at the user side is obtained according to the data source switching instruction, the target database identification of the SQLlite database is obtained, the target configuration file is loaded according to the target database identification, the data source of the user side is automatically switched to the SQLlite database from the MySQL database according to the target configuration file, and further the user side can automatically and quickly switch to the SQLlite database deployed locally at the user side when the access abnormality to the MySQL database is detected, so that the user side can normally execute operation, and flexible switching of the data source is realized.
FIG. 2 is a functional block diagram of a preferred embodiment of the application data source switching device of the present invention. The application data source switching device 11 comprises a detection unit 110, a triggering unit 111, an acquisition unit 112, a loading unit 113 and a switching unit 114. The module/unit referred to in the present invention refers to a series of computer program segments, which are stored in a memory, capable of being executed by a processor and of performing a fixed function. In the present embodiment, the functions of the respective modules/units will be described in detail in the following embodiments.
The detecting unit 110 is configured to detect in real time whether the access of the user side to the MySQL database is abnormal.
The MySQL database can be deployed in a network hosting environment such as a cloud host and a server, and the user side can be connected to the cloud host or the server so as to read data from the MySQL database.
In this embodiment, the detecting unit 110 detects in real time whether the access of the user side to the MySQL database is abnormal, including:
when detecting that the user side operates based on the MySQL database, detecting whether network connection of the MySQL database is abnormal or not in real time;
when detecting network connection abnormality of the MySQL database, determining that the access of the user side to the MySQL database is abnormal; or alternatively
When the network connection of the MySQL database is detected to be normal, a target time period is obtained by tracing back a preset time period from a current time point, the abnormal response times and average response time period of the request of the MySQL database in the target time period are obtained, a current scene is obtained, the time threshold and the time threshold corresponding to the target time period in the current scene are obtained, and when the abnormal response times are greater than the time threshold and/or the average response time period is greater than the time threshold, the abnormal access of the user side to the MySQL database is determined; or when the abnormal response times are smaller than or equal to the times threshold and the average response time is smaller than or equal to the time threshold, determining that the user side has normal access to the MySQL database;
the time threshold and the duration threshold are used for configuring historical access data of the MySQL database in different time periods according to different scenes.
The user side can perform operations such as adding, deleting, checking and the like based on the MySQL database.
The network connection of the MySQL database can be detected in real time by adopting a manner of wirehark packet capturing and the like.
The preset duration may be configured according to actual requirements, for example: when the preset time is 5 minutes and the current time point is 9 points, tracing back for 5 minutes from the current time point 9 points, and obtaining the target time period of 8:55-9:00.
The time threshold and the duration threshold can be configured according to historical access data of the MySQL database in different time periods in different scenes, and different time thresholds and duration thresholds can be configured in different time periods in different scenes. For example: under the scene of high network bandwidth, because the network bandwidth directly influences the network delay length, different range sections to which the network bandwidth belongs correspond to different thresholds, and the corresponding thresholds can be determined according to dynamic matching of the scene in the current time section. In a high network bandwidth scenario, the access time can be divided into a plurality of time periods such as an access peak period, an access valley period, a normal access period and the like according to the height of the access amount, average abnormal response times and average response time in each time period are calculated, and the average abnormal response times and the average response time in each time period are determined as a time threshold and a time threshold corresponding to each time period.
The time threshold and the time threshold corresponding to each time period can be stored in the user side in a mapping table mode, so that the corresponding time period is directly utilized to match in the mapping table when the user side needs to use the user side, and the time threshold corresponding to the current time period can be obtained.
Through the embodiment, in the process of using the MySQL database, the network connection condition, the abnormal response times and the average response time are sequentially detected, so that whether the access of the user side to the MySQL database is abnormal or not can be automatically detected from multiple dimensions.
It can be understood that, in order to enable the user terminal to use the data normally after the switching, and not generate the situation of abnormal data access, a certain consistency needs to be maintained between the MySQL database and the data in the sqlite database.
Specifically, when no abnormality of the access of the user side to the MySQL database is detected, synchronizing the data of the user side stored in the MySQL database and the data of the user side stored in the sql lite database at preset time intervals according to a pre-configured data synchronization policy.
The SQLlite database is a lightweight relational database management system, is an SQL (Structured Query Language ) database engine without a server, and can be connected statically or dynamically according to the requirement of an application program, and can directly read and write storage files of the database. Therefore, even if no network or other abnormal conditions exist, the SQLlite database can be read and written.
The preset time interval can be configured in a self-defined manner.
Of course, when detecting that the specified data in the MySQL database changes, the changed data increment may be updated to the sql lite database.
The data synchronization policy may specify data to be synchronized, such as key service data, and may be specifically configured according to actual use requirements.
The triggering unit 111 is configured to trigger a data source switching instruction to the user side when detecting that the user side accesses the MySQL database abnormally.
In this embodiment, the triggering unit 111 triggers a data source switching instruction to the user side, including:
acquiring the target database identifier of the SQLlite database deployed at the user terminal;
configuring a connection cutting instruction for the MySQL database;
and generating the data source switching instruction according to the target database identifier and the disconnection instruction.
Wherein the SQLlite database can be uniquely marked by the target database identification.
And triggering a data source switching instruction to the user side, and cutting off the connection with the MySQL database so as to connect to the SQLlite database which has the target database identifier and is deployed locally at the user side.
The obtaining unit 112 is configured to obtain, according to the data source switching instruction, an sql lite database deployed at the user terminal, and obtain a target database identifier of the sql lite database.
In this embodiment, the data source switching instruction may be parsed to obtain information carried by the data source switching instruction, and the sql lite database and the target database identifier may be obtained from the information carried by the data source switching instruction.
The loading unit 113 is configured to load a target configuration file according to the target database identifier.
In this embodiment, the loading unit 113 loads the target configuration file according to the target database identifier, including:
acquiring a plurality of configuration files stored in the user side;
acquiring a configuration file with the target database identifier from the plurality of configuration files as the target configuration file;
loading the target configuration file;
wherein the target profile includes a combination of one or more of the following information: the method comprises the steps of driving information of the SQLlite database, database connection information of the SQLlite database, a method for indicating package service logic processing of the SQLlite database and data attribute information.
The configuration files are files which are written in advance and stored in the user side, and corresponding database identifiers can be marked for each configuration file in the storage process, so that matching and calling can be directly carried out according to the database identifiers in the subsequent use, and the efficiency of switching data sources is improved.
Wherein, the database connection information of the sqlite database may include, but is not limited to: database names, connection passwords, and the like of the sql lite database.
Wherein the data attribute information may include a data type, a data structure, and the like.
The switching unit 114 is configured to switch the data source of the client from the MySQL database to the sqrlite database according to the target configuration file.
It will be appreciated that the MySQL database is deployed on a cloud host or server, where the amount of data storage is large, but access to the MySQL database needs to rely on the cloud host or server. The SQLlite database is deployed locally on the user side, namely the SQLlite database is embedded into the user side local equipment for installation, is a lightweight database, and has small stored data volume. Therefore, the client is preferentially connected to the MySQL database.
However, when the access to the MySQL database is abnormal, the data source can be quickly switched from the MySQL database to the SQLlite database, so that the automatic switching of the data source is realized, and when the MySQL database cannot be accessed due to no network or cloud host, server faults and the like, no code is required to be modified, the local SQLlite database is accessed through direct connection of the client application, the problem that relevant service data cannot be acquired to perform data read-write operation when the MySQL database is abnormal is solved, and the application flexibility is improved.
In this embodiment, after the data source of the user terminal is switched from the MySQL database to the sql lite database according to the target configuration file, when an operation triggered on the user terminal is detected, a read-write operation is performed on the sql lite database according to the detected operation.
The operation triggered on the user terminal may include operations such as adding, deleting, checking, etc.
Through the embodiment, the data source of the user terminal can be automatically switched to the SQLlite database under the condition of abnormal access to the MySQL database or no server and the like, so that the problem that the user terminal application cannot normally operate is solved, the user terminal service is normally executed and is in seamless connection, and the application flexibility is improved.
It can be appreciated that, since the data volume of the MySQL database is higher than that of the sql lite database, in order to ensure that the application at the user end is used normally, it is also necessary to switch back to the connection with the MySQL database when the MySQL database is restored, so as to optimize access to data.
Specifically, after the data source of the user terminal is switched from the MySQL database to the sql lite database according to the target configuration file, when the network connection of the MySQL database is detected to be recovered and normal, a confirmation request for recovering and switching the data source of the user terminal from the sql lite database to the MySQL database is generated, the confirmation request is sent to a configuration terminal, and when a confirmation signal fed back by the configuration terminal for the confirmation request is received, the data source of the user terminal is recovered and switched from the sql lite database to the MySQL database. For example: the configuration terminal can be terminal equipment of relevant staff, when the network connection of the MySQL database is detected to be recovered to be normal, the factor influencing whether the switching is successful is not only whether a network exists, so that the relevant staff can be further prompted to confirm whether the switching can be recovered to be connected to the MySQL database, and after an explicit confirmation signal is received, the switching is executed again, and switching failure is avoided.
Or when receiving a request triggered by a user to restore and switch the data source of the user terminal from the SQLlite database to the MySQL database, restoring and switching the data source of the user terminal from the SQLlite database to the MySQL database. For example: when the worker determines that the access to the MySQL database can be recovered, the worker actively triggers a request, and at the moment, the data source of the user side can be recovered and switched from the SQLlite database to the MySQL database.
By the embodiment, the automatic switching between the data sources can be realized, and the flexibility of the data source access is improved.
According to the technical scheme, whether the access of the user side to the MySQL database is abnormal or not can be detected in real time, so that the user side can respond in time when the access abnormality is detected, when the access abnormality of the user side to the MySQL database is detected, the SQLlite database deployed at the user side is obtained according to the data source switching instruction, the target database identification of the SQLlite database is obtained, the target configuration file is loaded according to the target database identification, the data source of the user side is automatically switched to the SQLlite database from the MySQL database according to the target configuration file, and further the user side can automatically and quickly switch to the SQLlite database deployed locally at the user side when the access abnormality to the MySQL database is detected, so that the user side can normally execute operation, and flexible switching of the data source is realized.
Fig. 3 is a schematic structural diagram of a computer device according to a preferred embodiment of the present invention for implementing the application data source switching method.
The computer device 1 may comprise a memory 12, a processor 13 and a bus, and may further comprise a computer program, such as an application data source switching program, stored in the memory 12 and executable on the processor 13.
It will be appreciated by those skilled in the art that the schematic diagram is merely an example of the computer device 1 and does not constitute a limitation of the computer device 1, the computer device 1 may be a bus type structure, a star type structure, the computer device 1 may further comprise more or less other hardware or software than illustrated, or a different arrangement of components, for example, the computer device 1 may further comprise an input-output device, a network access device, etc.
It should be noted that the computer device 1 is only used as an example, and other electronic products that may be present in the present invention or may be present in the future are also included in the scope of the present invention by way of reference.
The memory 12 includes at least one type of readable storage medium including flash memory, a removable hard disk, a multimedia card, a card memory (e.g., SD or DX memory, etc.), a magnetic memory, a magnetic disk, an optical disk, etc. The memory 12 may in some embodiments be an internal storage unit of the computer device 1, such as a removable hard disk of the computer device 1. The memory 12 may in other embodiments also be an external storage device of the computer device 1, such as a plug-in mobile hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card) or the like, which are provided on the computer device 1. Further, the memory 12 may also include both an internal storage unit and an external storage device of the computer device 1. The memory 12 may be used not only for storing application software installed in the computer device 1 and various types of data, such as code of an application data source switching program, but also for temporarily storing data that has been output or is to be output.
The processor 13 may be comprised of integrated circuits in some embodiments, for example, a single packaged integrated circuit, or may be comprised of multiple integrated circuits packaged with the same or different functions, including one or more central processing units (Central Processing unit, CPU), microprocessors, digital processing chips, graphics processors, a combination of various control chips, and the like. The processor 13 is a Control Unit (Control Unit) of the computer device 1, connects the respective components of the entire computer device 1 using various interfaces and lines, executes programs or modules stored in the memory 12 (for example, executes an application data source switching program, etc.), and invokes data stored in the memory 12 to perform various functions of the computer device 1 and process data.
The processor 13 executes the operating system of the computer device 1 and various types of applications installed. The processor 13 executes the application program to implement the steps of the various application data source switching method embodiments described above, such as the steps shown in fig. 1.
Illustratively, the computer program may be partitioned into one or more modules/units that are stored in the memory 12 and executed by the processor 13 to complete the present invention. The one or more modules/units may be a series of computer readable instruction segments capable of performing the specified functions, which instruction segments describe the execution of the computer program in the computer device 1. For example, the computer program may be divided into a detection unit 110, a trigger unit 111, an acquisition unit 112, a loading unit 113, a switching unit 114.
The integrated units implemented in the form of software functional modules described above may be stored in a computer readable storage medium. The software functional module is stored in a storage medium, and includes several instructions for causing a computer device (which may be a personal computer, a computer device, or a network device, etc.) or a processor (processor) to execute portions of the application data source switching method according to the embodiments of the present invention.
The modules/units integrated in the computer device 1 may be stored in a computer readable storage medium if implemented in the form of software functional units and sold or used as separate products. Based on this understanding, the present invention may also be implemented by a computer program for instructing a relevant hardware device to implement all or part of the procedures of the above-mentioned embodiment method, where the computer program may be stored in a computer readable storage medium and the computer program may be executed by a processor to implement the steps of each of the above-mentioned method embodiments.
Wherein the computer program comprises computer program code which may be in source code form, object code form, executable file or some intermediate form etc. The computer readable medium may include: any entity or device capable of carrying the computer program code, a recording medium, a U disk, a removable hard disk, a magnetic disk, an optical disk, a computer Memory, a Read-Only Memory (ROM), a random access Memory, or the like.
Further, the computer-readable storage medium may mainly include a storage program area and a storage data area, wherein the storage program area may store an operating system, an application program required for at least one function, and the like; the storage data area may store data created from the use of blockchain nodes, and the like.
The blockchain is a novel application mode of computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, encryption algorithm and the like. The Blockchain (Blockchain), which is essentially a decentralised database, is a string of data blocks that are generated by cryptographic means in association, each data block containing a batch of information of network transactions for verifying the validity of the information (anti-counterfeiting) and generating the next block. The blockchain may include a blockchain underlying platform, a platform product services layer, an application services layer, and the like.
The bus may be a peripheral component interconnect standard (peripheral component interconnect, PCI) bus or an extended industry standard architecture (extended industry standard architecture, EISA) bus, among others. The bus may be classified as an address bus, a data bus, a control bus, etc. For ease of illustration, only one straight line is shown in fig. 3, but not only one bus or one type of bus. The bus is arranged to enable a connection communication between the memory 12 and at least one processor 13 or the like.
Although not shown, the computer device 1 may further comprise a power source (such as a battery) for powering the various components, preferably the power source may be logically connected to the at least one processor 13 via a power management means, whereby the functions of charge management, discharge management, and power consumption management are achieved by the power management means. The power supply may also include one or more of any of a direct current or alternating current power supply, recharging device, power failure detection circuit, power converter or inverter, power status indicator, etc. The computer device 1 may further include various sensors, bluetooth modules, wi-Fi modules, etc., which will not be described in detail herein.
Further, the computer device 1 may also comprise a network interface, optionally comprising a wired interface and/or a wireless interface (e.g. WI-FI interface, bluetooth interface, etc.), typically used for establishing a communication connection between the computer device 1 and other computer devices.
The computer device 1 may optionally further comprise a user interface, which may be a Display, an input unit, such as a Keyboard (Keyboard), or a standard wired interface, a wireless interface. Alternatively, in some embodiments, the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an OLED (Organic Light-Emitting Diode) touch, or the like. The display may also be referred to as a display screen or display unit, as appropriate, for displaying information processed in the computer device 1 and for displaying a visual user interface.
It should be understood that the embodiments described are for illustrative purposes only and are not limited to this configuration in the scope of the patent application.
Fig. 3 shows only a computer device 1 with components 12-13, it being understood by those skilled in the art that the structure shown in fig. 3 is not limiting of the computer device 1 and may include fewer or more components than shown, or may combine certain components, or a different arrangement of components.
In connection with fig. 1, the memory 12 in the computer device 1 stores a plurality of instructions to implement an application data source switching method, the processor 13 being executable to implement:
detecting whether the access of a user side to the MySQL database is abnormal or not in real time;
triggering a data source switching instruction of the user side when detecting that the user side accesses the MySQL database abnormally;
according to the data source switching instruction, acquiring an SQLlite database deployed at the user terminal, and acquiring a target database identifier of the SQLlite database;
loading a target configuration file according to the target database identifier;
and switching the data source of the user terminal from the MySQL database to the SQLlite database according to the target configuration file.
Specifically, the specific implementation method of the above instructions by the processor 13 may refer to the description of the relevant steps in the corresponding embodiment of fig. 1, which is not repeated herein.
The data in this case were obtained legally.
In the several embodiments provided in the present invention, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the modules is merely a logical function division, and there may be other manners of division when actually implemented.
The invention is operational with numerous general purpose or special purpose computer system environments or configurations. For example: personal computers, server computers, hand-held or portable devices, tablet devices, multiprocessor systems, microprocessor-based systems, set top boxes, programmable consumer electronics, network PCs, minicomputers, mainframe computers, distributed computing environments that include any of the above systems or devices, and the like. The invention may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The invention may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The modules described as separate components may or may not be physically separate, and components shown as modules may or may not be physical units, may be located in one place, or may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional module in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units can be realized in a form of hardware or a form of hardware and a form of software functional modules.
It will be evident to those skilled in the art that the invention is not limited to the details of the foregoing illustrative embodiments, and that the present invention may be embodied in other specific forms without departing from the spirit or essential characteristics thereof.
The present embodiments are, therefore, to be considered in all respects as illustrative and not restrictive, the scope of the invention being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference signs in the claims shall not be construed as limiting the claim concerned.
Furthermore, it is evident that the word "comprising" does not exclude other elements or steps, and that the singular does not exclude a plurality. The units or means stated in the invention may also be implemented by one unit or means, either by software or hardware. The terms first, second, etc. are used to denote a name, but not any particular order.
Finally, it should be noted that the above-mentioned embodiments are merely for illustrating the technical solution of the present invention and not for limiting the same, and although the present invention has been described in detail with reference to the preferred embodiments, it should be understood by those skilled in the art that modifications and equivalents may be made to the technical solution of the present invention without departing from the spirit and scope of the technical solution of the present invention.

Claims (10)

1. An application data source switching method is characterized by comprising the following steps:
detecting whether the access of a user side to the MySQL database is abnormal or not in real time;
triggering a data source switching instruction of the user side when detecting that the user side accesses the MySQL database abnormally;
according to the data source switching instruction, acquiring an SQLlite database deployed at the user terminal, and acquiring a target database identifier of the SQLlite database;
Loading a target configuration file according to the target database identifier;
and switching the data source of the user terminal from the MySQL database to the SQLlite database according to the target configuration file.
2. The application data source switching method of claim 1, wherein the method further comprises:
when detecting that the access of the user side to the MySQL database is not abnormal, synchronizing the data of the user side stored in the MySQL database and the data of the user side stored in the SQLlite database at preset time intervals according to a preset data synchronization strategy.
3. The application data source switching method of claim 1, wherein the detecting whether the access of the user side to the MySQL database is abnormal in real time comprises:
when detecting that the user side operates based on the MySQL database, detecting whether network connection of the MySQL database is abnormal or not in real time;
when detecting network connection abnormality of the MySQL database, determining that the access of the user side to the MySQL database is abnormal; or alternatively
When the network connection of the MySQL database is detected to be normal, a target time period is obtained by tracing back a preset time period from a current time point, the abnormal response times and average response time period of the request of the MySQL database in the target time period are obtained, a current scene is obtained, the time threshold and the time threshold corresponding to the target time period in the current scene are obtained, and when the abnormal response times are greater than the time threshold and/or the average response time period is greater than the time threshold, the abnormal access of the user side to the MySQL database is determined; or when the abnormal response times are smaller than or equal to the times threshold and the average response time is smaller than or equal to the time threshold, determining that the user side has normal access to the MySQL database;
The time threshold and the duration threshold are used for configuring historical access data of the MySQL database in different time periods according to different scenes.
4. The method for switching application data sources according to claim 1, wherein the triggering the data source switching command to the user terminal includes:
acquiring the target database identifier of the SQLlite database deployed at the user terminal;
configuring a connection cutting instruction for the MySQL database;
and generating the data source switching instruction according to the target database identifier and the disconnection instruction.
5. The application data source switching method according to claim 1, wherein loading a target configuration file according to the target database identification comprises:
acquiring a plurality of configuration files stored in the user side;
acquiring a configuration file with the target database identifier from the plurality of configuration files as the target configuration file;
loading the target configuration file;
wherein the target profile includes a combination of one or more of the following information: the method comprises the steps of driving information of the SQLlite database, database connection information of the SQLlite database, a method for indicating package service logic processing of the SQLlite database and data attribute information.
6. The application data source switching method according to claim 1, wherein after switching the data source of the user terminal from the MySQL database to the sqlite database according to the target configuration file, the method further comprises:
when the operation triggered on the user side is detected, performing read-write operation on the SQLlite database according to the detected operation.
7. The application data source switching method according to claim 1, wherein after switching the data source of the user terminal from the MySQL database to the sqlite database according to the target configuration file, the method further comprises:
when the network connection of the MySQL database is detected to be recovered normally, generating a confirmation request whether to switch the data source of the user side from the SQLlite database to the MySQL database, sending the confirmation request to a configuration terminal, and when a confirmation signal fed back by the configuration terminal to the confirmation request is received, switching the data source of the user side from the SQLlite database to the MySQL database; or alternatively
When a request triggered by a user to restore and switch the data source of the user terminal from the SQLlite database to the MySQL database is received, restoring and switching the data source of the user terminal from the SQLlite database to the MySQL database.
8. An application data source switching device, characterized in that the application data source switching device comprises:
the detection unit is used for detecting whether the access of the user side to the MySQL database is abnormal or not in real time;
the triggering unit is used for triggering a data source switching instruction of the user side when detecting that the user side accesses the MySQL database abnormally;
the acquisition unit is used for acquiring the SQLlite database deployed at the user terminal according to the data source switching instruction and acquiring a target database identifier of the SQLlite database;
the loading unit is used for loading the target configuration file according to the target database identifier;
and the switching unit is used for switching the data source of the user terminal from the MySQL database to the SQLlite database according to the target configuration file.
9. A computer device, the computer device comprising:
a memory storing at least one instruction; a kind of electronic device with high-pressure air-conditioning system
A processor executing instructions stored in the memory to implement the application data source switching method of any one of claims 1 to 7.
10. A computer-readable storage medium, characterized by: the computer-readable storage medium having stored therein at least one instruction for execution by a processor in a computer device to implement the application data source switching method of any one of claims 1 to 7.
CN202310391791.4A 2023-04-04 2023-04-04 Application data source switching method, device, equipment and medium Pending CN116401104A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310391791.4A CN116401104A (en) 2023-04-04 2023-04-04 Application data source switching method, device, equipment and medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310391791.4A CN116401104A (en) 2023-04-04 2023-04-04 Application data source switching method, device, equipment and medium

Publications (1)

Publication Number Publication Date
CN116401104A true CN116401104A (en) 2023-07-07

Family

ID=87010124

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310391791.4A Pending CN116401104A (en) 2023-04-04 2023-04-04 Application data source switching method, device, equipment and medium

Country Status (1)

Country Link
CN (1) CN116401104A (en)

Similar Documents

Publication Publication Date Title
CN114124968B (en) Load balancing method, device, equipment and medium based on market data
CN113806434B (en) Big data processing method, device, equipment and medium
CN111694843B (en) Missing number detection method and device, electronic equipment and storage medium
CN115118738B (en) Disaster recovery method, device, equipment and medium based on RDMA
CN114675976B (en) GPU (graphics processing Unit) sharing method, device, equipment and medium based on kubernets
CN113923218B (en) Distributed deployment method, device, equipment and medium for coding and decoding plug-in
CN116401104A (en) Application data source switching method, device, equipment and medium
CN114124835A (en) Interface-based data transmission method, device, equipment and medium
CN117851520B (en) Data synchronization method, system, equipment and medium of securities core transaction engine
CN116483747B (en) Quotation snapshot issuing method, device, equipment and medium
CN116225789B (en) Transaction system backup capability detection method, device, equipment and medium
CN116760835B (en) Distributed storage method, device and medium
CN116860508B (en) Distributed system software defect continuous self-healing method, device, equipment and medium
CN116361753B (en) Authority authentication method, device, equipment and medium
CN114785789B (en) Database fault management method and device, electronic equipment and storage medium
CN114860349B (en) Data loading method, device, equipment and medium
CN115934576B (en) Test case generation method, device, equipment and medium in transaction scene
CN117316359B (en) Blood detection process tracking method, device, equipment and medium
CN116455997B (en) STEP market multipath forwarding method, STEP market multipath forwarding device, STEP market multipath forwarding equipment and STEP market multipath forwarding medium
CN113687834B (en) Distributed system node deployment method, device, equipment and medium
CN117914943B (en) Data subscription and pushing method, device, equipment and medium
CN116821189A (en) Invoice collection method, invoice collection device, invoice collection equipment and invoice collection medium
CN118283052A (en) Law enforcement event information acquisition method, device, equipment and medium
CN118193493A (en) Service method, device, equipment and medium based on law enforcement event processing task
CN117151955A (en) Traffic case processing state tracking method, device, equipment and medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination