Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider refactoring proxy-mysql-default-version #23614

Closed
TeslaCN opened this issue Jan 17, 2023 · 1 comment · Fixed by #25288
Closed

Consider refactoring proxy-mysql-default-version #23614

TeslaCN opened this issue Jan 17, 2023 · 1 comment · Fixed by #25288

Comments

@TeslaCN
Copy link
Member

TeslaCN commented Jan 17, 2023

Refactor

The property proxy-mysql-default-version of server.yaml from #16796 was used to fix issue #16735.

But this solution confused many users:

I'm wondering if we could support multi-version system variables query and remove this property, which could help simplifying usage of ShardingSphere-Proxy MySQL.

@TeslaCN TeslaCN self-assigned this Apr 13, 2023
@TeslaCN TeslaCN added this to the 5.3.3 milestone Apr 13, 2023
@TeslaCN
Copy link
Member Author

TeslaCN commented Apr 20, 2023

We could generate values for Java Enum by executing the following codes in MySQL server source code.

#include <iostream>
#include <map>
#include <string>
#include "set_var.h"
#include "sys_vars.h"

using namespace std;

string generateFlag(const sys_var *v);

string generateDefaultValue(sys_var *v);

int main() {
  map<string, string> m;
  for (sys_var *v = all_sys_vars.first; v; v = v->next) {
    string name = v->name.str, generated;
    for (char c : name) {
      generated += (char)toupper(c);
    }
    generated += '(';
    string flag = generateFlag(v);
    generated += flag;
    generated += ", ";
    string def = generateDefaultValue(v);
    generated += def + ')';
    m[name] = ("\"TODO\"" == def ? "// " : "") + generated;
  }
  for (auto &iterator : m) {
    cout << iterator.second << "," << endl << endl;
  }
  return 0;
}

string generateFlag(const sys_var *v) {
  string flag;
  if (v->scope() & sys_var::GLOBAL) flag += " | Flag.GLOBAL";
  if (v->scope() & sys_var::SESSION) flag += " | Flag.SESSION";
  if (v->scope() & sys_var::ONLY_SESSION) flag += " | Flag.ONLY_SESSION";
  if (v->is_readonly()) flag += " | Flag.READONLY";
  if (v->not_visible()) flag += " | Flag.INVISIBLE";
  if (v->is_trilevel()) flag += " | Flag.TRI_LEVEL";
  if (v->is_hint_updateable()) flag += " | Flag.HINT_UPDATEABLE";
  if (v->is_persist_readonly()) flag += " | Flag.PERSIST_AS_READ_ONLY";
  if (v->is_sensitive()) flag += " | Flag.SENSITIVE";
  return flag.substr(3);
}

string generateDefaultValue(sys_var *v) {
  stringstream stream;
  stream << '"';
  switch (v->get_option()->var_type) {
    case GET_STR: {
      char *c = reinterpret_cast<char *>(v->get_option()->def_value);
      if (nullptr != c) stream << c;
      break;
    }
    case GET_INT:
    case GET_LONG:
    case GET_LL:
    case GET_BOOL: {
      stream << v->get_option()->def_value;
      break;
    }
    case GET_UINT:
    case GET_ULONG:
    case GET_ULL: {
      stream << (ulonglong)v->get_option()->def_value;
      break;
    }
    case GET_DOUBLE: {
      stream << (double)v->get_option()->def_value;
      break;
    }
    default: {
      stream << "TODO";
    }
  }
  stream << '"';
  return stream.str();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants