Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion be/src/olap/storage_engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ std::vector<DataDir*> StorageEngine::get_stores() {
template std::vector<DataDir*> StorageEngine::get_stores<false>();
template std::vector<DataDir*> StorageEngine::get_stores<true>();

OLAPStatus StorageEngine::get_all_data_dir_info(vector<DataDirInfo>* data_dir_infos,
OLAPStatus StorageEngine::get_all_data_dir_info(std::vector<DataDirInfo>* data_dir_infos,
bool need_update) {
OLAPStatus res = OLAP_SUCCESS;
data_dir_infos->clear();
Expand Down Expand Up @@ -377,6 +377,20 @@ OLAPStatus StorageEngine::get_all_data_dir_info(vector<DataDirInfo>* data_dir_in
return res;
}

int64_t StorageEngine::get_file_or_directory_size(std::filesystem::path file_path) {
if (!std::filesystem::exists(file_path)) {
return 0;
}
if (!std::filesystem::is_directory(file_path)) {
return std::filesystem::file_size(file_path);
}
int64_t sum_size = 0;
for (const auto& it : std::filesystem::directory_iterator(file_path)) {
sum_size += get_file_or_directory_size(it.path());
}
return sum_size;
}

void StorageEngine::_start_disk_stat_monitor() {
for (auto& it : _store_map) {
it.second->health_check();
Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/storage_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class StorageEngine {
// @brief 获取所有root_path信息
OLAPStatus get_all_data_dir_info(std::vector<DataDirInfo>* data_dir_infos, bool need_update);

int64_t get_file_or_directory_size(std::filesystem::path file_path);

// get root path for creating tablet. The returned vector of root path should be random,
// for avoiding that all the tablet would be deployed one disk.
std::vector<DataDir*> get_stores_for_create_tablet(TStorageMedium::type storage_medium);
Expand Down
34 changes: 34 additions & 0 deletions be/src/service/backend_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,40 @@ void BackendService::get_tablet_stat(TTabletStatResult& result) {
StorageEngine::instance()->tablet_manager()->get_tablet_stat(&result);
}

int64_t BackendService::get_trash_used_capacity() {
int64_t result = 0;

std::vector<DataDirInfo> data_dir_infos;
StorageEngine::instance()->get_all_data_dir_info(&data_dir_infos, false /*do not update */);

for (const auto& root_path_info : data_dir_infos) {
std::string lhs_trash_path = root_path_info.path + TRASH_PREFIX;
std::filesystem::path trash_path(lhs_trash_path);
result += StorageEngine::instance()->get_file_or_directory_size(trash_path);
}
return result;
}

void BackendService::get_disk_trash_used_capacity(std::vector<TDiskTrashInfo>& diskTrashInfos) {
std::vector<DataDirInfo> data_dir_infos;
StorageEngine::instance()->get_all_data_dir_info(&data_dir_infos, false /*do not update */);

for (const auto& root_path_info : data_dir_infos) {
TDiskTrashInfo diskTrashInfo;

diskTrashInfo.__set_root_path(root_path_info.path);

diskTrashInfo.__set_state(root_path_info.is_used ? "ONLINE" : "OFFLINE");

std::string lhs_trash_path = root_path_info.path + TRASH_PREFIX;
std::filesystem::path trash_path(lhs_trash_path);
diskTrashInfo.__set_trash_used_capacity(
StorageEngine::instance()->get_file_or_directory_size(trash_path));

diskTrashInfos.push_back(diskTrashInfo);
}
}

void BackendService::submit_routine_load_task(TStatus& t_status,
const std::vector<TRoutineLoadTask>& tasks) {
for (auto& task : tasks) {
Expand Down
8 changes: 7 additions & 1 deletion be/src/service/backend_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class TQueryOptions;
class TExportTaskRequest;
class TExportStatusResult;
class TStreamLoadRecordResult;
class TDiskTrashInfo;

// This class just forward rpc for actual handler
// make this class because we can bind multiple service on single point
Expand Down Expand Up @@ -129,6 +130,10 @@ class BackendService : public BackendServiceIf {

virtual void get_tablet_stat(TTabletStatResult& result) override;

virtual int64_t get_trash_used_capacity() override;

virtual void get_disk_trash_used_capacity(std::vector<TDiskTrashInfo>& diskTrashInfos) override;

virtual void submit_routine_load_task(TStatus& t_status,
const std::vector<TRoutineLoadTask>& tasks) override;

Expand All @@ -141,7 +146,8 @@ class BackendService : public BackendServiceIf {
// used for external service, close some context and release resource related with this context
virtual void close_scanner(TScanCloseResult& result_, const TScanCloseParams& params);

virtual void get_stream_load_record(TStreamLoadRecordResult& result, const int64_t last_stream_record_time) override;
virtual void get_stream_load_record(TStreamLoadRecordResult& result,
const int64_t last_stream_record_time) override;

private:
Status start_plan_fragment_execution(const TExecPlanFragmentParams& exec_params);
Expand Down
1 change: 1 addition & 0 deletions docs/.vuepress/sidebar/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ module.exports = [
"SHOW MIGRATIONS",
"SHOW PLUGINS",
"SHOW TABLE STATUS",
"SHOW TRASH",
"UNINSTALL PLUGIN",
],
},
Expand Down
1 change: 1 addition & 0 deletions docs/.vuepress/sidebar/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ module.exports = [
"SHOW MIGRATIONS",
"SHOW PLUGINS",
"SHOW TABLE STATUS",
"SHOW TRASH",
"UNINSTALL PLUGIN",
],
},
Expand Down
53 changes: 53 additions & 0 deletions docs/en/sql-reference/sql-statements/Administration/SHOW TRASH.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
{
"title": "SHOW TRASH",
"language": "en"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

# SHOW TRASH
## description

This statement is used to view trash used capacity on some backends.

Syntax:

SHOW TRASH [ON "BackendHost:BackendHeartBeatPort"];

Explain:

1. Backend The format is BackendHost:BackendHeartBeatPort of the node.
2. TrashUsedCapacity Indicates that the trash data of the node occupies space.

## example

1. View the space occupied by trash data of all be nodes.

SHOW TRASH;

2. Check the space occupied by trash data of '192.168.0.1:9050'(The specific disk information will be displayed).

SHOW TRASH ON "192.168.0.1:9050";

## keyword
SHOW, TRASH

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
{
"title": "SHOW TRASH",
"language": "zh-CN"
}
---

<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->

# SHOW TRASH
## description
该语句用于查看 backend 内的垃圾数据占用空间。
语法:
SHOW TRASH [ON BackendHost:BackendHeartBeatPort];

说明:
1. Backend 格式为该节点的BackendHost:BackendHeartBeatPort。
2. TrashUsedCapacity 表示该节点垃圾数据占用空间。

## example

1. 查看所有be节点的垃圾数据占用空间。

SHOW TRASH;

2. 查看'192.168.0.1:9050'的垃圾数据占用空间(会显示具体磁盘信息)。

SHOW TRASH ON "192.168.0.1:9050";

## keyword
SHOW, TRASH

10 changes: 9 additions & 1 deletion fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ terminal String KW_ADD, KW_ADMIN, KW_AFTER, KW_AGGREGATE, KW_ALL, KW_ALTER, KW_A
KW_S3, KW_SCHEMA, KW_SCHEMAS, KW_SECOND, KW_SELECT, KW_SEMI, KW_SERIALIZABLE, KW_SESSION, KW_SET, KW_SETS, KW_SET_VAR, KW_SHOW, KW_SIGNED,
KW_SMALLINT, KW_SNAPSHOT, KW_SONAME, KW_SPLIT, KW_START, KW_STATUS, KW_STOP, KW_STORAGE, KW_STREAM, KW_STRING, KW_STRUCT,
KW_SUM, KW_SUPERUSER, KW_SYNC, KW_SYSTEM,
KW_TABLE, KW_TABLES, KW_TABLET, KW_TASK, KW_TEMPORARY, KW_TERMINATED, KW_THAN, KW_TIME, KW_THEN, KW_TIMESTAMP, KW_TINYINT,
KW_TABLE, KW_TABLES, KW_TABLET, KW_TASK, KW_TEMPORARY, KW_TERMINATED, KW_THAN, KW_TIME, KW_THEN, KW_TIMESTAMP, KW_TINYINT,KW_TRASH,
KW_TO, KW_TRANSACTION, KW_TRIGGERS, KW_TRIM, KW_TRUE, KW_TRUNCATE, KW_TYPE, KW_TYPES,
KW_UNCOMMITTED, KW_UNBOUNDED, KW_UNION, KW_UNIQUE, KW_UNSIGNED, KW_USE, KW_USER, KW_USING, KW_UNINSTALL,
KW_VALUE, KW_VALUES, KW_VARCHAR, KW_VARIABLES, KW_VERBOSE, KW_VIEW,
Expand Down Expand Up @@ -2554,6 +2554,14 @@ show_param ::=
{:
RESULT = new ShowBackendsStmt();
:}
| KW_TRASH KW_ON STRING_LITERAL:backend
{:
RESULT = new ShowTrashDiskStmt(backend);
:}
| KW_TRASH
{:
RESULT = new ShowTrashStmt();
:}
| KW_FRONTENDS
{:
RESULT = new ShowFrontendsStmt();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you 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.

package org.apache.doris.analysis;

import org.apache.doris.catalog.Catalog;
import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.common.proc.TrashProcNode;
import org.apache.doris.qe.ShowResultSetMetaData;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.system.Backend;
import org.apache.doris.mysql.privilege.PrivPredicate;

import com.google.common.collect.ImmutableMap;

public class ShowTrashDiskStmt extends ShowStmt {

private Backend backend;

public ShowTrashDiskStmt(String backendQuery) {
ImmutableMap<Long, Backend> backendsInfo = Catalog.getCurrentSystemInfo().getIdToBackend();
for (Backend backend : backendsInfo.values()) {
String backendStr = String.valueOf(backend.getHost()) + ":" + String.valueOf(backend.getHeartbeatPort());
if (backendQuery.equals(backendStr)) {
this.backend = backend;
break;
}
}
}

public Backend getBackend() {
return backend;
}

@Override
public void analyze(Analyzer analyzer) throws AnalysisException {
if (!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)
&& !Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(),
PrivPredicate.OPERATOR)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN/OPERATOR");
}
}

@Override
public ShowResultSetMetaData getMetaData() {
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder();
for (String title : TrashProcNode.TITLE_NAMES) {
builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
}
return builder.build();
}

@Override
public RedirectStatus getRedirectStatus() {
return RedirectStatus.NO_FORWARD;
}
}
Loading