// Locates the region in which the given row key for the given table is. func (c *Client) locateRegion(ctx context.Context, table, key []byte) (*regioninfo.Info, string, uint16, error) { metaKey := createRegionSearchKey(table, key) rpc, err := hrpc.NewGetBefore(ctx, metaTableName, metaKey, hrpc.Families(infoFamily)) if err != nil { return nil, "", 0, err } rpc.SetRegion(c.metaRegionInfo) resp, err := c.sendRPC(rpc) if err != nil { ch := c.metaRegionInfo.GetAvailabilityChan() if ch != nil { select { case <-ch: return c.locateRegion(ctx, table, key) case <-rpc.GetContext().Done(): return nil, "", 0, ErrDeadline } } else { return nil, "", 0, err } } metaRow := resp.(*pb.GetResponse) if metaRow.Result == nil { return nil, "", 0, TableNotFound } reg, host, port, err := c.parseMetaTableResponse(metaRow) if err != nil { return nil, "", 0, err } if !bytes.Equal(table, reg.Table) { // This would indicate a bug in HBase. return nil, "", 0, fmt.Errorf("WTF: Meta returned an entry for the wrong table!"+ " Looked up table=%q key=%q got region=%s", table, key, reg) } else if len(reg.StopKey) != 0 && bytes.Compare(key, reg.StopKey) >= 0 { // This would indicate a hole in the meta table. return nil, "", 0, fmt.Errorf("WTF: Meta returned an entry for the wrong region!"+ " Looked up table=%q key=%q got region=%s", table, key, reg) } return reg, host, port, nil }
// Locates the region in which the given row key for the given table is. func (c *Client) locateRegion(ctx context.Context, table, key []byte) (*region.Client, *regioninfo.Info, error) { metaKey := createRegionSearchKey(table, key) rpc, _ := hrpc.NewGetBefore(ctx, metaTableName, metaKey, hrpc.Families(infoFamily)) rpc.SetRegion(c.metaRegionInfo) resp, err := c.sendRPC(rpc) if err != nil { ch := c.metaRegionInfo.GetAvailabilityChan() if ch != nil { select { case <-ch: return c.locateRegion(ctx, table, key) case <-rpc.GetContext().Done(): return nil, nil, ErrDeadline } } else { return nil, nil, err } } return c.discoverRegion(ctx, resp.(*pb.GetResponse)) }