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
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ under the License.
2) 重命名数据库
ALTER DATABASE db_name RENAME new_db_name;

3) 设置数据库的副本数量配额
ALTER DATABASE db_name SET REPLICA QUOTA quota;

说明:
重命名数据库后,如需要,请使用 REVOKE 和 GRANT 命令修改相应的用户权限。
重命名数据库后,如需要,请使用 REVOKE 和 GRANT 命令修改相应的用户权限。
数据库的默认数据量配额为1024GB,默认副本数量配额为1073741824。

## example
1. 设置指定数据库数据量配额
Expand All @@ -42,6 +46,9 @@ under the License.

2. 将数据库 example_db 重命名为 example_db2
ALTER DATABASE example_db RENAME example_db2;

3. 设定指定数据库副本数量配额
ALTER DATABASE example_db SET REPLICA QUOTA 102400;

## keyword
ALTER,DATABASE,RENAME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ under the License.

# SHOW DATA
## description
该语句用于展示数据量
该语句用于展示数据量和副本数量
语法:
SHOW DATA [FROM db_name[.table_name]];

说明:
1. 如果不指定 FROM 子句,使用展示当前 db 下细分到各个 table 的数据量
2. 如果指定 FROM 子句,则展示 table 下细分到各个 index 的数据量
1. 如果不指定 FROM 子句,使用展示当前 db 下细分到各个 table 的数据量和副本数量
2. 如果指定 FROM 子句,则展示 table 下细分到各个 index 的数据量和副本数量
3. 如果想查看各个 Partition 的大小,请参阅 help show partitions

## example
1. 展示默认 db 的各个 table 的数据量及汇总数据量
1. 展示默认 db 的各个 table 的数据量,副本数量,汇总数据量和汇总副本数量。
SHOW DATA;

2. 展示指定 db 的下指定表的细分数据量
2. 展示指定 db 的下指定表的细分数据量和副本数量
SHOW DATA FROM example_db.table_name;

## keyword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ALTER DATABASE db_name RENAME new_db_name;

Explain:
After renaming the database, use REVOKE and GRANT commands to modify the corresponding user rights if necessary.
The database's default data quota is 1024GB, and the default replica quota is 1073741824.

## example
1. Setting the specified database data quota
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,20 @@ under the License.

# SHOW DATA
## Description
This statement is used to show the amount of data
This statement is used to show the amount of data and the number of replica
Grammar:
SHOW DATA [FROM db_name[.table_name]];

Explain:
1. If you do not specify the FROM clause, use the amount of data that shows the current DB subdivided into tables
2. If the FROM clause is specified, the amount of data subdivided into indices under the table is shown.
1. If you do not specify the FROM clause, use the amount of data and the number of replica that shows the current DB subdivided into tables
2. If the FROM clause is specified, the amount of data and the number of replica subdivided into indices under the table is shown.
3. If you want to see the size of individual Partitions, see help show partitions

## example
1. Display the data volume and aggregate data volume of each table of default DB
1. Display the data volume, replica size, aggregate data volume and aggregate replica count of each table of default DB
SHOW DATA;

2. Display the subdivision data volume of the specified table below the specified DB
2. Display the subdivision data volume and replica count of the specified table below the specified DB
SHOW DATA FROM example_db.table_name;

## keyword
Expand Down
8 changes: 7 additions & 1 deletion fe/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;

import org.apache.doris.analysis.AlterDatabaseQuotaStmt.QuotaType;
import org.apache.doris.analysis.SetOperationStmt.Qualifier;
import org.apache.doris.analysis.SetOperationStmt.Operation;
import org.apache.doris.analysis.SetOperationStmt.SetOperand;
Expand Down Expand Up @@ -711,8 +712,13 @@ alter_stmt ::=
:}
| KW_ALTER KW_DATABASE ident:dbName KW_SET KW_DATA KW_QUOTA quantity:quota_quantity
{:
RESULT = new AlterDatabaseQuotaStmt(dbName, quota_quantity);
RESULT = new AlterDatabaseQuotaStmt(dbName, QuotaType.DATA, quota_quantity);
:}
| KW_ALTER KW_DATABASE ident:dbName KW_SET KW_REPLICA KW_QUOTA INTEGER_LITERAL:number
{:
RESULT = new AlterDatabaseQuotaStmt(dbName, QuotaType.REPLICA, String.valueOf(number));
:}

| KW_ALTER KW_DATABASE ident:dbName KW_RENAME ident:newDbName
{:
RESULT = new AlterDatabaseRename(dbName, newDbName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,20 @@

public class AlterDatabaseQuotaStmt extends DdlStmt {
private String dbName;
private String quotaQuantity;
private QuotaType quotaType;
private String quotaValue;
private long quota;

public AlterDatabaseQuotaStmt(String dbName, String quotaQuantity) {
public enum QuotaType {
NONE,
DATA,
REPLICA
}

public AlterDatabaseQuotaStmt(String dbName, QuotaType quotaType, String quotaValue) {
this.dbName = dbName;
this.quotaQuantity = quotaQuantity;
this.quotaType = quotaType;
this.quotaValue = quotaValue;
}

public String getDbName() {
Expand All @@ -46,7 +54,10 @@ public long getQuota() {
return quota;
}


public QuotaType getQuotaType() {
return quotaType;
}

@Override
public void analyze(Analyzer analyzer) throws UserException {
super.analyze(analyzer);
Expand All @@ -59,11 +70,16 @@ public void analyze(Analyzer analyzer) throws UserException {
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
}
dbName = ClusterNamespace.getFullName(getClusterName(), dbName);
quota = ParseUtil.analyzeDataVolumn(quotaQuantity);
if (quotaType == QuotaType.DATA) {
quota = ParseUtil.analyzeDataVolumn(quotaValue);
} else if (quotaType == QuotaType.REPLICA) {
quota = ParseUtil.analyzeReplicaNumber(quotaValue);
}

}

@Override
public String toSql() {
return "ALTER DATABASE " + dbName + " SET DATA QUOTA " + quotaQuantity;
return "ALTER DATABASE " + dbName + " SET " + (quotaType == QuotaType.DATA ? "DATA" : "REPLICA") +" QUOTA " + quotaValue;
}
}
27 changes: 20 additions & 7 deletions fe/src/main/java/org/apache/doris/analysis/ShowDataStmt.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ public class ShowDataStmt extends ShowStmt {
ShowResultSetMetaData.builder()
.addColumn(new Column("TableName", ScalarType.createVarchar(20)))
.addColumn(new Column("Size", ScalarType.createVarchar(30)))
.addColumn(new Column("ReplicaCount", ScalarType.createVarchar(20)))
.build();

private static final ShowResultSetMetaData SHOW_INDEX_DATA_META_DATA =
ShowResultSetMetaData.builder()
.addColumn(new Column("TableName", ScalarType.createVarchar(20)))
.addColumn(new Column("IndexName", ScalarType.createVarchar(20)))
.addColumn(new Column("Size", ScalarType.createVarchar(30)))
.addColumn(new Column("ReplicaCount", ScalarType.createVarchar(20)))
.build();

private String dbName;
Expand Down Expand Up @@ -94,6 +96,7 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
try {
if (tableName == null) {
long totalSize = 0;
long totalReplicaCount = 0;

// sort by table name
List<Table> tables = db.getTables();
Expand All @@ -120,36 +123,42 @@ public int compare(Table t1, Table t2) {

OlapTable olapTable = (OlapTable) table;
long tableSize = olapTable.getDataSize();
long replicaCount = olapTable.getReplicaCount();

Pair<Double, String> tableSizePair = DebugUtil.getByteUint(tableSize);
String readableSize = DebugUtil.DECIMAL_FORMAT_SCALE_3.format(tableSizePair.first) + " "
+ tableSizePair.second;

List<String> row = Arrays.asList(table.getName(), readableSize);
List<String> row = Arrays.asList(table.getName(), readableSize, String.valueOf(replicaCount));
totalRows.add(row);

totalSize += tableSize;
totalReplicaCount += replicaCount;
} // end for tables

Pair<Double, String> totalSizePair = DebugUtil.getByteUint(totalSize);
String readableSize = DebugUtil.DECIMAL_FORMAT_SCALE_3.format(totalSizePair.first) + " "
+ totalSizePair.second;
List<String> total = Arrays.asList("Total", readableSize);
List<String> total = Arrays.asList("Total", readableSize, String.valueOf(totalReplicaCount));
totalRows.add(total);

// quota
long quota = db.getDataQuota();
long replicaQuota = db.getReplicaQuota();
Pair<Double, String> quotaPair = DebugUtil.getByteUint(quota);
String readableQuota = DebugUtil.DECIMAL_FORMAT_SCALE_3.format(quotaPair.first) + " "
+ quotaPair.second;
List<String> quotaRow = Arrays.asList("Quota", readableQuota);

List<String> quotaRow = Arrays.asList("Quota", readableQuota, String.valueOf(replicaQuota));
totalRows.add(quotaRow);

// left
long left = Math.max(0, quota - totalSize);
long replicaCountLeft = Math.max(0, replicaQuota - totalReplicaCount);
Pair<Double, String> leftPair = DebugUtil.getByteUint(left);
String readableLeft = DebugUtil.DECIMAL_FORMAT_SCALE_3.format(leftPair.first) + " "
+ leftPair.second;
List<String> leftRow = Arrays.asList("Left", readableLeft);
List<String> leftRow = Arrays.asList("Left", readableLeft, String.valueOf(replicaCountLeft));
totalRows.add(leftRow);
} else {
if (!Catalog.getCurrentCatalog().getAuth().checkTblPriv(ConnectContext.get(), dbName,
Expand All @@ -173,6 +182,7 @@ public int compare(Table t1, Table t2) {
OlapTable olapTable = (OlapTable) table;
int i = 0;
long totalSize = 0;
long totalReplicaCount = 0;

// sort by index name
Map<String, Long> indexNames = olapTable.getIndexNameToId();
Expand All @@ -183,9 +193,11 @@ public int compare(Table t1, Table t2) {

for (Long indexId : sortedIndexNames.values()) {
long indexSize = 0;
long indexReplicaCount = 0;
for (Partition partition : olapTable.getAllPartitions()) {
MaterializedIndex mIndex = partition.getIndex(indexId);
indexSize += mIndex.getDataSize();
indexReplicaCount += mIndex.getReplicaCount();
}

Pair<Double, String> indexSizePair = DebugUtil.getByteUint(indexSize);
Expand All @@ -196,14 +208,15 @@ public int compare(Table t1, Table t2) {
if (i == 0) {
row = Arrays.asList(tableName,
olapTable.getIndexNameById(indexId),
readableSize);
readableSize, String.valueOf(indexReplicaCount));
} else {
row = Arrays.asList("",
olapTable.getIndexNameById(indexId),
readableSize);
readableSize, String.valueOf(indexReplicaCount));
}

totalSize += indexSize;
totalReplicaCount += indexReplicaCount;
totalRows.add(row);

i++;
Expand All @@ -212,7 +225,7 @@ public int compare(Table t1, Table t2) {
Pair<Double, String> totalSizePair = DebugUtil.getByteUint(totalSize);
String readableSize = DebugUtil.DECIMAL_FORMAT_SCALE_3.format(totalSizePair.first) + " "
+ totalSizePair.second;
List<String> row = Arrays.asList("", "Total", readableSize);
List<String> row = Arrays.asList("", "Total", readableSize, String.valueOf(totalReplicaCount));
totalRows.add(row);
}
} finally {
Expand Down
22 changes: 16 additions & 6 deletions fe/src/main/java/org/apache/doris/catalog/Catalog.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.doris.analysis.AlterClause;
import org.apache.doris.analysis.AlterClusterStmt;
import org.apache.doris.analysis.AlterDatabaseQuotaStmt;
import org.apache.doris.analysis.AlterDatabaseQuotaStmt.QuotaType;
import org.apache.doris.analysis.AlterDatabaseRename;
import org.apache.doris.analysis.AlterSystemStmt;
import org.apache.doris.analysis.AlterTableStmt;
Expand Down Expand Up @@ -2781,16 +2782,25 @@ public void alterDatabaseQuota(AlterDatabaseQuotaStmt stmt) throws DdlException
ErrorReport.reportDdlException(ErrorCode.ERR_BAD_DB_ERROR, dbName);
}

db.setDataQuotaWithLock(stmt.getQuota());

DatabaseInfo dbInfo = new DatabaseInfo(dbName, "", db.getDataQuota());
QuotaType quotaType = stmt.getQuotaType();
if (quotaType == QuotaType.DATA) {
db.setDataQuotaWithLock(stmt.getQuota());
} else if (quotaType == QuotaType.REPLICA) {
db.setReplicaQuotaWithLock(stmt.getQuota());
}
long quota = stmt.getQuota();
DatabaseInfo dbInfo = new DatabaseInfo(dbName, "", quota, quotaType);
editLog.logAlterDb(dbInfo);
}

public void replayAlterDatabaseQuota(String dbName, long quota) {
public void replayAlterDatabaseQuota(String dbName, long quota, QuotaType quotaType) {
Database db = getDb(dbName);
Preconditions.checkNotNull(db);
db.setDataQuotaWithLock(quota);
if (quotaType == QuotaType.DATA) {
db.setDataQuotaWithLock(quota);
} else if (quotaType == QuotaType.REPLICA) {
db.setReplicaQuotaWithLock(quota);
}
}

public void renameDatabase(AlterDatabaseRename stmt) throws DdlException {
Expand Down Expand Up @@ -2835,7 +2845,7 @@ public void renameDatabase(AlterDatabaseRename stmt) throws DdlException {
fullNameToDb.remove(fullDbName);
fullNameToDb.put(newFullDbName, db);

DatabaseInfo dbInfo = new DatabaseInfo(fullDbName, newFullDbName, -1L);
DatabaseInfo dbInfo = new DatabaseInfo(fullDbName, newFullDbName, -1L, QuotaType.NONE);
editLog.logDatabaseRename(dbInfo);
} finally {
unlock();
Expand Down
Loading