storage the configuartion item default value as constant string value

This commit is contained in:
obdev
2024-02-06 18:32:26 +00:00
committed by ob-robot
parent 459bf2f421
commit e842f89ff7
3 changed files with 83 additions and 107 deletions

View File

@ -115,8 +115,6 @@ void ObConfigItem::init(Scope::ScopeInfo scope_info,
set_name(name); set_name(name);
if (!set_value(def)) { if (!set_value(def)) {
OB_LOG_RET(ERROR, common::OB_ERR_UNEXPECTED, "Set config item value failed", K(name), K(def)); OB_LOG_RET(ERROR, common::OB_ERR_UNEXPECTED, "Set config item value failed", K(name), K(def));
} else if (!set_default_value(def)) {
OB_LOG_RET(ERROR, common::OB_ERR_UNEXPECTED, "Set config item default value failed", K(name), K(def));
} else { } else {
set_info(info); set_info(info);
attr_ = attr; attr_ = attr;
@ -768,7 +766,7 @@ ObConfigMomentItem::ObConfigMomentItem(ObConfigContainer *container,
const char *def, const char *def,
const char *info, const char *info,
const ObParameterAttr attr) const ObParameterAttr attr)
: value_() : value_()
{ {
MEMSET(value_str_, 0, sizeof(value_str_)); MEMSET(value_str_, 0, sizeof(value_str_));
MEMSET(value_reboot_str_, 0, sizeof(value_reboot_str_)); MEMSET(value_reboot_str_, 0, sizeof(value_reboot_str_));

View File

@ -148,18 +148,6 @@ public:
} }
return ret == OB_SUCCESS; return ret == OB_SUCCESS;
} }
bool set_default_value(const char *str)
{
int64_t pos = 0;
int ret = OB_SUCCESS;
const char *ptr = value_default_ptr();
if (nullptr == ptr) {
ret = OB_INVALID_ARGUMENT;
} else {
ret = databuff_printf(const_cast<char *>(ptr), value_default_len(), pos, "%s", str);
}
return OB_SUCCESS == ret;
}
virtual bool set_dump_value(const char *str) virtual bool set_dump_value(const char *str)
{ {
UNUSED(str); UNUSED(str);
@ -201,10 +189,6 @@ public:
ObLatchRGuard rd_guard(const_cast<ObLatch&>(lock_), ObLatchIds::CONFIG_LOCK); ObLatchRGuard rd_guard(const_cast<ObLatch&>(lock_), ObLatchIds::CONFIG_LOCK);
return value_ptr(); return value_ptr();
} }
const char *default_str() const
{
return value_default_ptr();
}
int case_compare(const char* str) const int case_compare(const char* str) const
{ {
ObLatchRGuard rd_guard(const_cast<ObLatch&>(lock_), ObLatchIds::CONFIG_LOCK); ObLatchRGuard rd_guard(const_cast<ObLatch&>(lock_), ObLatchIds::CONFIG_LOCK);
@ -257,7 +241,10 @@ public:
virtual ObConfigItemType get_config_item_type() const { virtual ObConfigItemType get_config_item_type() const {
return ObConfigItemType::OB_CONF_ITEM_TYPE_UNKNOWN; return ObConfigItemType::OB_CONF_ITEM_TYPE_UNKNOWN;
} }
const char *default_str() const
{
return value_default_ptr();
}
protected: protected:
//use current value to do input operation //use current value to do input operation
virtual bool set(const char *str) = 0; virtual bool set(const char *str) = 0;
@ -266,8 +253,6 @@ protected:
virtual uint64_t value_len() const = 0; virtual uint64_t value_len() const = 0;
virtual uint64_t value_reboot_len() const = 0; virtual uint64_t value_reboot_len() const = 0;
virtual const char *value_default_ptr() const = 0; virtual const char *value_default_ptr() const = 0;
virtual uint64_t value_default_len() const = 0;
const ObConfigChecker *ck_; const ObConfigChecker *ck_;
int64_t version_; int64_t version_;
int64_t dumped_version_; int64_t dumped_version_;
@ -345,19 +330,18 @@ protected:
int size_; int size_;
bool valid_; bool valid_;
}; };
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
struct ObInnerConfigIntListItem value_; struct ObInnerConfigIntListItem value_;
static const uint64_t VALUE_BUF_SIZE = 32 * MAX_INDEX_SIZE; static const uint64_t VALUE_BUF_SIZE = 32 * MAX_INDEX_SIZE;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
DISALLOW_COPY_AND_ASSIGN(ObConfigIntListItem); DISALLOW_COPY_AND_ASSIGN(ObConfigIntListItem);
}; };
@ -406,7 +390,6 @@ public:
virtual ObConfigItemType get_config_item_type() const { virtual ObConfigItemType get_config_item_type() const {
return ObConfigItemType::OB_CONF_ITEM_TYPE_STRLIST; return ObConfigItemType::OB_CONF_ITEM_TYPE_STRLIST;
} }
public: public:
static const int64_t MAX_INDEX_SIZE = 64; static const int64_t MAX_INDEX_SIZE = 64;
static const uint64_t VALUE_BUF_SIZE = 65536UL; static const uint64_t VALUE_BUF_SIZE = 65536UL;
@ -479,17 +462,16 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
DISALLOW_COPY_AND_ASSIGN(ObConfigStrListItem); DISALLOW_COPY_AND_ASSIGN(ObConfigStrListItem);
}; };
@ -537,6 +519,11 @@ protected:
virtual bool set(const char *str); virtual bool set(const char *str);
virtual int64_t parse(const char *str, bool &valid) const = 0; virtual int64_t parse(const char *str, bool &valid) const = 0;
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override
{
return get_default_ptr();
}
private: private:
int64_t value_; int64_t value_;
int64_t min_value_; int64_t min_value_;
@ -602,7 +589,6 @@ public:
return ObConfigItemType::OB_CONF_ITEM_TYPE_DOUBLE; return ObConfigItemType::OB_CONF_ITEM_TYPE_DOUBLE;
} }
virtual bool check() const override; virtual bool check() const override;
protected: protected:
//use current value to do input operation //use current value to do input operation
bool set(const char *str); bool set(const char *str);
@ -623,18 +609,16 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 64UL; static const uint64_t VALUE_BUF_SIZE = 64UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
double value_; double value_;
@ -694,7 +678,6 @@ public:
virtual ObConfigItemType get_config_item_type() const { virtual ObConfigItemType get_config_item_type() const {
return ObConfigItemType::OB_CONF_ITEM_TYPE_CAPACITY; return ObConfigItemType::OB_CONF_ITEM_TYPE_CAPACITY;
} }
protected: protected:
int64_t parse(const char *str, bool &valid) const; int64_t parse(const char *str, bool &valid) const;
const char *value_ptr() const override const char *value_ptr() const override
@ -713,18 +696,17 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 32UL; static const uint64_t VALUE_BUF_SIZE = 32UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
DISALLOW_COPY_AND_ASSIGN(ObConfigCapacityItem); DISALLOW_COPY_AND_ASSIGN(ObConfigCapacityItem);
@ -761,7 +743,6 @@ public:
virtual ObConfigItemType get_config_item_type() const { virtual ObConfigItemType get_config_item_type() const {
return ObConfigItemType::OB_CONF_ITEM_TYPE_TIME; return ObConfigItemType::OB_CONF_ITEM_TYPE_TIME;
} }
protected: protected:
int64_t parse(const char *str, bool &valid) const; int64_t parse(const char *str, bool &valid) const;
const char *value_ptr() const override const char *value_ptr() const override
@ -780,18 +761,15 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 32UL; static const uint64_t VALUE_BUF_SIZE = 32UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
DISALLOW_COPY_AND_ASSIGN(ObConfigTimeItem); DISALLOW_COPY_AND_ASSIGN(ObConfigTimeItem);
@ -827,7 +805,6 @@ public:
virtual ObConfigItemType get_config_item_type() const { virtual ObConfigItemType get_config_item_type() const {
return ObConfigItemType::OB_CONF_ITEM_TYPE_INT; return ObConfigItemType::OB_CONF_ITEM_TYPE_INT;
} }
protected: protected:
int64_t parse(const char *str, bool &valid) const; int64_t parse(const char *str, bool &valid) const;
const char *value_ptr() const override const char *value_ptr() const override
@ -846,18 +823,15 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 32UL; static const uint64_t VALUE_BUF_SIZE = 32UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
DISALLOW_COPY_AND_ASSIGN(ObConfigIntItem); DISALLOW_COPY_AND_ASSIGN(ObConfigIntItem);
@ -900,7 +874,6 @@ public:
} }
return *this; return *this;
} }
public: public:
struct ObInnerConfigMomentItem struct ObInnerConfigMomentItem
{ {
@ -929,18 +902,15 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 64UL; static const uint64_t VALUE_BUF_SIZE = 64UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
struct ObInnerConfigMomentItem value_; struct ObInnerConfigMomentItem value_;
@ -965,7 +935,6 @@ public:
virtual ObConfigItemType get_config_item_type() const { virtual ObConfigItemType get_config_item_type() const {
return ObConfigItemType::OB_CONF_ITEM_TYPE_BOOL; return ObConfigItemType::OB_CONF_ITEM_TYPE_BOOL;
} }
protected: protected:
//use current value to do input operation //use current value to do input operation
bool set(const char *str); bool set(const char *str);
@ -986,18 +955,15 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 8UL; static const uint64_t VALUE_BUF_SIZE = 8UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
bool value_; bool value_;
@ -1048,7 +1014,6 @@ public:
} }
return *this; return *this;
} }
protected: protected:
//use current value to do input operation //use current value to do input operation
bool set(const char *str) { UNUSED(str); return true; } bool set(const char *str) { UNUSED(str); return true; }
@ -1068,18 +1033,15 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 65536UL; static const uint64_t VALUE_BUF_SIZE = 65536UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
DISALLOW_COPY_AND_ASSIGN(ObConfigStringItem); DISALLOW_COPY_AND_ASSIGN(ObConfigStringItem);
@ -1212,18 +1174,17 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
//if there is subclass from ObConfigLogArchiveOptionsItem, please implement it in
//ob_parameter_macro.h
//virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return NULL; //get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 2048UL; static const uint64_t VALUE_BUF_SIZE = 2048UL;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
private: private:
DISALLOW_COPY_AND_ASSIGN(ObConfigLogArchiveOptionsItem); DISALLOW_COPY_AND_ASSIGN(ObConfigLogArchiveOptionsItem);
@ -1280,7 +1241,6 @@ public:
return ret; return ret;
} }
ObConfigVersionItem &operator = (int64_t value); ObConfigVersionItem &operator = (int64_t value);
protected: protected:
virtual bool set(const char *str) override; virtual bool set(const char *str) override;
virtual int64_t parse(const char *str, bool &valid) const override; virtual int64_t parse(const char *str, bool &valid) const override;
@ -1300,18 +1260,15 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
static const uint64_t VALUE_BUF_SIZE = 32UL; // 32 is enough for version like 4.2.0.0 static const uint64_t VALUE_BUF_SIZE = 32UL; // 32 is enough for version like 4.2.0.0
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
char value_dump_str_[VALUE_BUF_SIZE]; char value_dump_str_[VALUE_BUF_SIZE];
bool dump_value_updated_; bool dump_value_updated_;
@ -1404,21 +1361,18 @@ protected:
{ {
return sizeof(value_reboot_str_); return sizeof(value_reboot_str_);
} }
virtual const char *get_default_ptr() const = 0;
const char *value_default_ptr() const override const char *value_default_ptr() const override
{ {
return value_default_str_; return get_default_ptr();
}
uint64_t value_default_len() const override
{
return sizeof(value_default_str_);
} }
protected: protected:
static const uint64_t VALUE_BUF_SIZE = 65536UL; static const uint64_t VALUE_BUF_SIZE = 65536UL;
static const int64_t MAX_MODE_BYTES = 32; static const int64_t MAX_MODE_BYTES = 32;
ObConfigParser *parser_; ObConfigParser *parser_;
char value_str_[VALUE_BUF_SIZE]; char value_str_[VALUE_BUF_SIZE];
char value_reboot_str_[VALUE_BUF_SIZE]; char value_reboot_str_[VALUE_BUF_SIZE];
char value_default_str_[VALUE_BUF_SIZE];
// max bits size: 8 * 32 = 256 // max bits size: 8 * 32 = 256
uint8_t value_[MAX_MODE_BYTES]; uint8_t value_[MAX_MODE_BYTES];
private: private:

View File

@ -40,7 +40,7 @@
common::ObConfigWorkAreaPolicyChecker, args)) common::ObConfigWorkAreaPolicyChecker, args))
// TODO: use parameter instead of config // TODO: use parameter instead of config
#define _DEF_PARAMETER_EASY(access_specifier, param, scope, name, args...) \ #define _DEF_PARAMETER_EASY(access_specifier, param, scope, name, def, args...) \
access_specifier: \ access_specifier: \
class ObConfig ## param ## Item ## _ ## name \ class ObConfig ## param ## Item ## _ ## name \
: public common::ObConfig ## param ## Item \ : public common::ObConfig ## param ## Item \
@ -48,7 +48,7 @@ access_specifier:
public: \ public: \
ObConfig ## param ## Item ## _ ## name() \ ObConfig ## param ## Item ## _ ## name() \
: common::ObConfig ## param ## Item(local_container(), scope, #name, \ : common::ObConfig ## param ## Item(local_container(), scope, #name, \
args) {} \ def, args) {} \
template <class T> \ template <class T> \
ObConfig ## param ## Item ## _ ## name& operator=(T value) \ ObConfig ## param ## Item ## _ ## name& operator=(T value) \
{ \ { \
@ -56,9 +56,15 @@ access_specifier:
return *this; \ return *this; \
} \ } \
TO_STRING_KV(K_(value_str)) \ TO_STRING_KV(K_(value_str)) \
protected: \
const char *value_default_str_ = def; \
const char *get_default_ptr() const override \
{ \
return value_default_str_; \
} \
} name; } name;
#define _DEF_PARAMETER_RANGE_EASY(access_specifier, param, scope, name, args...) \ #define _DEF_PARAMETER_RANGE_EASY(access_specifier, param, scope, name, def, args...) \
access_specifier: \ access_specifier: \
class ObConfig ## param ## Item ## _ ## name \ class ObConfig ## param ## Item ## _ ## name \
: public common::ObConfig ## param ## Item \ : public common::ObConfig ## param ## Item \
@ -66,13 +72,19 @@ access_specifier:
public: \ public: \
ObConfig ## param ## Item ## _ ## name() \ ObConfig ## param ## Item ## _ ## name() \
: common::ObConfig ## param ## Item(local_container(), scope, \ : common::ObConfig ## param ## Item(local_container(), scope, \
#name, args) {} \ #name, def, args) {} \
template <class T> \ template <class T> \
ObConfig ## param ## Item ## _ ## name& operator=(T value) \ ObConfig ## param ## Item ## _ ## name& operator=(T value) \
{ \ { \
common::ObConfig ## param ## Item::operator=(value); \ common::ObConfig ## param ## Item::operator=(value); \
return *this; \ return *this; \
} \ } \
protected: \
const char *value_default_str_ = def; \
const char *get_default_ptr() const override \
{ \
return value_default_str_; \
} \
} name; } name;
#define _DEF_PARAMETER_CHECKER_EASY(access_specifier, param, scope, name, def, checker, args...) \ #define _DEF_PARAMETER_CHECKER_EASY(access_specifier, param, scope, name, def, checker, args...) \
@ -93,6 +105,12 @@ access_specifier:
common::ObConfig ## param ## Item::operator=(value); \ common::ObConfig ## param ## Item::operator=(value); \
return *this; \ return *this; \
} \ } \
protected: \
const char *value_default_str_ = def; \
const char *get_default_ptr() const override \
{ \
return value_default_str_; \
} \
} name; } name;
#define _DEF_PARAMETER_PARSER_EASY(access_specifier, param, scope, name, def, parser, args...) \ #define _DEF_PARAMETER_PARSER_EASY(access_specifier, param, scope, name, def, parser, args...) \
@ -105,6 +123,12 @@ access_specifier:
: common::ObConfig ## param ## Item( \ : common::ObConfig ## param ## Item( \
local_container(), scope, #name, def, \ local_container(), scope, #name, def, \
new (std::nothrow) parser(), args) {} \ new (std::nothrow) parser(), args) {} \
protected: \
const char *value_default_str_ = def; \
const char *get_default_ptr() const override \
{ \
return value_default_str_; \
} \
} name; } name;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////