示例#1
0
        public async Task ExecAll()
        {
            var table = DateTime.Now.ToString("yyyyMMddHHmmss");
            var cols  = new[]
            {
                new ColumnFamily("info")
                {
                    Compression      = Compression.GZ,
                    KeepDeletedCells = KeepDeletedCells.TRUE
                },
                new ColumnFamily("special")
                {
                    Compression       = Compression.GZ,
                    KeepDeletedCells  = KeepDeletedCells.TTL,
                    DataBlockEncoding = DataBlockEncoding.PREFIX
                }
            };
            var create = new CreateTableCall(table, cols)
            {
                SplitKeys = new[] { "0", "5" }
            };
            var disable = new DisableTableCall(table);
            var delete  = new DeleteTableCall(table);

            var ct = await _admin.CreateTable(create);

            Log.Logger.Information($"Create table: {table},result:{ct}");
            var dt = await _admin.DisableTable(disable);

            Log.Logger.Information($"Disable table: {table},result:{dt}");
            var del = await _admin.DeleteTable(delete);

            Log.Logger.Information($"Delete table: {table},result:{del}");
        }
示例#2
0
        public async Task <bool> CreateTable(CreateTableCall t, CancellationToken?token = null)
        {
            token ??= DefaultCancellationSource.Token;
            var res = await SendRPC(t, token);

            if (res?.Msg is CreateTableResponse create)
            {
                return(await CheckProcedureWithBackoff(create.ProcId, token.Value));
            }

            return(false);
        }
示例#3
0
        public async Task ExecAll()
        {
            var table = DateTime.Now.ToString("yyyyMMddHHmmss");
            var cols  = new[]
            {
                new ColumnFamily(ConstByte.DefaultFamily)
                {
                    Compression      = Compression.GZ,
                    KeepDeletedCells = KeepDeletedCells.TRUE
                },
                new ColumnFamily("special")
                {
                    Compression       = Compression.GZ,
                    KeepDeletedCells  = KeepDeletedCells.TTL,
                    DataBlockEncoding = DataBlockEncoding.PREFIX
                }
            };
            var create = new CreateTableCall(table, cols)
            {
                SplitKeys = new[] { "0", "5" }
            };
            var disable = new DisableTableCall(table);
            var delete  = new DeleteTableCall(table);

            var status = await _admin.GetClusterStatus();

            foreach (var liveServer in status.ClusterStatus.LiveServers)
            {
                foreach (var regionLoad in liveServer.ServerLoad.RegionLoads)
                {
                    Log.Logger.Information($"RegionSpecifier:{regionLoad.RegionSpecifier.Value.ToStringUtf8()}");
                }
            }


            var ct = await _admin.CreateTable(create);

            Log.Logger.Information($"Create table: {table},result:{ct}");
            var dt = await _admin.DisableTable(disable);

            Log.Logger.Information($"Disable table: {table},result:{dt}");
            var del = await _admin.DeleteTable(delete);

            Log.Logger.Information($"Delete table: {table},result:{del}");
        }
示例#4
0
        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Debug()
                         .WriteTo.Console(
                outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger();

            HBaseConfig.Instance.ServiceProvider = new ServiceCollection()
                                                   .AddLogging(cfg => cfg.AddSerilog(Log.Logger))
                                                   .BuildServiceProvider();

            StudentFaker = new Faker <Student>()
                           .StrictMode(true)
                           .RuleFor(t => t.Name, f => f.Name.FindName())
                           .RuleFor(t => t.Address, f => f.Address.FullAddress())
                           .RuleFor(t => t.Age, f => f.Random.Int(1, 100))
                           .RuleFor(t => t.Create, f => f.Date.Recent())
                           .RuleFor(t => t.Modify, f => f.Date.Soon().OrNull(f))
                           .RuleFor(t => t.Score, f => f.Random.Float(0, 5))
                           .RuleFor(t => t.IsMarried, f => f.Random.Bool().OrNull(f))
                           .RuleFor(t => t.Courses, f => Enumerable.Range(0, f.Random.Int(0, 10)).Select(i => f.Company.CompanyName()).ToList().OrNull(f))
            ;
            Values = new Dictionary <string, Dictionary <string, byte[]> >
            {
                {
                    ConstString.DefaultFamily, new Dictionary <string, byte[]>
                    {
                        { "key", "value".ToUtf8Bytes() }
                    }
                }
            };
            var client = await new StandardClient(ZkQuorum).Build();

            if (client == null)
            {
                return;
            }
            var admin = await new AdminClient(ZkQuorum).Build();

            if (admin == null)
            {
                return;
            }
            var ado = new AdminClientOperation(admin);
            await ado.ExecAll();


            var sth = new Stopwatch();
            var sto = new SingleThreadOperation(client);

            var create = new CreateTableCall(Table.ToUtf8Bytes(), new[] { new ColumnFamily(ConstString.DefaultFamily), new ColumnFamily("special") })
            {
                SplitKeys = Enumerable.Range('1', 9).Concat(Enumerable.Range('a', 6)).Select(t => $"{(char)t}")
                            .ToArray()
            };

            var tables = await admin.ListTableNames(new ListTableNamesCall { Regex = Table });

            if (true != tables?.Any())
            {
                await admin.CreateTable(create);
            }

            await sto.ExecCheckAndPut();

            const int putCount = 10000;

            var mto = new MultiThreadOperation(client);

            sth.Restart();
            await mto.ExecPut(putCount);

            Log.Logger.Information($"exec multi thread put ,count: {putCount},take :{sth.Elapsed}");

            sth.Restart();
            await sto.ExecPut(putCount / 100);

            Log.Logger.Information($"exec single thread put ,count: {putCount / 100},take :{sth.Elapsed}");

            await sto.ExecAppend();

            await sto.ExecIncrement();

            sth.Restart();
            await sto.ExecScan();

            Log.Logger.Information($"exec scan,take :{sth.Elapsed}");
            await sto.ExecScanAndDelete();

            Console.WriteLine($"Do you want to delete table {Table}?(y)");
            if (Console.ReadKey().Key == ConsoleKey.Y)
            {
                await admin.DisableTable(new DisableTableCall(Table.ToUtf8Bytes()));

                var dt = await admin.DeleteTable(new DeleteTableCall(Table.ToUtf8Bytes()));

                Log.Logger.Information($"del table:{Table},result:{dt}");
            }
        }
示例#5
0
文件: Program.cs 项目: ahweb/HBaseNet
        static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .MinimumLevel.Debug()
                         .WriteTo.Console(
                outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}")
                         .CreateLogger();

            HBaseConfig.Instance.ServiceProvider = new ServiceCollection()
                                                   .AddLogging(cfg => cfg.AddSerilog(Log.Logger))
                                                   .BuildServiceProvider();

            Family = new Dictionary <string, string[]>
            {
                { "default", new[] { "key" } }
            };
            Values = new Dictionary <string, IDictionary <string, byte[]> >
            {
                {
                    "default", new Dictionary <string, byte[]>
                    {
                        { "key", "value".ToUtf8Bytes() }
                    }
                }
            };
            var client = await new StandardClient(ZkQuorum).Build();

            if (client == null)
            {
                return;
            }
            var admin = await new AdminClient(ZkQuorum).Build();

            if (admin == null)
            {
                return;
            }
            var ado = new AdminClientOperation(admin);
            await ado.ExecAll();


            var sth = new Stopwatch();
            var sto = new SingleThreadOperation(client);

            var create = new CreateTableCall(Table.ToUtf8Bytes(), new[] { new ColumnFamily("default"), })
            {
                SplitKeys = Enumerable.Range('1', 9).Concat(Enumerable.Range('a', 6)).Select(t => $"{(char)t}").ToArray()
            };

            var tables = await admin.ListTableNames(new ListTableNamesCall { Regex = Table });

            if (true != tables?.Any())
            {
                await admin.CreateTable(create);
            }

            await sto.ExecCheckAndPut();

            const int putCount = 10000;

            var mto = new MultiThreadOperation(client);

            sth.Restart();
            await mto.ExecPut(putCount);

            Log.Logger.Information($"exec multi thread put ,count: {putCount},take :{sth.Elapsed}");

            sth.Restart();
            await sto.ExecPut(putCount / 100);

            Log.Logger.Information($"exec single thread put ,count: {putCount / 100},take :{sth.Elapsed}");

            await sto.ExecAppend();

            await sto.ExecIncrement();

            sth.Restart();
            await sto.ExecScan();

            Log.Logger.Information($"exec scan,take :{sth.Elapsed}");
            await sto.ExecScanAndDelete();

            Console.WriteLine($"Do you want to delete table {Table}?(y)");
            if (Console.ReadKey().Key == ConsoleKey.Y)
            {
                await admin.DisableTable(new DisableTableCall(Table.ToUtf8Bytes()));

                var dt = await admin.DeleteTable(new DeleteTableCall(Table.ToUtf8Bytes()));

                Log.Logger.Information($"del table:{Table},result:{dt}");
            }
        }