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

[Enhancement] Make some system tables query from leader fe (backport #51763) #51823

Merged
merged 3 commits into from
Oct 12, 2024
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 @@ -14,11 +14,26 @@

package com.starrocks.catalog.system;

import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Lists;
import com.starrocks.analysis.DescriptorTable.ReferencedPartitionInfo;
import com.starrocks.catalog.Column;
import com.starrocks.catalog.ScalarType;
import com.starrocks.catalog.Table;
import com.starrocks.catalog.system.information.BeConfigsSystemTable;
import com.starrocks.catalog.system.information.BeTabletsSystemTable;
import com.starrocks.catalog.system.information.FeTabletSchedulesSystemTable;
import com.starrocks.catalog.system.information.LoadTrackingLogsSystemTable;
import com.starrocks.catalog.system.information.LoadsSystemTable;
import com.starrocks.catalog.system.information.MaterializedViewsSystemTable;
import com.starrocks.catalog.system.information.PartitionsMetaSystemTable;
import com.starrocks.catalog.system.information.PipesSystemTable;
import com.starrocks.catalog.system.information.RoutineLoadJobsSystemTable;
import com.starrocks.catalog.system.information.StreamLoadsSystemTable;
import com.starrocks.catalog.system.information.TablesConfigSystemTable;
import com.starrocks.catalog.system.information.TaskRunsSystemTable;
import com.starrocks.catalog.system.information.TasksSystemTable;
import com.starrocks.catalog.system.information.ViewsSystemTable;
import com.starrocks.thrift.TSchemaTable;
import com.starrocks.thrift.TSchemaTableType;
import com.starrocks.thrift.TTableDescriptor;
Expand All @@ -39,11 +54,30 @@ public class SystemTable extends Table {
public static final int NAME_CHAR_LEN = 2048;
public static final int MAX_FIELD_VARCHAR_LENGTH = 65535;

// some metadata may be inaccurate in the follower fe, because they may be not persisted in leader fe,
// such as routine load job state changed from NEED_SCHEDULE to RUNNING.
private static final ImmutableSortedSet<String> QUERY_FROM_LEADER_TABLES =
ImmutableSortedSet.orderedBy(String.CASE_INSENSITIVE_ORDER)
.add(FeTabletSchedulesSystemTable.NAME)
.add(LoadTrackingLogsSystemTable.NAME)
.add(LoadsSystemTable.NAME)
.add(MaterializedViewsSystemTable.NAME)
.add(PartitionsMetaSystemTable.NAME)
.add(PipesSystemTable.NAME)
.add(RoutineLoadJobsSystemTable.NAME)
.add(StreamLoadsSystemTable.NAME)
.add(TablesConfigSystemTable.NAME)
.add(TaskRunsSystemTable.NAME)
.add(TasksSystemTable.NAME)
.add(ViewsSystemTable.NAME)
.build();

private final TSchemaTableType schemaTableType;

private final String catalogName;

public SystemTable(long id, String name, TableType type, List<Column> baseSchema, TSchemaTableType schemaTableType) {
public SystemTable(long id, String name, TableType type, List<Column> baseSchema,
TSchemaTableType schemaTableType) {
this(DEFAULT_INTERNAL_CATALOG_NAME, id, name, type, baseSchema, schemaTableType);
}

Expand All @@ -65,12 +99,12 @@ public static boolean isFeSchemaTable(String name) {

public boolean requireOperatePrivilege() {
return (SystemTable.isBeSchemaTable(getName()) || SystemTable.isFeSchemaTable(getName())) &&
!getName().equals("be_tablets") && !getName().equals("fe_tablet_schedules");
!getName().equals(BeTabletsSystemTable.NAME) && !getName().equals(FeTabletSchedulesSystemTable.NAME);
}

@Override
public boolean supportsUpdate() {
return name.equals("be_configs");
return name.equals(BeConfigsSystemTable.NAME);
}

@Override
Expand Down Expand Up @@ -125,4 +159,8 @@ public TTableDescriptor toThrift(List<ReferencedPartitionInfo> partitions) {
public boolean isSupported() {
return true;
}

public static boolean needQueryFromLeader(String tableName) {
return QUERY_FROM_LEADER_TABLES.contains(tableName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeBvarsSystemTable {
private static final String NAME = "be_bvars";

public static SystemTable create() {
return new SystemTable(SystemId.BE_BVARS_ID,
"be_bvars",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT), false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeCloudNativeCompactionsSystemTable {
private static final String NAME = "be_cloud_native_compactions";

public static SystemTable create() {
return new SystemTable(SystemId.BE_CLOUD_NATIVE_COMPACTIONS,
"be_cloud_native_compactions",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeCompactionsSystemTable {
private static final String NAME = "be_compactions";

public static SystemTable create() {
return new SystemTable(SystemId.BE_COMPACTIONS_ID,
"be_compactions",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeConfigsSystemTable {
public static final String NAME = "be_configs";

public static SystemTable create() {
return new SystemTable(SystemId.BE_CONFIGS_ID,
"be_configs",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeLogsSystemTable {
private static final String NAME = "be_logs";

public static SystemTable create() {
return new SystemTable(SystemId.BE_LOGS_ID,
"be_logs",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeMetricsSystemTable {
private static final String NAME = "be_metrics";

public static SystemTable create() {
return new SystemTable(SystemId.BE_METRICS_ID,
"be_metrics",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeTabletsSystemTable {
public static final String NAME = "be_tablets";

public static SystemTable create() {
return new SystemTable(SystemId.BE_TABLETS_ID,
"be_tablets",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeThreadsSystemTable {
private static final String NAME = "be_threads";

public static SystemTable create() {
return new SystemTable(SystemId.BE_THREADS_ID,
"be_threads",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class BeTxnsSystemTable {
private static final String NAME = "be_txns";

public static SystemTable create() {
return new SystemTable(SystemId.BE_TXNS_ID,
"be_txns",
NAME,
Table.TableType.SCHEMA,
builder()
.column("BE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class CharacterSetsSystemTable {
private static final String NAME = "character_sets";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.CHARACTER_SETS_ID,
"character_sets",
NAME,
Table.TableType.SCHEMA,
builder()
.column("CHARACTER_SET_NAME", ScalarType.createVarchar(512))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class CollationsSystemTable {
private static final String NAME = "collations";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.COLLATIONS_ID,
"collations",
NAME,
Table.TableType.SCHEMA,
builder()
.column("COLLATION_NAME", ScalarType.createVarchar(512))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class ColumnPrivilegesSystemTable {
private static final String NAME = "column_privileges";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.COLUMN_PRIVILEGES_ID,
"column_privileges",
NAME,
Table.TableType.SCHEMA,
builder()
.column("GRANTEE", ScalarType.createVarchar(NAME_CHAR_LEN))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class ColumnsSystemTable {
private static final String NAME = "columns";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.COLUMNS_ID,
"columns",
NAME,
Table.TableType.SCHEMA,
builder()
.column("TABLE_CATALOG", ScalarType.createVarchar(512))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class EnginesSystemTable {
private static final String NAME = "engines";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.ENGINES_ID,
"engines",
NAME,
Table.TableType.SCHEMA,
builder()
.column("ENGINE", ScalarType.createVarchar(64))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class EventsSystemTable {
private static final String NAME = "events";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.EVENTS_ID,
"events",
NAME,
Table.TableType.SCHEMA,
builder()
.column("EVENT_CATALOG", ScalarType.createVarchar(64))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class FeMetricsSystemTable {
public static final String NAME = "fe_metrics";

public static SystemTable create() {
return new SystemTable(SystemId.FE_METRICS_ID,
"fe_metrics",
NAME,
Table.TableType.SCHEMA,
builder()
.column("FE_ID", ScalarType.createVarchar(NAME_CHAR_LEN))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class FeTabletSchedulesSystemTable {
public static final String NAME = "fe_tablet_schedules";

public static SystemTable create() {
return new SystemTable(SystemId.FE_SCHEDULES_ID,
"fe_tablet_schedules",
NAME,
Table.TableType.SCHEMA,
builder()
.column("TABLE_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class GlobalVariablesSystemTable {
private static final String NAME = "global_variables";

public static SystemTable create() {
return new SystemTable(SystemId.GLOBAL_VARIABLES_ID,
"global_variables",
NAME,
Table.TableType.SCHEMA,
builder()
.column("VARIABLE_NAME", ScalarType.createVarchar(64))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class KeyColumnUsageSystemTable {
private static final String NAME = "key_column_usage";

public static SystemTable create(String catalogName) {
return new SystemTable(
catalogName,
SystemId.KEY_COLUMN_USAGE_ID,
"key_column_usage",
NAME,
Table.TableType.SCHEMA,
builder()
.column("CONSTRAINT_CATALOG", ScalarType.createVarchar(NAME_CHAR_LEN))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class LoadTrackingLogsSystemTable {
public static final String NAME = "load_tracking_logs";

public static SystemTable create() {
return new SystemTable(SystemId.LOAD_TRACKING_LOGS_ID,
"load_tracking_logs",
NAME,
Table.TableType.SCHEMA,
builder()
.column("JOB_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class LoadsSystemTable {
public static final String NAME = "loads";

public static SystemTable create() {
return new SystemTable(SystemId.LOADS_ID,
"loads",
NAME,
Table.TableType.SCHEMA,
builder()
.column("JOB_ID", ScalarType.createType(PrimitiveType.BIGINT))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class MaterializedViewsSystemTable {
public static final String NAME = "materialized_views";

public static SystemTable create() {
return new SystemTable(SystemId.MATERIALIZED_VIEWS_ID,
"materialized_views",
NAME,
Table.TableType.SCHEMA,
builder()
.column("MATERIALIZED_VIEW_ID", ScalarType.createVarchar(50))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@
import static com.starrocks.catalog.system.SystemTable.builder;

public class PartitionsMetaSystemTable {
public static final String NAME = "partitions_meta";

public static SystemTable create() {
return new SystemTable(SystemId.PARTITIONS_META_ID,
"partitions_meta",
NAME,
Table.TableType.SCHEMA,
builder()
.column("DB_NAME", ScalarType.createVarchar(NAME_CHAR_LEN))
Expand Down
Loading
Loading