Exemplo n.º 1
0
        private async Task <RegionInfo> FindRegionInfoForRPC(byte[] table, byte[] key, CancellationToken token)
        {
            var result    = default(RegionInfo);
            var searchKey = RegionInfo.CreateRegionSearchKey(table, key);
            var rpc       = new ScanCall(_metaTableName, searchKey, table)
            {
                Families     = _infoFamily,
                CloseScanner = true,
                Reversed     = true,
                NumberOfRows = 1,
                Info         = _metaRegionInfo
            };

            await _metaClient.QueueRPC(rpc);

            var res = await _metaClient.GetRPCResult(rpc.CallId);

            if (res?.Msg is ScanResponse scanResponse)
            {
                result = RegionInfo.ParseFromScanResponse(scanResponse);
            }

            if (result != null)
            {
                _logger.LogInformation($"Find region info :{result.Name.ToUtf8String()}, at {result.Host}:{result.Port}");
            }
            return(result);
        }
Exemplo n.º 2
0
        private async Task <bool> CheckProcedureWithBackoff(ulong procId, CancellationToken token)
        {
            var backoff = BackoffStart;
            var oldTime = DateTime.Now;

            while (DateTime.Now - oldTime < Timeout)
            {
                var req = new GetProcedureStateCall(procId);
                await _adminClient.QueueRPC(req);

                var res = await _adminClient.GetRPCResult(req.CallId);

                if (res == null)
                {
                    return(false);
                }

                if (res.Msg is GetProcedureResultResponse rep)
                {
                    switch (rep.State)
                    {
                    case GetProcedureResultResponse.Types.State.NotFound:
                        return(false);

                    case GetProcedureResultResponse.Types.State.Finished:
                        return(true);
                    }
                }
                else if (res.Error != null)
                {
                    switch (res.Error)
                    {
                    case DoNotRetryIOException _:
                        return(false);
                    }
                }
                backoff = await TaskEx.SleepAndIncreaseBackoff(backoff, BackoffIncrease, token);
            }

            return(false);
        }