github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/views/databases/data/tableInfo.tsx (about)

     1  // Copyright 2018 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  import * as protos from "src/js/protos";
    12  import { FixLong } from "src/util/fixLong";
    13  
    14  import _ from "lodash";
    15  
    16  type TableDetailsResponse = protos.cockroach.server.serverpb.TableDetailsResponse;
    17  type TableStatsResponse = protos.cockroach.server.serverpb.TableStatsResponse;
    18  
    19  // TableInfo is a supporting data structure which combines data about a single
    20  // table that was obtained from multiple backend sources.
    21  export class TableInfo {
    22    public name: string;
    23    public id: number;
    24    public numColumns: number;
    25    public numIndices: number;
    26    public physicalSize: number;
    27    public mvccSize: protos.cockroach.storage.enginepb.IMVCCStats;
    28    public rangeCount: number;
    29    public createStatement: string;
    30    public grants: protos.cockroach.server.serverpb.TableDetailsResponse.IGrant[];
    31    public numReplicas: number;
    32    constructor(name: string, details: TableDetailsResponse, stats: TableStatsResponse) {
    33        this.name = name;
    34        this.id = details && details.descriptor_id.toNumber();
    35        this.numColumns = details && details.columns.length;
    36        this.numIndices = details && _.uniqBy(details.indexes, idx => idx.name).length;
    37        this.rangeCount = stats && stats.range_count && stats.range_count.toNumber();
    38        this.createStatement = details && details.create_table_statement;
    39        this.grants = details && details.grants;
    40        this.numReplicas = details && details.zone_config && details.zone_config.num_replicas;
    41        if (stats) {
    42            this.mvccSize = stats.stats;
    43            this.physicalSize = FixLong(stats.approximate_disk_bytes).toNumber();
    44        }
    45    }
    46  }