// GetTablet is a high level function to read tablet data.
// It generates trace spans.
778288
func (ts *Server) GetTablet(ctx context.Context, alias *topodatapb.TabletAlias) (*TabletInfo, error) {
	conn, err := ts.ConnForCell(ctx, alias.Cell)
	if err != nil {
		return nil, err
	}

	span, ctx := trace.NewSpan(ctx, "TopoServer.GetTablet")
	span.Annotate("tablet", topoproto.TabletAliasString(alias))
	defer span.Finish()

	tabletPath := path.Join(TabletsPath, topoproto.TabletAliasString(alias), TabletFile)
	data, version, err := conn.Get(ctx, tabletPath)
	if err != nil {
		return nil, err
	}
	tablet := &topodatapb.Tablet{}
	if err := proto.Unmarshal(data, tablet); err != nil {
		return nil, err
	}

	return &TabletInfo{
		version: version,
		Tablet:  tablet,
	}, nil
}
1284006
func (f *TableFile) GetString(ref ResStringPoolRef) string {
	return f.stringPool.GetString(ref)
}
1340524
func TableDefinitionGetColumn(td *tabletmanagerdatapb.TableDefinition, name string) (index int, ok bool) {
	lowered := strings.ToLower(name)
	for i, n := range td.Columns {
		if lowered == strings.ToLower(n) {
			return i, true
		}
	}
	return -1, false
}
1284732
func (c *Client) GetHost(hostID string) (*host.Host, error) {
	response := host.New()
	if err := c.call("GetHost", hostID, response); err != nil {
		return nil, err
	}
	return response, nil
}
774599
func (ts *Server) DeleteTablet(ctx context.Context, tabletAlias *topodatapb.TabletAlias) error {
	conn, err := ts.ConnForCell(ctx, tabletAlias.Cell)
	if err != nil {
		return err
	}

	// get the current tablet record, if any, to log the deletion
	ti, tErr := ts.GetTablet(ctx, tabletAlias)

	tabletPath := path.Join(TabletsPath, topoproto.TabletAliasString(tabletAlias), TabletFile)
	if err := conn.Delete(ctx, tabletPath, nil); err != nil {
		return err
	}

	// Only try to log if we have the required info.
	if tErr == nil {
		// Only copy the identity info for the tablet. The rest has been deleted.
		event.Dispatch(&events.TabletChange{
			Tablet: topodatapb.Tablet{
				Alias:    tabletAlias,
				Keyspace: ti.Tablet.Keyspace,
				Shard:    ti.Tablet.Shard,
			},
			Status: "deleted",
		})
	}
	return nil
}
1079802
func GetHost(r *http.Request) string {
	h := r.URL.Host
	if h == "" {
		h = r.Host
	}
	return h
}
101038
func GetColorTable(target uint32, format uint32, xtype uint32, table unsafe.Pointer) {
	C.glowGetColorTable(gpGetColorTable, (C.GLenum)(target), (C.GLenum)(format), (C.GLenum)(xtype), table)
}
110893
func NewTablet(uid uint32, cell, host string) *topodatapb.Tablet {
	return &topodatapb.Tablet{
		Alias: &topodatapb.TabletAlias{
			Cell: cell,
			Uid:  uid,
		},
		Hostname: host,
		PortMap:  make(map[string]int32),
	}
}
394394
func (fbs *FilterByShard) ReplaceTablet(old, new *topodatapb.Tablet, name string) {
	if fbs.isIncluded(old) && fbs.isIncluded(new) {
		fbs.tr.ReplaceTablet(old, new, name)
	}
}
224531
func CopyTablets(ctx context.Context, fromTS, toTS *topo.Server) {
	cells, err := fromTS.GetKnownCells(ctx)
	if err != nil {
		log.Fatalf("fromTS.GetKnownCells: %v", err)
	}

	for _, cell := range cells {
		tabletAliases, err := fromTS.GetTabletsByCell(ctx, cell)
		if err != nil {
			log.Fatalf("GetTabletsByCell(%v): %v", cell, err)
		} else {
			for _, tabletAlias := range tabletAliases {

				// read the source tablet
				ti, err := fromTS.GetTablet(ctx, tabletAlias)
				if err != nil {
					log.Fatalf("GetTablet(%v): %v", tabletAlias, err)
				}

				// try to create the destination
				err = toTS.CreateTablet(ctx, ti.Tablet)
				if topo.IsErrType(err, topo.NodeExists) {
					// update the destination tablet
					log.Warningf("tablet %v already exists, updating it", tabletAlias)
					_, err = toTS.UpdateTabletFields(ctx, tabletAlias, func(t *topodatapb.Tablet) error {
						*t = *ti.Tablet
						return nil
					})
				}
				if err != nil {
					log.Fatalf("CreateTablet(%v): %v", tabletAlias, err)
				}
			}
		}
	}
}
704850
func (b *Log) getTableStatus(tableName string) (tableStatus, error) {
	_, err := b.svc.DescribeTable(&dynamodb.DescribeTableInput{
		TableName: aws.String(tableName),
	})
	err = convertError(err)
	if err != nil {
		if trace.IsNotFound(err) {
			return tableStatusMissing, nil
		}
		return tableStatusError, trace.Wrap(err)
	}
	return tableStatusOK, nil
}
322164
func (t *Table) GetOffset() (row, column int) {
	return t.rowOffset, t.columnOffset
}
396116
func GetDataset(name string) (*Dataset, error) {
	if !DatasetExists(name) {
		return nil, fmt.Errorf("Dataset not found")
	}
	return &Dataset{
		Name: name,
	}, nil
}
201799
func (hc *HealthCheckImpl) ReplaceTablet(old, new *topodatapb.Tablet, name string) {
	go func() {
		hc.deleteConn(old)
		hc.AddTablet(new, name)
	}()
}
1052542
func getHost(r *http.Request) string {
	if r.Host != "" {
		return r.Host
	}

	return r.URL.Host
}
1317413
func (h *Handle) GetTableStats(tblInfo *model.TableInfo) *statistics.Table {
	return h.GetPartitionStats(tblInfo, tblInfo.ID)
}
280112
func getTables(store *cassandra.CassandraStore, match string) ([]cassandra.Table, error) {
	var tables []cassandra.Table
	if match == "*" || match == "" {
		for _, table := range store.TTLTables {
			if table.Name == "metric_idx" || !strings.HasPrefix(table.Name, "metric_") {
				continue
			}
			tables = append(tables, table)
		}
		sort.Sort(TablesByTTL(tables))
	} else {
		for _, table := range store.TTLTables {
			if table.Name == match {
				tables = append(tables, table)
				return tables, nil
			}
		}
		return nil, fmt.Errorf("table %q not found", match)
	}
	return tables, nil
}