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 <(RegionClient client, RegionInfo info)> ResolveRegion(ICall rpc, CancellationToken token)
        {
            RegionInfo   reg    = null;
            RegionClient client = null;
            var          millisecondsTimeout = 60000;
            var          oldTime             = DateTime.Now;

            reg    = GetInfoFromCache(rpc.Table, rpc.Key);
            client = reg?.Client;
            if (true == client?.IsInvalid)
            {
                _cache.ClientDown(reg);
                client = null;
            }
            if (client == null)
            {
                _loadRegionQueue.Enqueue(rpc);
                await TaskEx.WaitOn(() =>
                {
                    reg    = GetInfoFromCache(rpc.Table, rpc.Key);
                    client = reg?.Client;
                    return(client == null && rpc.FindRegionRetryCount < RetryCount);
                }, 5, millisecondsTimeout);
            }
            return(client, reg);
        }
Exemplo n.º 3
0
 private byte[] FullyQualifiedTable(RegionInfo reg)
 {
     if (reg.Namespace?.Any() != true)
     {
         return(reg.Table);
     }
     return(BinaryEx.ConcatInOrder(reg.Namespace, new[] { ConstByte.Colon }, reg.Table));
 }
Exemplo n.º 4
0
 public StandardClient(string zkQuorum)
 {
     ZkQuorum    = zkQuorum;
     _infoFamily = new Dictionary <string, string[]>
     {
         { "info", null }
     };
     _metaTableName   = "hbase:meta".ToUtf8Bytes();
     _metaRegionInfo  = new RegionInfo(0, "hbase".ToUtf8Bytes(), "meta".ToUtf8Bytes(), "hbase:meta,,1".ToUtf8Bytes(), null);
     _cache           = new RegionCache();
     _loadRegionQueue = new ConcurrentQueue <ICall>();
     ProcessResolveRegionTask();
 }
Exemplo n.º 5
0
        private RegionInfo GetInfoFromCache(byte[] table, byte[] key)
        {
            if (BinaryComparer.Compare(table, _metaTableName) == 0)
            {
                return(_metaRegionInfo);
            }
            var search = RegionInfo.CreateRegionSearchKey(table, key);
            var info   = _cache.GetInfo(search);

            if (info == null || false == BinaryComparer.Equals(table, info.Table))
            {
                return(null);
            }
            if (info.StopKey.Length > 0 && BinaryComparer.Compare(key, info.StopKey) >= 0)
            {
                return(null);
            }
            return(info);
        }