forked from oceanbase/seekdb
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathob_plugin_load_param.cpp
More file actions
126 lines (113 loc) · 4 KB
/
Copy pathob_plugin_load_param.cpp
File metadata and controls
126 lines (113 loc) · 4 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_load_param.h"
using namespace oceanbase::common;
namespace oceanbase {
namespace plugin {
const char ITEM_TERMINATE_CHAR = ',';
const char FIELD_TERMINATE_CHAR = ':';
const char *ObPluginLoadOption::value_string() const
{
switch (value_) {
case ObPluginLoadOption::INVALID: return "INVALID";
case ObPluginLoadOption::ON: return "ON";
case ObPluginLoadOption::OFF: return "OFF";
case ObPluginLoadOption::MAX: return "MAX";
default: return "UNKNOWN_OPTION";
}
}
DEF_TO_STRING(ObPluginLoadOption)
{
return snprintf(buf, buf_len, "%d:%s", static_cast<int>(value_), value_string());
}
ObPluginLoadOption ObPluginLoadOption::from_string(const ObString &str)
{
ObPluginLoadOption ret(ObPluginLoadOption::INVALID);
if (0 == str.case_compare("on")) {
ret.value_ = ObPluginLoadOption::ON;
} else if (0 == str.case_compare("off")) {
ret.value_ = ObPluginLoadOption::OFF;
}
return ret;
}
int ObPluginLoadParamParser::parse(const ObString ¶m, ObIArray<ObPluginLoadParam> &plugin_params)
{
int ret = OB_SUCCESS;
ObString param_str(param);
param_str = param_str.trim();
if (param_str.empty()) {
// nothing to do
} else {
ObPluginLoadParam plugin_param;
ObString last_str = param_str;
while (OB_SUCC(ret) && !last_str.empty() && OB_NOT_NULL(last_str.find(ITEM_TERMINATE_CHAR))) {
ObString item_str = last_str.split_on(ITEM_TERMINATE_CHAR);
last_str = last_str.trim();
item_str = item_str.trim();
if (item_str.empty()) {
// ignore
} else if (OB_FAIL(parse_item(item_str, plugin_param))) {
LOG_WARN("failed to parse plugin load param", K(ret));
} else if (OB_FAIL(plugin_params.push_back(plugin_param))) {
LOG_WARN("failed to push back plugin param", K(plugin_param), K(ret));
}
}
ObString item_str = last_str;
if (OB_FAIL(ret)) {
} else if (item_str.empty()) {
} else if (OB_FAIL(parse_item(item_str, plugin_param))) {
LOG_WARN("failed to parse plugin load param", K(ret));
} else if (OB_FAIL(plugin_params.push_back(plugin_param))) {
LOG_WARN("failed to push back plugin param", K(plugin_param), K(ret));
}
}
return ret;
}
int ObPluginLoadParamParser::parse_item(const ObString &item_str, ObPluginLoadParam &plugin_param)
{
int ret = OB_SUCCESS;
if (item_str.empty()) {
ret = OB_INVALID_ARGUMENT;
} else {
ObString src_str = item_str;
ObString library_name;
ObPluginLoadOption load_option(ObPluginLoadOption::ON);
const char *sep = item_str.find(FIELD_TERMINATE_CHAR);
LOG_DEBUG("item str find field terminated char", KP(sep), K(item_str));
if (OB_ISNULL(sep)) {
library_name = item_str;
} else {
library_name = src_str.split_on(sep);
ObString option_str = src_str.trim();
load_option = ObPluginLoadOption::from_string(option_str);
if (library_name.empty()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("library name is empty", K(ret), K(item_str));
} else if (ObPluginLoadOption::INVALID == load_option.value()) {
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid plugin load option", K(load_option), K(option_str));
}
}
if (OB_SUCC(ret)) {
plugin_param.library_name = library_name;
plugin_param.load_option = load_option;
}
}
return ret;
}
} // namespace plugin
} // namespace oceanbase