Automatic loading method, system, equipment and program of database plug-in
By automatically loading the plug -in when the user logs in to the database, the user's forgetting the database function abnormality caused by the database function caused by the loading plug -in, and the effect of a higher user experience and reducing operation and maintenance costs.
Patent Information
- Application Number
- CN202411918469.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-25
- Publication Date
- 2025-01-28
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The loading process of existing database plug-ins requires the user to manually execute commands, which may cause the user to forget to load the necessary plug-ins, resulting in abnormal database functions, and increase user time waste and operation and maintenance costs.
When the user logs in to the database, it automatically loads the plug -in to be loaded. The plug -in list is obtained through the creation of the session thread to read the configuration file, and the intermodal lock mechanism is used to ensure the security and order of the thread loaded by the plug -in.
The automatic loading of the database plug -in, reducing the complexity of user operation, increasing user experience, and reducing product operation and maintenance costs.
Smart Images

Figure CN119376820A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of database technology, and in particular to a method, system, device and program for automatically loading a database plug-in. Background Art
[0002] Currently, mainstream database products all provide a variety of plug-in source codes with rich functions. When using the database, users can select the appropriate plug-in source code for compilation according to their needs, and package the generated plug-in files into the released database version package.
[0003] A plugin usually consists of the following parts: SQL scripts: These scripts define the core functionality of the plugin, including creating new data types, functions, operators, etc.
[0004] Control file: The control file defines the plugin's version information, dependencies, and other metadata.
[0005] Shared library: For some plug-ins that need to perform complex calculations or need to access low-level system resources, you may need to write a shared library. This library is usually compiled into a .so file (on Unix-like systems) or a .dll file (on Windows systems).
[0006] After the user installs and deploys the database, connect to the database through the client tool and manually execute the load plug-in command. The kernel execution process mainly includes the following parts: Parse the command: First, parse the plugin load command to extract the plugin name and other parameters. Then parse the control file according to the plugin name to obtain the plugin version number, plugin library information, etc.
[0007] Load SQL script: Load the plug-in's SQL script and execute the commands in it. These commands will create new data types, functions, operators, etc., thereby expanding the functionality of the database.
[0008] Load the plugin library: Create a function SQL in the load SQL script. If the function definition is specified to be in the plugin library, the library will be loaded. The plugin library only needs to be loaded once. These functions can implement more complex functions, such as custom aggregate functions.
[0009] Register a plug-in: Add the plug-in to the system table of the database so that it can be used by other database objects (such as tables, views, etc.).
[0010] A distributed database cluster includes CN (coordinator node) and DN (data node). When a user operates a database, he / she will connect to a CN node. For example, if a user APP connects to the CN1 node, a corresponding connection session will be created on CN1. For this session, CN1 is the master CN node. When a user executes an SQL command, a corresponding connection will be established between the CN and DN nodes in the cluster. For example, if CN1 connects to CN2, a corresponding session will be created on CN2. For this session, CN2 is the slave CN node. Figure 6 shown.
[0011] The loading process is initiated by manually executing commands, which meets the requirements for most plug-in usage. However, some plug-ins that are highly associated with kernel modules require that the relevant functions of the plug-ins be available after the database is created. This manual loading process will cause various problems in actual use. First of all, operations such as building a database and loading plug-ins are completed by users. Users may not know which plug-ins a certain database product provides, so they will not load the necessary plug-ins; even if there are prompts in the product manual, different users will still have a high probability of forgetting to load them when using them. Due to the lack of necessary plug-ins, there are functional abnormalities during the use of the database, which not only wastes users' time and reduces the user experience, but also increases the product's operation and maintenance costs.
[0012] Therefore, how to create a new automatic loading method for database plug-ins has become a goal that the industry urgently needs to improve. Summary of the invention
[0013] In view of this, an embodiment of the present disclosure provides a method for automatically loading a database plug-in, which at least partially solves the problems existing in the prior art.
[0014] In a first aspect, an embodiment of the present disclosure provides a method for automatically loading a database plug-in, the method comprising the following steps: S110: When a user logs into a database, a session thread is created inside the database; it is determined whether the currently logged-in database is a template library; if the logged-in database is not a template library, the process proceeds to S120; S120: the session thread reads the configuration file of the database of the plug-in to be automatically loaded, and obtains the plug-in list and the mutex locking mode according to the compatible type of the database; the locking mode includes ordinary locking and attempted locking; S130: traverse the plug-in list, and determine in turn whether the plug-in library files in the plug-in list exist; when the plug-in library file does not exist, exit the plug-in loading process; when the plug-in library file exists, enter S140; S140: Determine whether the plug-in has been loaded; if the plug-in has been loaded, exit the plug-in loading process; if the plug-in has not been loaded, enter S150; S150: Determine whether the current user has the plug-in loading permission; if the user does not have the plug-in loading permission, an error message is displayed to prompt the user to load the plug-in with administrator permission; if the user has the plug-in loading permission, enter S160; S160: Get the mutex lock and lock it according to the preset locking mode; in the normal locking mode, when the mutex lock is not obtained, the operating system releases the CPU to enter sleep waiting; in the attempted locking mode, if the lock is held, the operating system immediately returns an error, and the loading thread exits the plug-in loading process; when the mutex lock is obtained, enter S180; S170: Determine whether the plug-in has been loaded; when the plug-in has been loaded, exit the plug-in loading process; when the plug-in has not been loaded, load the plug-in, and release the mutex after loading is completed.
[0015] According to a specific implementation of the embodiment of the present disclosure, the method further includes: When the database for automatically loading the plug-in is a distributed database, it is determined whether the current database node is the primary CN; when the node is not the primary CN, the plug-in loading process is exited; when the node is the primary CN, S150 is entered.
[0016] According to a specific implementation of the embodiment of the present disclosure, the method further includes: When the mutex is released, the next plug-in is automatically loaded and steps S130 to S170 are repeated.
[0017] According to a specific implementation of the embodiment of the present disclosure, the sequentially determining whether the plug-in library files in the plug-in list exist includes: The lib folder in the database installation package is searched according to the plug-in name; when a plug-in name file with a preset suffix is found, it indicates that the plug-in library file exists; when no file is found, it indicates that the plug-in library file does not exist.
[0018] According to a specific implementation of the embodiment of the present disclosure, the determining whether the plug-in has been loaded includes: The database plug-in system table is queried according to the plug-in name; when the database plug-in system table has the plug-in record, it is determined that the plug-in has been loaded; when the database plug-in system table does not have the plug-in record, it is determined that the plug-in has not been loaded.
[0019] According to a specific implementation of the embodiment of the present disclosure, the determining whether the current user has the permission to load the plug-in includes: Parse the plug-in control file, and determine whether administrator privileges are required to load the plug-in according to the plug-in control file; if not required, directly load the plug-in; if required, read the database user system table to determine whether the current user has administrator privileges.
[0020] According to a specific implementation of the embodiment of the present disclosure, the plug-in loading and releasing the mutex after loading is completed include: Determine whether there is an automatic loading function; if so, call the automatic loading function to load the plug-in; if not, end the loading process of the plug-in; The calling of the automatic loading function to load the plug-in includes: Parse plugin loading commands; Load SQL scripts and plugin libraries; Register the plugin.
[0021] In a second aspect, an embodiment of the present disclosure provides an automatic loading system for a database plug-in, the system comprising: The plug-in acquisition module is configured to create a session thread inside the database when the user logs in to the database; determine whether the current login database is a template library; wherein, when the login database is not a template library, the session thread reads the configuration file of the database to be automatically loaded with the plug-in, and obtains the plug-in list and the mutex locking mode according to the compatible type of the database; the locking mode includes ordinary locking and attempted locking; A judgment module is configured to traverse the plug-in list and determine in turn whether the plug-in library files in the plug-in list exist; wherein, when the plug-in library file does not exist, exit the plug-in loading process; when the plug-in library file exists, determine whether the plug-in has been loaded; wherein, when the plug-in has been loaded, exit the plug-in loading process; when the plug-in is not loaded, determine whether the current user has the loading permission of the plug-in; wherein, when the user does not have the plug-in loading permission, an error message is given to load with administrator permissions; when the user has the plug-in loading permission, obtain a mutex lock and lock it according to a preset locking method; wherein, in the normal locking mode, when the mutex lock is not obtained, the operating system releases the CPU to enter sleep waiting; in the attempted locking mode, if the lock is held, the operating system immediately returns an error, and the loading thread exits the plug-in loading process; The secondary judgment module is configured to judge whether the plug-in has been loaded when the mutex lock is acquired; when the plug-in has been loaded, the plug-in loading process is exited; when the plug-in has not been loaded, the plug-in is loaded, and the mutex lock is released after the loading is completed.
[0022] In a third aspect, an embodiment of the present disclosure further provides an electronic device, the electronic device comprising: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor performs the automatic loading method of the database plug-in described in any one of the first aspect or any one of the implementations of the first aspect.
[0023] In a fourth aspect, an embodiment of the present disclosure further provides a computer program product, comprising a computer program stored on a non-transitory computer-readable storage medium, wherein the computer program comprises program instructions, and when the program instructions are executed by a computer, the computer executes the automatic loading method of the database plug-in in the aforementioned first aspect or any implementation of the first aspect.
[0024] The automatic loading method of the database plug-in in the embodiment of the present disclosure automatically loads the corresponding plug-in according to the database type when the user logs in for the first time after creating the database. The whole process is transparent to the user, and the user does not need to care about the loading process. The innovation of this technology is reflected in the automatic loading of the plug-in when the user connects to the database, avoiding the tedious manual loading, reducing the complexity of the user's use of the database, increasing the user experience, and also reducing the operation and maintenance costs of the product. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] The above is only an overview of the technical solution of the present invention. In order to more clearly understand the technical means of the present invention, the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0026] Figure 1 A schematic diagram of a flow chart of an automatic loading method of a database plug-in provided in an embodiment of the present disclosure; Figure 2 A flowchart of a method for automatically loading a database plug-in provided in an embodiment of the present disclosure; Figure 3 A schematic diagram of a plug-in loading command execution flow provided in an embodiment of the present disclosure; Figure 4 A schematic diagram of the structure of an automatic loading system for a database plug-in provided in an embodiment of the present disclosure; Figure 5 Schematic diagram of an electronic device provided for an embodiment of the present disclosure Figure 6 A schematic diagram of node connections in a distributed database provided in an embodiment of the present disclosure. DETAILED DESCRIPTION
[0027] The embodiments of the present disclosure are described in detail below with reference to the accompanying drawings.
[0028] The following describes the embodiments of the present disclosure through specific examples, and those skilled in the art can easily understand other advantages and effects of the present disclosure from the contents disclosed in this specification. Obviously, the described embodiments are only a part of the embodiments of the present disclosure, rather than all of the embodiments. The present disclosure can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present disclosure. It should be noted that the following embodiments and features in the embodiments can be combined with each other without conflict. Based on the embodiments in the present disclosure, all other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of the present disclosure.
[0029] It should be noted that various aspects of the embodiments within the scope of the appended claims are described below. It should be apparent that the aspects described herein may be embodied in a wide variety of forms, and any specific structure and / or function described herein is merely illustrative. Based on the present disclosure, it should be understood by those skilled in the art that an aspect described herein may be implemented independently of any other aspect, and two or more of these aspects may be combined in various ways. For example, any number of aspects described herein may be used to implement a device and / or practice a method. In addition, other structures and / or functionalities other than one or more of the aspects described herein may be used to implement this device and / or practice this method.
[0030] Additionally, in the following description, specific details are provided to facilitate a thorough understanding of the examples. However, it will be understood by those skilled in the art that the aspects described may be practiced without these specific details.
[0031] Currently, mainstream database products all provide a rich set of kernel programming interfaces, allowing developers to integrate their own code into the kernel in the form of plug-ins without modifying any core code, thereby expanding database functionality. A plug-in is a pluggable module that can be used to provide additional functionality, data types, functions, operators, and more. PostgreSQL, MySQL, and other databases all provide a variety of feature-rich plug-in source codes that users can compile and use as needed.
[0032] The plug-in is usually loaded manually by the user. The specific process is to connect to the database through the client tool and execute the database plug-in loading command. The plug-in name is specified in the command. The kernel will find the configuration file of the corresponding plug-in, load the dynamic library of the plug-in according to the content of the configuration file, and execute the sql file of the specified version of the plug-in to complete the plug-in loading. This manual loading mechanism is not a problem in most scenarios, but some plug-ins are strongly associated with kernel modules, such as compatibility plug-ins. When an Oracle-compatible database is created, the plug-in should be loaded at the same time as the database is created. If users are allowed to manually load plug-ins after building a database, on the one hand, customers may not know the existence of related plug-ins. Plug-ins are unique to databases, and plug-ins provided by different database vendors are also different. Even if they know the related plug-ins, there is a high probability that they will forget to load the plug-ins after creating a database. The lack of related plug-ins will cause compatibility issues in database functions, increase operation and maintenance costs, and reduce user experience. Based on this, a method for automatically loading database plug-ins is designed. When a user logs in for the first time after creating a database, the corresponding plug-in is automatically loaded according to the database type. The whole process is transparent to the user, and the user does not need to care about the loading process.
[0033] The present invention can solve various problems existing in manual loading of database plug-ins, and reduces the complexity of using the database for users by automatically loading the plug-ins when connecting to the database.
[0034] There are various compatibility types for databases, and different plug-ins need to be loaded for each compatibility. When connecting to a database, you need to load the corresponding plug-in according to the corresponding type.
[0035] Figure 1 A schematic diagram of the automatic loading method flow of a database plug-in provided in an embodiment of the present disclosure.
[0036] Figure 2 For Figure 1 Flow chart of the automatic loading method of the corresponding database plug-in.
[0037] like Figure 1 As shown, at step S110, when a user logs into a database, a session thread is created inside the database; it is determined whether the currently logged-in database is a template library; wherein, when the logged-in database is not a template library, the process proceeds to S120.
[0038] More specifically, the template library is created when the database is initialized. As the basic template for creating other databases, the library needs to remain pure throughout the life cycle of the database, so automatic loading does not operate on the template library. The name of the template database is fixed, which is template. You can directly determine whether the login library is a template database by its name.
[0039] At step S120, the session thread reads the configuration file of the database of the plug-in to be automatically loaded, and obtains the plug-in list and the mutex locking mode according to the compatible type of the database; the locking mode includes ordinary locking and attempted locking.
[0040] More specifically, the mutex locking operating system provides two interfaces: normal locking and attempted locking. Normal locking, if the lock is already held by other threads, will sleep and wait; attempted locking, if the lock is already held by other threads, will immediately return an error.
[0041] It is convenient to configure different plug-ins to be loaded and lock modes for different mode databases; manual loading confirms which plug-in to load by entering a command.
[0042] In an embodiment of the present invention, when a user logs in to a compatible database, a connection session is created inside the database, a configuration file of a plug-in to be automatically loaded is read, and a list of plug-ins to be automatically loaded is obtained according to the compatible type of the database.
[0043] At step S130, the plug-in list is traversed to determine whether the plug-in library files in the plug-in list exist. If the plug-in library file does not exist, the plug-in loading process is exited. If the plug-in library file exists, the process proceeds to S140. In an embodiment of the present invention, the step of sequentially determining whether the plug-in library files in the plug-in list exist includes: searching for a lib folder in a database installation package according to the plug-in name; when a plug-in name file with a preset suffix is found, it indicates that the plug-in library file exists; when no file is found, it indicates that the plug-in library file does not exist.
[0044] More specifically, the plug-in list is traversed, and the automatic loading process is started for each plug-in; it is determined whether the plug-in library file exists, specifically by searching the lib folder in the database installation package according to the plug-in name. If the plug-in name .so file is found, it means that the plug-in exists, and step S140 is entered, otherwise the plug-in loading process is exited.
[0045] At step S140, it is determined whether the plug-in has been loaded; when the plug-in has been loaded, the plug-in loading process is exited; when the plug-in has not been loaded, the process proceeds to S150; In an embodiment of the present invention, the method further includes: when the database to be automatically loaded with the plug-in is a distributed database, determining whether the current database node is a primary CN; wherein, when the node is not the primary CN, exiting the plug-in loading process; when the node is the primary CN, entering S150. This determination process is not required for a centralized database.
[0046] In an embodiment of the present invention, determining whether the plug-in has been loaded includes: querying a database plug-in system table according to the plug-in name; when the plug-in record exists in the database plug-in system table, determining that the plug-in has been loaded; when the plug-in record does not exist in the database plug-in system table, determining that the plug-in has not been loaded.
[0047] More specifically, to determine whether the plug-in has been loaded, the database plug-in system table is queried according to the plug-in name. The system table records the plug-in information that has been loaded in the current database. Each plug-in is a record in the system table, including the plug-in name, version number, creation user, etc. If the query finds a record that proves that the plug-in has been loaded, then exit and load other plug-ins in the plug-in list, otherwise go to step S150.
[0048] At step S150, it is determined whether the current user has the plug-in loading permission. If the user does not have the plug-in loading permission, an error message is displayed to prompt the user to load the plug-in with administrator permission. If the user has the plug-in loading permission, the process proceeds to S160. In an embodiment of the present invention, the determination of whether the current user has the loading permission of the plug-in includes: parsing the plug-in control file, and determining whether administrator permission is required to load the plug-in according to the plug-in control file; when not required, directly loading; when required, reading the database user system table to determine whether the current user has administrator permission.
[0049] More specifically, the plug-in loading permission will also be judged in the subsequent plug-in loading process. This advance judgment is made for system performance considerations. Concurrent loading requires obtaining a mutex lock. Threads that cannot obtain the lock will enter a lock wait. In order to prevent threads that do not have loading permissions from entering an invalid lock wait and wasting system resources, an advance judgment is made here. Only threads with loading permissions need to obtain a mutex lock to prepare for subsequent loading. Other threads directly report an error and exit, ending the loading process early. This can improve system performance in cases where automatic loading involves large concurrency.
[0050] At step S160, the mutex lock is acquired and locked according to the preset locking method; wherein, in the normal locking mode, when the mutex lock is not acquired, the operating system releases the CPU to enter sleep waiting; in the attempted locking mode, if the lock is held by other threads, the operating system immediately returns an error, and the loading thread exits the plug-in loading process; when the mutex lock is acquired, enter S170.
[0051] More specifically, when a mutex lock is obtained in the two modes, S170 is entered; wherein, the mutex lock is created separately for each plug-in to be loaded, and the software uses a two-dimensional array for storage, the first dimension is the database mode, and the second dimension is the specific plug-in. When actually obtaining, the mutex lock that needs to be used can be quickly located by looking up the table according to the database mode and the plug-in number as the array table; the two locking methods can be configured according to the needs of the plug-in. If the performance requirements are high, you can use a try lock. When a thread has obtained the lock, other threads do not need to wait and directly exit the plug-in automatic loading process, which will not be affected during high concurrency. The problem is that if the service is provided when the plug-in is not loaded, because it is not processed until the plug-in is loaded, there will be a short-term inconsistency with the plug-in after loading, but it will be consistent after loading, so it is temporary; if the performance requirements are not high and the consistency requirements are high, ordinary locking is used to ensure the consistency of the processing results before and after. Different plug-ins have different functions, and you can evaluate the locking method used according to your needs.
[0052] The mutex lock is created separately for each plug-in to be loaded, that is, one mutex lock for each plug-in, which is stored in a two-dimensional array internally and introduces a locking mode, so that different plug-ins can be locked separately when locking, which can reduce lock conflicts when there is large concurrency and improve the performance of the entire system.
[0053] Obtain a mutex lock to prevent multiple sessions from loading plug-ins concurrently. Since automatic loading is automatically completed when the corresponding session is created inside the database after the user connects to the database, there may be multiple users connecting to the database at the same time, and plug-in loading itself also takes time, so there will be multiple connections at the same time during the loading window, that is, multiple sessions will be created inside the database. When each session is created, the plug-in will be loaded and enter a competitive state, so a mutex lock is required to ensure the integrity of plug-in loading. In the normal locking mode, if the lock is not obtained when acquiring the lock, the CPU is released to enter sleep waiting, and if it is obtained, it enters step S170. The sleep waiting session will be awakened after the session that obtains the lock completes the plug-in loading and releases the lock, and also enters step S170 to attempt to load. Note that the awakening here only awakens one session, and other sessions continue to sleep. The session waiting to be awakened completes step S170 and releases the mutex lock before continuing to awaken the next session. By analogy, all dormant sessions are awakened in turn, and the process of step S170 is completed.
[0054] In step S170, it is determined whether the plug-in has been loaded; when the plug-in has been loaded, the plug-in loading process is exited; when the plug-in has not been loaded, the plug-in is loaded, and the mutex lock is released after the loading is completed.
[0055] More specifically, after the plugin is automatically loaded, it can be uninstalled. You need to comment out the name of the automatically loaded plugin in the configuration file, and it will not be automatically loaded when you create a new library later. For some databases that have automatically loaded plugins, you can manually execute the uninstall command to complete the uninstallation of the plugin.
[0056] In an embodiment of the present invention, the plug-in loading and releasing the mutex lock after the loading is completed include: determining whether an automatic loading function exists; when it exists, calling the automatic loading function to load the plug-in; when it does not exist, ending the loading process of the plug-in; calling the automatic loading function to load the plug-in includes: parsing the plug-in loading command; loading the SQL script, loading the plug-in library; registering the plug-in.
[0057] More specifically, when loading the plugin library, first determine whether there is an automatic loading function. If so, call the function. The implementation of this function varies slightly among plugins. Some plugins need to rely on other plugins. In this case, you need to execute the loading commands of other dependent plugins first, and then execute the loading command of this plugin. If the plugin library does not provide an automatic loading function, it means that the plugin does not support automatic loading, and the plugin loading process can be ended directly.
[0058] The load command processing for each plugin consists of the following steps: Parse plugin loading commands; Load SQL scripts and plugin libraries; Register the plug-in; for distributed databases, when a plug-in is loaded on the main CN, the loading command will be forwarded to other nodes in the cluster for execution. If other nodes execute successfully, it means that the plug-in has been loaded successfully. If any node fails to load, the plug-in loading is considered to have failed to ensure the consistency of the entire cluster. When a single node executes commands in a SQL script, if it is a DLL operation, special processing is required. Unlike regular DDL processing, regular DDL processing needs to be forwarded to other nodes in the cluster after the main CN processing is completed, so as to ensure that all cluster nodes have objects created by the DDL. The DDL in the plug-in does not need to be forwarded, but only processed on this node. After the entire SQL script is processed, the main CN will forward the loading command to other nodes in the cluster, and other nodes will execute the same process as the main CN processing the loading command to complete the loading of the plug-in.
[0059] In an embodiment of the present invention, the plug-in supports unloading after automatic loading. It is necessary to comment out the name of the plug-in that is automatically loaded in the configuration file, and the subsequent creation of a new library will not be automatically loaded. For plug-ins that have been automatically loaded in some databases, the uninstall command can be manually executed to complete the unloading of the plug-in.
[0060] More specifically, if Figure 3 As shown, the detailed design of the process implementation of automatic plug-in loading is described as follows: 1. Loading location: After connecting to the database through the client, a session will be generated. The automatic loading of the plug-in can be completed during the session initialization.
[0061] 2. Loading permissions: Since the plug-in loading process requires the execution of the plug-in SQL file, the SQL inside the file will define various objects in the system mode, and the user who logs in to the session needs to have the corresponding permissions.
[0062] 3. Plug-in selection: Different compatibility databases require different plug-ins to be loaded. You need to load the appropriate plug-in according to the compatibility mode of different databases.
[0063] 4. Concurrent loading: Since the database supports concurrent operations, multiple sessions will be connected to the same database at the same time. The loading process is placed in the public function session initialization, so that multiple sessions can load plug-ins concurrently. In order to avoid exceptions caused by concurrent loading, a mutex is required to protect the process. It should be noted that the mutex needs to be released before exiting after loading to prevent deadlock problems.
[0064] 5. Loading protection: In addition to the lock protection mentioned above for concurrent loading, additional protection is also required in the process. For a database, a plug-in only needs to be loaded once, and subsequent sessions do not need to be loaded repeatedly. Therefore, it is necessary to determine whether the database has loaded the corresponding plug-in before loading, and to determine whether the plug-in to be loaded has been loaded by traversing the plug-in system table. During the sleep waiting window for obtaining the mutex lock, other sessions may have completed the plug-in loading, so a second protection judgment is required after obtaining the mutex lock.
[0065] In the embodiment of the present invention, the method further includes: when the mutex lock is released, entering into automatic loading of the next plug-in, and repeating S130 to S170.
[0066] More specifically, when a session completes plug-in loading, the subsequent session that obtains the mutex lock no longer needs to load the plug-in again. Here, it is necessary to refer to the process of step S130 to determine whether the plug-in has been loaded again. If other sessions have completed plug-in loading while the session is waiting in step S160, then exit the plug-in loading process. If it is not loaded, execute the loading command. The execution process of the loading instruction refers to the four steps in the background technology, which are: parsing commands, loading SQL scripts, loading plug-in libraries, and registering plug-ins. After the loading is completed, the mutex lock will be released to notify other dormant sessions to enter the step S170 process. The automatic loading process of the plug-in in this session ends, and enters the automatic loading of the next plug-in, repeating steps S130 to S170.
[0067] The value of the automatic loading method of the database plug-in proposed in the present invention is that the plug-in is automatically loaded when the user connects to the database, eliminating the tedious manual loading, reducing the complexity of the user's use of the database, improving the user experience, and also reducing the operation and maintenance costs of the product.
[0068] Figure 4 The automatic loading system 400 of a database plug-in provided by the present invention is shown, comprising a plug-in acquisition module 410 , a judgment module 420 and a secondary judgment module 430 .
[0069] The plug-in acquisition module 410 is used to create a session thread inside the database when the user logs in to the database; determine whether the current login database is a template library; wherein, when the login database is not a template library, the session thread reads the configuration file of the database to be automatically loaded with the plug-in, and obtains the plug-in list and the mutex locking mode according to the compatible type of the database; the locking mode includes ordinary locking and attempted locking; The judgment module 420 is used to traverse the plug-in list and determine in turn whether the plug-in library files in the plug-in list exist; wherein, when the plug-in library file does not exist, exit the plug-in loading process; when the plug-in library file exists, determine whether the plug-in has been loaded; wherein, when the plug-in has been loaded, exit the plug-in loading process; when the plug-in is not loaded, determine whether the current user has the loading permission of the plug-in; wherein, when the user does not have the plug-in loading permission, an error message is given to load with administrator permissions; when the user has the plug-in loading permission, obtain the mutex lock and lock it according to the preset locking method; wherein, in the normal locking mode, when the mutex lock is not obtained, the operating system releases the CPU to enter sleep waiting; in the attempted locking mode, if the lock is held by other threads, the operating system immediately returns an error, and the loading thread exits the plug-in loading process; The secondary judgment module 430 is used to judge whether the plug-in has been loaded when the mutex lock is acquired; when the plug-in has been loaded, the plug-in loading process is exited; when the plug-in has not been loaded, the plug-in is loaded and the mutex lock is released after the loading is completed.
[0070] See also Figure 5 The present disclosure also provides an electronic device 50, which includes: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the automatic loading method of the database plug-in in the aforementioned method embodiment.
[0071] The embodiment of the present disclosure also provides a non-transitory computer-readable storage medium, which stores computer instructions, and the computer instructions are used to enable the computer to execute the automatic loading method of the database plug-in in the aforementioned method embodiment.
[0072] The embodiments of the present disclosure also provide a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, which, when executed by a computer, enable the computer to execute the automatic loading method of the database plug-in in the aforementioned method embodiment.
[0073] Reference below Figure 5 , which shows a schematic diagram of the structure of an electronic device 50 suitable for implementing the embodiment of the present disclosure. The electronic device in the embodiment of the present disclosure may include, but is not limited to, mobile terminals such as mobile phones, notebook computers, digital broadcast receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 5 The electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present disclosure.
[0074] like Figure 5 As shown, the electronic device 50 may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 501, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 502 or a program loaded from a storage device 508 into a random access memory (RAM) 503. In the RAM 503, various programs and data required for the operation of the electronic device 50 are also stored. The processing device 501, the ROM 502, and the RAM 503 are connected to each other via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0075] Typically, the following devices may be connected to the I / O interface 505: input devices 506 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; output devices 507 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; storage devices 508 including, for example, a magnetic tape, a hard disk, etc.; and communication devices 509. The communication device 509 may allow the electronic device 50 to communicate with other devices wirelessly or by wire to exchange data. Although the electronic device 50 having various devices is shown in the figure, it should be understood that it is not required to implement or have all the devices shown. More or fewer devices may be implemented or have alternatively.
[0076] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device 509, or installed from a storage device 508, or installed from a ROM 502. When the computer program is executed by the processing device 501, the above-mentioned functions defined in the method of the embodiment of the present disclosure are executed.
[0077] It should be noted that the computer-readable medium mentioned above in the present disclosure may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present disclosure, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. Computer readable signal media may also be any computer readable medium other than computer readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer readable medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0078] The computer-readable medium may be included in the electronic device, or may exist independently without being incorporated into the electronic device.
[0079] The computer-readable medium carries one or more programs. When the one or more programs are executed by the electronic device, the electronic device: obtains at least two Internet Protocol addresses; sends a node evaluation request including the at least two Internet Protocol addresses to a node evaluation device, wherein the node evaluation device selects an Internet Protocol address from the at least two Internet Protocol addresses and returns it; receives the Internet Protocol address returned by the node evaluation device; wherein the obtained Internet Protocol address indicates an edge node in a content distribution network.
[0080] Alternatively, the computer-readable medium carries one or more programs, and when the one or more programs are executed by the electronic device, the electronic device: receives a node evaluation request including at least two Internet Protocol addresses; selects an Internet Protocol address from the at least two Internet Protocol addresses; and returns the selected Internet Protocol address; wherein the received Internet Protocol address indicates an edge node in a content distribution network.
[0081] Computer program code for performing the operations of the present disclosure may be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0082] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present disclosure. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some implementations as replacements, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0083] The units involved in the embodiments described in the present disclosure may be implemented by software or hardware. The name of a unit does not limit the unit itself in some cases. For example, the first acquisition unit may also be described as a "unit for acquiring at least two Internet Protocol addresses".
[0084] It should be understood that various parts of the present disclosure may be implemented in hardware, software, firmware, or a combination thereof.
[0085] The above is only a specific implementation of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed in the present disclosure should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for automatically loading a database plug-in, characterized in that: The method comprises the following steps: S110: When a user logs into a database, a session thread is created inside the database; it is determined whether the currently logged-in database is a template library; if the logged-in database is not a template library, the process proceeds to S120; S120: the session thread reads the configuration file of the database of the plug-in to be automatically loaded, and obtains the plug-in list and the mutex locking mode according to the compatible type of the database; the locking mode includes ordinary locking and attempted locking; S130: traverse the plug-in list, and determine in turn whether the plug-in library files in the plug-in list exist; when the plug-in library file does not exist, exit the plug-in loading process; when the plug-in library file exists, enter S140; S140: Determine whether the plug-in has been loaded; if the plug-in has been loaded, exit the plug-in loading process; if the plug-in has not been loaded, enter S150; S150: Determine whether the current user has the plug-in loading permission; if the user does not have the plug-in loading permission, an error message is displayed to prompt the user to load the plug-in with administrator permission; if the user has the plug-in loading permission, enter S160; S160: Acquire the mutex lock and lock it according to the preset locking mode; in the normal locking mode, when the mutex lock is not acquired, the operating system releases the CPU to enter sleep waiting; in the attempted locking mode, if the lock is held, the operating system immediately returns an error, and the loading thread exits the plug-in loading process; when the mutex lock is acquired, enter S170; S170: Determine whether the plug-in has been loaded; when the plug-in has been loaded, exit the plug-in loading process; when the plug-in has not been loaded, load the plug-in, and release the mutex after loading is completed.
2. The automatic loading method of a database plug-in according to claim 1, characterized in that: The method further comprises: When the database for automatically loading the plug-in is a distributed database, it is determined whether the current database node is the primary CN; when the node is not the primary CN, the plug-in loading process is exited; when the node is the primary CN, S150 is entered.
3. The automatic loading method of a database plug-in according to claim 1, characterized in that: The method further comprises: When the mutex is released, the next plug-in is automatically loaded and steps S130 to S170 are repeated.
4. The automatic loading method of a database plug-in according to claim 1, characterized in that: The step of sequentially determining whether the plug-in library files in the plug-in list exist includes: The lib folder in the database installation package is searched according to the plug-in name; when a plug-in name file with a preset suffix is found, it indicates that the plug-in library file exists; when no file is found, it indicates that the plug-in library file does not exist.
5. The automatic loading method of a database plug-in according to claim 1, characterized in that: The determining whether the plug-in has been loaded includes: The database plug-in system table is queried according to the plug-in name; when the database plug-in system table has the plug-in record, it is determined that the plug-in has been loaded; when the database plug-in system table does not have the plug-in record, it is determined that the plug-in has not been loaded.
6. The automatic loading method of a database plug-in according to claim 1, characterized in that: The determining whether the current user has the permission to load the plug-in includes: Parse the plug-in control file, and determine whether administrator privileges are required to load the plug-in according to the plug-in control file; if not required, directly load the plug-in; if required, read the database user system table to determine whether the current user has administrator privileges.
7. The automatic loading method of a database plug-in according to claim 1, characterized in that: The plug-in loading and releasing the mutex after loading is completed include: Determine whether there is an automatic loading function; if so, call the automatic loading function to load the plug-in; if not, end the loading process of the plug-in; The calling of the automatic loading function to load the plug-in includes: Parse plugin loading commands; Load SQL scripts and plugin libraries; Register the plugin.
8. An automatic loading system for a database plug-in, characterized in that: The system comprises: The plug-in acquisition module is configured to create a session thread inside the database when the user logs in to the database; determine whether the current login database is a template library; wherein, when the login database is not a template library, the session thread reads the configuration file of the database to be automatically loaded with the plug-in, and obtains the plug-in list and the mutex locking mode according to the compatible type of the database; the locking mode includes ordinary locking and attempted locking; A judgment module is configured to traverse the plug-in list and determine in turn whether the plug-in library files in the plug-in list exist; wherein, when the plug-in library file does not exist, exit the plug-in loading process; when the plug-in library file exists, determine whether the plug-in has been loaded; wherein, when the plug-in has been loaded, exit the plug-in loading process; when the plug-in is not loaded, determine whether the current user has the loading permission of the plug-in; wherein, when the user does not have the plug-in loading permission, an error message is given to load with administrator permissions; when the user has the plug-in loading permission, obtain a mutex lock and lock it according to a preset locking method; wherein, in the normal locking mode, when the mutex lock is not obtained, the operating system releases the CPU to enter sleep waiting; in the attempted locking mode, if the lock is held, the operating system immediately returns an error, and the loading thread exits the plug-in loading process; The secondary judgment module is configured to judge whether the plug-in has been loaded when the mutex lock is acquired; when the plug-in has been loaded, the plug-in loading process is exited; when the plug-in has not been loaded, the plug-in is loaded, and the mutex lock is released after the loading is completed.
9. An electronic device, characterized in that: The electronic device includes: at least one processor; and, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and when the instructions are executed by the at least one processor, the at least one processor executes the automatic loading method of the database plug-in according to any one of claims 1 to 7.
10. A computer program product, characterized in that The computer program product comprises a computer program stored on a non-transitory computer-readable storage medium, wherein the computer program comprises program instructions, which, when executed by a computer, cause the computer to execute the automatic loading method of a database plug-in as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Method and system for dynamically loading interface to realize software package during operation
CN114564280A
Multi-type database compatibility method and device, equipment and storage medium
CN114706918A
Task execution method and device based on coroutine, storage medium and electronic equipment
CN116225728A