-
-
Save Taik/0788d61dc48868c1aa98 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(pprof) list establishRegion | |
Total: 1932512 | |
ROUTINE ======================== <...>/vendor/github.com/tsuna/gohbase.(*client).establishRegion in <...>/vendor/github.com/tsuna/gohbase/client.go | |
0 1453748 (flat, cum) 75.23% of Total | |
. . 851: var err error | |
. . 852: reg := originalReg | |
. . 853: backoff := backoffStart | |
. . 854: | |
. . 855: for { | |
. 90115 856: ctx, _ := context.WithTimeout(context.Background(), regionLookupTimeout) | |
. . 857: if port != 0 && err == nil { | |
. . 858: // If this isn't the admin or meta region, check if a client | |
. . 859: // for this host/port already exists | |
. . 860: if c.clientType != adminClient && reg != c.metaRegionInfo { | |
. . 861: client := c.clients.checkForClient(host, port) | |
. . 862: if client != nil { | |
. . 863: // There's already a client, add it to the | |
. . 864: // cache and mark the new region as available. | |
. 10926 865: c.clients.put(reg, client) | |
. . 866: originalReg.MarkAvailable() | |
. . 867: return | |
. . 868: } | |
. . 869: } | |
. . 870: // Make this channel buffered so that if we time out we don't | |
. . 871: // block the newRegion goroutine forever. | |
. . 872: ch := make(chan newRegResult, 1) | |
. . 873: var clientType region.ClientType | |
. . 874: if c.clientType == standardClient { | |
. . 875: clientType = region.RegionClient | |
. . 876: } else { | |
. . 877: clientType = region.MasterClient | |
. . 878: } | |
. . 879: go newRegionClient(ctx, ch, clientType, host, port, c.rpcQueueSize, c.flushInterval) | |
. . 880: | |
. . 881: select { | |
. . 882: case res := <-ch: | |
. . 883: if res.Err == nil { | |
. . 884: if c.clientType == adminClient { | |
. . 885: c.adminClient = res.Client | |
. . 886: } else if reg == c.metaRegionInfo { | |
. . 887: c.metaClient = res.Client | |
. . 888: } else { | |
. . 889: c.clients.put(reg, res.Client) | |
. . 890: if reg != originalReg { | |
. . 891: // Here `reg' is guaranteed to be available, so we | |
. . 892: // must publish the region->client mapping first, | |
. . 893: // because as soon as we add it to the key->region | |
. . 894: // mapping here, concurrent readers are gonna want | |
. . 895: // to find the client. | |
. . 896: c.regions.put(reg.RegionName, reg) | |
. . 897: } | |
. . 898: } | |
. . 899: originalReg.MarkAvailable() | |
. . 900: return | |
. . 901: } else { | |
. . 902: err = res.Err | |
. . 903: } | |
. . 904: case <-ctx.Done(): | |
. . 905: err = ErrDeadline | |
. . 906: } | |
. . 907: } | |
. . 908: if err != nil { | |
. . 909: if err == TableNotFound { | |
. . 910: c.regions.del(originalReg.RegionName) | |
. . 911: originalReg.MarkAvailable() | |
. . 912: return | |
. . 913: } | |
. . 914: // This will be hit if either there was an error locating the | |
. . 915: // region, or the region was located but there was an error | |
. . 916: // connecting to it. | |
. . 917: backoff, err = sleepAndIncreaseBackoff(ctx, backoff) | |
. . 918: if err != nil { | |
. . 919: continue | |
. . 920: } | |
. . 921: } | |
. . 922: if c.clientType == adminClient { | |
. . 923: host, port, err = c.zkLookup(ctx, zk.Master) | |
. . 924: } else if reg == c.metaRegionInfo { | |
. . 925: host, port, err = c.zkLookup(ctx, zk.Meta) | |
. . 926: } else { | |
. 1352707 927: reg, host, port, err = c.locateRegion(ctx, originalReg.Table, originalReg.StartKey) | |
. . 928: } | |
. . 929: } | |
. . 930:} | |
ROUTINE ======================== github.com/Magnetic/aardvark/vendor/github.com/tsuna/gohbase.(*client).reestablishRegion in /Users/thinhnguyen/go/src/github.com/Magnetic/aardvark/vendor/github.com/tsuna/gohbase/client.go | |
0 1453748 (flat, cum) 75.23% of Total | |
. . 842: | |
. . 843: return reg, host, port, nil | |
. . 844:} | |
. . 845: | |
. . 846:func (c *client) reestablishRegion(reg *regioninfo.Info) { | |
. 1453748 847: c.establishRegion(reg, "", 0) | |
. . 848:} | |
. . 849: | |
. . 850:func (c *client) establishRegion(originalReg *regioninfo.Info, host string, port uint16) { | |
. . 851: var err error | |
. . 852: reg := originalReg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(pprof) list InfoFromCell | |
Total: 1932512 | |
ROUTINE ======================== <...>/vendor/github.com/tsuna/gohbase/regioninfo.InfoFromCell in <...>/vendor/github.com/tsuna/gohbase/regioninfo/info.go | |
374531 1352707 (flat, cum) 70.00% of Total | |
. . 50: const pbufMagic = 1346524486 // 4 bytes: "PBUF" | |
. . 51: magic := binary.BigEndian.Uint32(value) | |
. . 52: if magic != pbufMagic { | |
. . 53: return nil, fmt.Errorf("invalid magic number in %q", cell) | |
. . 54: } | |
. . 55: regInfo := &pb.RegionInfo{} | |
. 978176 56: err := proto.UnmarshalMerge(value[4:len(value)-4], regInfo) | |
. . 57: if err != nil { | |
. . 58: return nil, fmt.Errorf("failed to decode %q: %s", cell, err) | |
. . 59: } | |
. . 60: return &Info{ | |
. . 61: Table: regInfo.TableName.Qualifier, | |
. . 62: RegionName: cell.Row, | |
. . 63: StartKey: regInfo.StartKey, | |
. . 64: StopKey: regInfo.EndKey, | |
374531 374531 65: availableLock: sync.Mutex{}, | |
. . 66: }, nil | |
. . 67:} | |
. . 68: | |
. . 69:// IsUnavailable returns true if this region has been marked as unavailable. | |
. . 70:func (i *Info) IsUnavailable() bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(pprof) list locateRegion | |
Total: 1932512 | |
ROUTINE ======================== <...>/vendor/github.com/tsuna/gohbase.(*client).locateRegion in <...>/vendor/github.com/tsuna/gohbase/client.go | |
0 1352707 (flat, cum) 70.00% of Total | |
. . 740: | |
. . 741:// Locates the region in which the given row key for the given table is. | |
. . 742:func (c *client) locateRegion(ctx context.Context, | |
. . 743: table, key []byte) (*regioninfo.Info, string, uint16, error) { | |
. . 744: | |
. . 745: metaKey := createRegionSearchKey(table, key) | |
. . 746: rpc, err := hrpc.NewGetBefore(ctx, metaTableName, metaKey, hrpc.Families(infoFamily)) | |
. . 747: if err != nil { | |
. . 748: return nil, "", 0, err | |
. . 749: } | |
. . 750: rpc.SetRegion(c.metaRegionInfo) | |
. . 751: resp, err := c.sendRPC(rpc) | |
. . 752: | |
. . 753: if err != nil { | |
. . 754: ch := c.metaRegionInfo.GetAvailabilityChan() | |
. . 755: if ch != nil { | |
. . 756: select { | |
. . 757: case <-ch: | |
. . 758: return c.locateRegion(ctx, table, key) | |
. . 759: case <-rpc.GetContext().Done(): | |
. . 760: return nil, "", 0, ErrDeadline | |
. . 761: } | |
. . 762: } else { | |
. . 763: return nil, "", 0, err | |
. . 764: } | |
. . 765: } | |
. . 766: | |
. . 767: metaRow := resp.(*pb.GetResponse) | |
. . 768: if metaRow.Result == nil { | |
. . 769: return nil, "", 0, TableNotFound | |
. . 770: } | |
. . 771: | |
. 1352707 772: reg, host, port, err := c.parseMetaTableResponse(metaRow) | |
. . 773: if err != nil { | |
. . 774: return nil, "", 0, err | |
. . 775: } | |
. . 776: if !bytes.Equal(table, reg.Table) { | |
. . 777: // This would indicate a bug in HBase. | |
(pprof) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(pprof) list parseMetaTableResponse | |
Total: 1932512 | |
ROUTINE ======================== <...>/vendor/github.com/tsuna/gohbase.(*client).parseMetaTableResponse in <...>/vendor/github.com/tsuna/gohbase/client.go | |
0 1352707 (flat, cum) 70.00% of Total | |
. . 797: | |
. . 798: for _, cell := range metaRow.Result.Cell { | |
. . 799: switch string(cell.Qualifier) { | |
. . 800: case "regioninfo": | |
. . 801: var err error | |
. 1352707 802: reg, err = regioninfo.InfoFromCell(cell) | |
. . 803: if err != nil { | |
. . 804: return nil, "", 0, err | |
. . 805: } | |
. . 806: case "server": | |
. . 807: value := cell.Value | |
. . 808: if len(value) == 0 { | |
. . 809: continue // Empty during NSRE. | |
. . 810: } | |
. . 811: colon := bytes.IndexByte(value, ':') | |
. . 812: if colon < 1 { // Colon can't be at the beginning. | |
. . 813: return nil, "", 0, | |
. . 814: fmt.Errorf("broken meta: no colon found in info:server %q", cell) | |
. . 815: } | |
. . 816: host = string(value[:colon]) | |
. . 817: portU64, err := strconv.ParseUint(string(value[colon+1:]), 10, 16) | |
. . 818: if err != nil { | |
. . 819: return nil, "", 0, err | |
. . 820: } | |
. . 821: port = uint16(portU64) | |
. . 822: default: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment