mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
added space_used columns (#2397)
added space_used columns to show tables and fb_cluster_nodes
This commit is contained in:
parent
9f042216a7
commit
164aac509e
5 changed files with 54 additions and 5 deletions
5
api.go
5
api.go
|
|
@ -3340,6 +3340,7 @@ type SystemAPI interface {
|
|||
ClusterReplicaCount() int
|
||||
ShardWidth() int
|
||||
ClusterState() string
|
||||
DataDir() string
|
||||
|
||||
ClusterNodes() []ClusterNode
|
||||
}
|
||||
|
|
@ -3408,6 +3409,10 @@ func (fsapi *FeatureBaseSystemAPI) ClusterState() string {
|
|||
return string(state)
|
||||
}
|
||||
|
||||
func (fsapi *FeatureBaseSystemAPI) DataDir() string {
|
||||
return fsapi.server.dataDir
|
||||
}
|
||||
|
||||
func (fsapi *FeatureBaseSystemAPI) ClusterNodes() []ClusterNode {
|
||||
result := make([]ClusterNode, 0)
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ func (p *ExecutionPlanner) compileShowTablesStatement(stmt parser.Statement) (ty
|
|||
dataType: parser.NewDataTypeString(),
|
||||
}}
|
||||
|
||||
return NewPlanOpQuery(p, NewPlanOpProjection(columns, NewPlanOpFeatureBaseTables(pilosa.TablesToIndexInfos(tbls))), p.sql), nil
|
||||
return NewPlanOpQuery(p, NewPlanOpProjection(columns, NewPlanOpFeatureBaseTables(p, pilosa.TablesToIndexInfos(tbls))), p.sql), nil
|
||||
}
|
||||
|
||||
func (p *ExecutionPlanner) compileShowColumnsStatement(stmt *parser.ShowColumnsStatement) (_ types.PlanOperator, err error) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package planner
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
pilosa "github.com/molecula/featurebase/v3"
|
||||
|
|
@ -15,12 +16,14 @@ import (
|
|||
// PlanOpFeatureBaseTables wraps a []*IndexInfo that is returned from
|
||||
// schemaAPI.Schema().
|
||||
type PlanOpFeatureBaseTables struct {
|
||||
planner *ExecutionPlanner
|
||||
indexInfo []*pilosa.IndexInfo
|
||||
warnings []string
|
||||
}
|
||||
|
||||
func NewPlanOpFeatureBaseTables(indexInfo []*pilosa.IndexInfo) *PlanOpFeatureBaseTables {
|
||||
func NewPlanOpFeatureBaseTables(planner *ExecutionPlanner, indexInfo []*pilosa.IndexInfo) *PlanOpFeatureBaseTables {
|
||||
return &PlanOpFeatureBaseTables{
|
||||
planner: planner,
|
||||
indexInfo: indexInfo,
|
||||
warnings: make([]string, 0),
|
||||
}
|
||||
|
|
@ -82,6 +85,11 @@ func (p *PlanOpFeatureBaseTables) Schema() types.Schema {
|
|||
ColumnName: "keys",
|
||||
Type: parser.NewDataTypeBool(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: "fb_tables",
|
||||
ColumnName: "space_used",
|
||||
Type: parser.NewDataTypeInt(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: "fb_tables",
|
||||
ColumnName: "description",
|
||||
|
|
@ -96,15 +104,17 @@ func (p *PlanOpFeatureBaseTables) Children() []types.PlanOperator {
|
|||
|
||||
func (p *PlanOpFeatureBaseTables) Iterator(ctx context.Context, row types.Row) (types.RowIterator, error) {
|
||||
return &showTablesRowIter{
|
||||
planner: p.planner,
|
||||
indexInfo: p.indexInfo,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (p *PlanOpFeatureBaseTables) WithChildren(children ...types.PlanOperator) (types.PlanOperator, error) {
|
||||
return NewPlanOpFeatureBaseTables(p.indexInfo), nil
|
||||
return NewPlanOpFeatureBaseTables(p.planner, p.indexInfo), nil
|
||||
}
|
||||
|
||||
type showTablesRowIter struct {
|
||||
planner *ExecutionPlanner
|
||||
indexInfo []*pilosa.IndexInfo
|
||||
rowIndex int
|
||||
}
|
||||
|
|
@ -113,16 +123,37 @@ var _ types.RowIterator = (*showTablesRowIter)(nil)
|
|||
|
||||
func (i *showTablesRowIter) Next(ctx context.Context) (types.Row, error) {
|
||||
if i.rowIndex < len(i.indexInfo) {
|
||||
|
||||
indexName := i.indexInfo[i.rowIndex].Name
|
||||
|
||||
var err error
|
||||
var spaceUsed pilosa.DiskUsage
|
||||
switch strings.ToLower(indexName) {
|
||||
case "fb_cluster_info", "fb_cluster_nodes", "fb_performance_counters", "fb_exec_requests", "fb_table_ddl":
|
||||
spaceUsed = pilosa.DiskUsage{
|
||||
Usage: 0,
|
||||
}
|
||||
default:
|
||||
u := i.planner.systemAPI.DataDir()
|
||||
u = fmt.Sprintf("%s/indexes/%s", u, indexName)
|
||||
|
||||
spaceUsed, err = pilosa.GetDiskUsage(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
createdAt := time.Unix(0, i.indexInfo[i.rowIndex].CreatedAt)
|
||||
updatedAt := time.Unix(0, i.indexInfo[i.rowIndex].UpdatedAt)
|
||||
row := []interface{}{
|
||||
i.indexInfo[i.rowIndex].Name,
|
||||
i.indexInfo[i.rowIndex].Name,
|
||||
indexName,
|
||||
indexName,
|
||||
i.indexInfo[i.rowIndex].Owner,
|
||||
i.indexInfo[i.rowIndex].LastUpdateUser,
|
||||
createdAt.Format(time.RFC3339),
|
||||
updatedAt.Format(time.RFC3339),
|
||||
i.indexInfo[i.rowIndex].Options.Keys,
|
||||
spaceUsed.Usage,
|
||||
i.indexInfo[i.rowIndex].Options.Description,
|
||||
}
|
||||
i.rowIndex += 1
|
||||
|
|
|
|||
|
|
@ -103,6 +103,11 @@ var systemTables = map[string]*systemTable{
|
|||
ColumnName: "is_primary",
|
||||
Type: parser.NewDataTypeBool(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: fbClusterNodes,
|
||||
ColumnName: "space_used",
|
||||
Type: parser.NewDataTypeBool(),
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
|
|
@ -323,6 +328,12 @@ func (i *fbClusterNodesRowIter) Next(ctx context.Context) (types.Row, error) {
|
|||
i.result = i.planner.systemAPI.ClusterNodes()
|
||||
}
|
||||
|
||||
u := i.planner.systemAPI.DataDir()
|
||||
spaceUsed, err := pilosa.GetDiskUsage(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(i.result) > 0 {
|
||||
n := i.result[0]
|
||||
row := []interface{}{
|
||||
|
|
@ -331,6 +342,7 @@ func (i *fbClusterNodesRowIter) Next(ctx context.Context) (types.Row, error) {
|
|||
n.URI,
|
||||
n.GRPCURI,
|
||||
n.IsPrimary,
|
||||
spaceUsed.Usage,
|
||||
}
|
||||
// Move to next result element.
|
||||
i.result = i.result[1:]
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ func TestPlanner_Show(t *testing.T) {
|
|||
wireQueryFieldString("uri"),
|
||||
wireQueryFieldString("grpc_uri"),
|
||||
wireQueryFieldBool("is_primary"),
|
||||
wireQueryFieldBool("space_used"),
|
||||
}, columns); diff != "" {
|
||||
t.Fatal(diff)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue