Skip to content

Commit

Permalink
Fix issues (#2001)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

1. add show queries HTTP API document
2. admin show variable {var_name}, use 'role' to replace server_role.
3. add value type check in set config value.
4. SQL: SHOW QUERY SESSION LONG_VALUE => SHOW QUERY LONG_VALUE
5. SQL: EXPORT PROFILE LONG_VALUE {file_path} => EXPORT PROFILES
LONG_VALUE {file_path}

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
- [x] Documentation Update
- [x] Refactoring

---------

Signed-off-by: Jin Hai <[email protected]>
  • Loading branch information
JinHai-CN authored Oct 9, 2024
1 parent 1f9b2e4 commit a3b6a13
Show file tree
Hide file tree
Showing 11 changed files with 1,716 additions and 1,604 deletions.
78 changes: 77 additions & 1 deletion docs/references/http_api_reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,7 @@ A `500` HTTP status code indicates an error condition. The response includes a J
**GET** `/instance/profiles`
When set session variable 'enable_profiling', Infinity will record query profile information. This command is to list recorded queries profile.
When set session variable 'profile', Infinity will record query profile information. This command is to list recorded queries profile.
### Request
Expand Down Expand Up @@ -2562,3 +2562,79 @@ A `500` HTTP status code indicates an error condition. The response includes a J
</Tabs>
---
## Show queries
**GET** `/instance/queries`
Show running queries, only valid when config: record_running_query is set.
### Request
- Method: GET
- URL: `/instance/queries`
- Headers: `accept: application/json`
#### Request example
```shell
curl --request GET \
--url http://localhost:23820/instance/queries \
--header 'accept: application/json'
```
### Response
<Tabs
defaultValue="s200"
values={[
{label: 'Status code 200', value: 's200'},
{label: 'Status code 500', value: 's500'},
]}>
<TabItem value="s200">
The response includes a JSON object like the following:
```shell
{
"error_code": 0,
"queries": [
{
"query_id": "1928",
"query_kind": "COPY",
"session_id": "63",
"start_time": "21:22:49:708:989:0",
"time_consumption": "2s"
}
]
}
```
- `"error_code"`: `integer`
`0`: The operation succeeds.
</TabItem>
<TabItem value="s500">
A `500` HTTP status code indicates an error condition. The response includes a JSON object like the following:
```shell
{
"error_code": 2005,
"error_message": "Not support in maintenance mode"
}
```
- `"error_code"`: `integer`
A non-zero value indicates a specific error condition.
- `"error_message"`: `string`
When `error_code` is non-zero, `"error_message"` provides additional details about the error.
</TabItem>
</Tabs>
---
6 changes: 5 additions & 1 deletion src/admin/admin_executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3574,11 +3574,15 @@ QueryResult AdminExecutor::ShowVariable(QueryContext *query_context, const Admin
String variable_name = admin_statement->variable_name_.value();
ToLower(variable_name);

if (variable_name == "server_role") {
if (variable_name == "role") {
output_block_ptr->Init(output_column_types);
Value value = Value::MakeVarchar(ToString(InfinityContext::instance().GetServerRole()));
ValueExpression value_expr(value);
value_expr.AppendToChunk(output_block_ptr->column_vectors[0]);
} else {
query_result.result_table_ = nullptr;
query_result.status_ = Status::NoSysVar(variable_name);
return query_result;
}
output_block_ptr->Finalize();
query_result.result_table_->Append(std::move(output_block_ptr));
Expand Down
28 changes: 28 additions & 0 deletions src/executor/operator/physical_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
GlobalOptionIndex config_index = config->GetOptionIndex(set_command->var_name());
switch(config_index) {
case GlobalOptionIndex::kLogLevel: {
if (set_command->value_type() != SetVarType::kString) {
Status status = Status::DataTypeMismatch("String", set_command->value_type_str());
RecoverableError(status);
}
if (set_command->value_str() == "trace") {
SetLogLevel(LogLevel::kTrace);
config->SetLogLevel(LogLevel::kTrace);
Expand Down Expand Up @@ -185,6 +189,10 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
break;
}
case GlobalOptionIndex::kRecordRunningQuery: {
if (set_command->value_type() != SetVarType::kBool) {
Status status = Status::DataTypeMismatch("Boolean", set_command->value_type_str());
RecoverableError(status);
}
bool flag = set_command->value_bool();
if(config->RecordRunningQuery() && !flag) {
// turn off the query recording and clean all query record.
Expand All @@ -194,6 +202,10 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
break;
}
case GlobalOptionIndex::kCleanupInterval: {
if (set_command->value_type() != SetVarType::kInteger) {
Status status = Status::DataTypeMismatch("Integer", set_command->value_type_str());
RecoverableError(status);
}
i64 interval = set_command->value_int();
if(interval < 0) {
Status status = Status::InvalidCommand(fmt::format("Attempt to set cleanup interval: {}", interval));
Expand All @@ -204,6 +216,10 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
break;
}
case GlobalOptionIndex::kFullCheckpointInterval: {
if (set_command->value_type() != SetVarType::kInteger) {
Status status = Status::DataTypeMismatch("Integer", set_command->value_type_str());
RecoverableError(status);
}
i64 interval = set_command->value_int();
if(interval < 0) {
Status status = Status::InvalidCommand(fmt::format("Attempt to set full checkpoint interval: {}", interval));
Expand All @@ -214,6 +230,10 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
break;
}
case GlobalOptionIndex::kDeltaCheckpointInterval: {
if (set_command->value_type() != SetVarType::kInteger) {
Status status = Status::DataTypeMismatch("Integer", set_command->value_type_str());
RecoverableError(status);
}
i64 interval = set_command->value_int();
if(interval < 0) {
Status status = Status::InvalidCommand(fmt::format("Attempt to set delta checkpoint interval: {}", interval));
Expand All @@ -224,6 +244,10 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
break;
}
case GlobalOptionIndex::kCompactInterval: {
if (set_command->value_type() != SetVarType::kInteger) {
Status status = Status::DataTypeMismatch("Integer", set_command->value_type_str());
RecoverableError(status);
}
i64 interval = set_command->value_int();
if(interval < 0) {
Status status = Status::InvalidCommand(fmt::format("Attempt to set compact segment interval: {}", interval));
Expand All @@ -234,6 +258,10 @@ bool PhysicalCommand::Execute(QueryContext *query_context, OperatorState *operat
break;
}
case GlobalOptionIndex::kOptimizeIndexInterval: {
if (set_command->value_type() != SetVarType::kInteger) {
Status status = Status::DataTypeMismatch("Integer", set_command->value_type_str());
RecoverableError(status);
}
i64 interval = set_command->value_int();
if(interval < 0) {
Status status = Status::InvalidCommand(fmt::format("Attempt to set optimize interval interval: {}", interval));
Expand Down
2 changes: 1 addition & 1 deletion src/main/variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void VarUtil::InitVariablesMap() {
session_name_map_[TOTAL_COMMIT_COUNT_VAR_NAME.data()] = SessionVariable::kTotalCommitCount;
session_name_map_[TOTAL_ROLLBACK_COUNT_VAR_NAME.data()] = SessionVariable::kTotalRollbackCount;
session_name_map_[CONNECTED_TS_VAR_NAME.data()] = SessionVariable::kConnectedTime;
session_name_map_["enable_profile"] = SessionVariable::kEnableProfile;
session_name_map_["profile"] = SessionVariable::kEnableProfile;
}

HashMap<String, GlobalVariable> VarUtil::global_name_map_;
Expand Down
Loading

0 comments on commit a3b6a13

Please sign in to comment.