github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/views/reports/containers/range/rangeInfo.ts (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 _ from "lodash";
    12  import Long from "long";
    13  
    14  import * as protos from "src/js/protos";
    15  import { FixLong } from "src/util/fixLong";
    16  
    17  export function GetLocalReplica(info: protos.cockroach.server.serverpb.IRangeInfo) {
    18    return _.find(info.state.state.desc.internal_replicas, rep => rep.store_id === info.source_store_id);
    19  }
    20  
    21  export function IsLeader(info: protos.cockroach.server.serverpb.IRangeInfo) {
    22    const localRep = GetLocalReplica(info);
    23    if (_.isNil(localRep)) {
    24      return false;
    25    }
    26    return Long.fromInt(localRep.replica_id).eq(FixLong(info.raft_state.lead));
    27  }
    28  
    29  export default {
    30    GetLocalReplica: GetLocalReplica,
    31    IsLeader: IsLeader,
    32  };