forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_plugin_entry_handle.cpp
More file actions
126 lines (111 loc) · 3.74 KB
/
Copy pathob_plugin_entry_handle.cpp
File metadata and controls
126 lines (111 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*
* Copyright (c) 2025 OceanBase.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#define USING_LOG_PREFIX SHARE
#include "plugin/sys/ob_plugin_entry_handle.h"
#include "plugin/sys/ob_plugin_handle.h"
#include "plugin/sys/ob_plugin_utils.h"
#include "plugin/interface/ob_plugin_intf.h"
namespace oceanbase {
namespace plugin {
const char *ob_plugin_state_to_string(ObPluginState state)
{
switch (state) {
case ObPluginState::INVALID: return "INVALID";
case ObPluginState::UNINIT: return "UNINIT";
case ObPluginState::READY: return "READY";
case ObPluginState::DEAD: return "DEAD";
default: return "UNKNOWN_STATE";
}
}
////////////////////////////////////////////////////////////////////////////////
bool ObPluginEntry::is_valid() const
{
bool bret = true;
if (interface_type <= OBP_PLUGIN_TYPE_INVALID || interface_type >= OBP_PLUGIN_TYPE_MAX ||
name.length() == 0 || name.length() > OB_PLUGIN_NAME_MAX_LENGTH ||
OB_ISNULL(descriptor) ||
OB_ISNULL(plugin_handle)) {
bret = false;
}
return bret;
}
////////////////////////////////////////////////////////////////////////////////
ObPluginEntryHandle::~ObPluginEntryHandle()
{
destroy();
}
int ObPluginEntryHandle::init(const ObPluginEntry &plugin_entry)
{
int ret = OB_SUCCESS;
if (!plugin_entry.is_valid()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("try to init an invalid plugin", K(plugin_entry));
} else {
plugin_entry_ = plugin_entry;
state_ = ObPluginState::UNINIT;
}
return ret;
}
void ObPluginEntryHandle::destroy()
{
deinit_plugin();
state_ = ObPluginState::DEAD;
}
int ObPluginEntryHandle::init_plugin()
{
int ret = OB_SUCCESS;
if (state_ >= ObPluginState::READY) {
ret = OB_INIT_TWICE;
LOG_WARN("plugin cannot be inited twice", K(*this));
} else if (OB_ISNULL(plugin_entry_.descriptor) || OB_ISNULL(plugin_entry_.plugin_handle)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("can't call plugin init", K(ret), K(plugin_entry_));
} else if (OB_FAIL(plugin_entry_.descriptor->init(&plugin_entry_.plugin_handle->plugin_param()))) {
LOG_WARN("failed to init plugin descriptor", K(ret));
} else {
state_ = ObPluginState::READY;
}
return ret;
}
void ObPluginEntryHandle::deinit_plugin()
{
int ret = OB_SUCCESS;
if (state_ != ObPluginState::READY) {
} else if (OB_ISNULL(plugin_entry_.descriptor) || OB_ISNULL(plugin_entry_.plugin_handle)) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("can't call plugin deinit", K(ret), K(plugin_entry_));
} else if (OB_FAIL(plugin_entry_.descriptor->deinit(&plugin_entry_.plugin_handle->plugin_param()))) {
LOG_WARN("failed to run plugin descriptor deinit", K(ret));
} else {
OB_DELETE(ObIPluginDescriptor, OB_PLUGIN_MEMORY_LABEL, plugin_entry_.descriptor);
plugin_entry_.descriptor = nullptr;
state_ = ObPluginState::DEAD;
}
}
bool ObPluginEntryHandle::ready() const
{
return state_ == ObPluginState::READY;
}
ObPluginVersion ObPluginEntryHandle::library_version() const
{
ObPluginVersion version = 0;
if (OB_NOT_NULL(plugin_entry_.plugin_handle) && OB_NOT_NULL(plugin_entry_.plugin_handle->plugin())) {
version = plugin_entry_.plugin_handle->plugin()->version;
}
return version;
}
} // namespace plugin
} // namespace oceanbase