【问题标题】:Unable to count the number of rows in BigTable无法计算 BigTable 中的行数
【发布时间】:2016-10-24 06:15:26
【问题描述】:

https://cloud.google.com/bigtable/docs/go/cbt-reference

在这个参考中,我尝试了以下命令

cbt count <table>

三个不同的表。

对于其中一个,我得到了我的预期:行数,略低于 1M。

对于第二个表,我收到以下错误:

[~]$ cbt count prod.userprofile
2016/10/23 22:47:48 Reading rows: rpc error: code = 4 desc = Error while reading table 'projects/focal-elf-631/instances/campaign-stat/tables/prod.userprofile'
[~]$ cbt count prod.userprofile
2016/10/23 23:00:23 Reading rows: rpc error: code = 4 desc = Error while reading table 'projects/focal-elf-631/instances/campaign-stat/tables/prod.userprofile'

我试了几次,但每次都报同样的错误。

对于最后一个,我得到一个不同的错误(错误代码与上面相同,但它的描述不同):

[~]$ cbt count prod.appprofile
2016/10/23 22:45:17 Reading rows: rpc error: code = 4 desc = Error while reading table 'projects/focal-elf-631/instances/campaign-stat/tables/prod.appprofile' : Response was not consumed in time; terminating connection. (Possible causes: row size > 256MB, slow client data read, and network problems)
[~]$ cbt count prod.appprofile
2016/10/23 23:11:10 Reading rows: rpc error: code = 4 desc = Error while reading table 'projects/focal-elf-631/instances/campaign-stat/tables/prod.appprofile' : Response was not consumed in time; terminating connection. (Possible causes: row size > 256MB, slow client data read, and network problems)

这个我也试了好几次,都没有变。

我用“rpc 错误代码 4”作为关键字在 stackoverflow 上搜索和搜索,但没有发现任何有用的东西。

我真的很好奇为什么这个命令会失败,以及我能做些什么来解决这个问题(顺便说一下,这两个表正在 24/7 生产中使用,我们有几十个大表节点工作得很好,所以我认为这与带宽或 QPS 无关)。

【问题讨论】:

  • 错误代码 4 是“超过最后期限”。 “计数”操作效率很低,它必须进行全表扫描才能获得行数。失败的两张表是不是特别大?另外,您是否正在使用具有自动重试功能的较新的 google-cloud-go 库,这可能会有所帮助?
  • 感谢您的解释和建议。第一个(用户配置文件)非常大,所以这对我来说并不奇怪。第二个实际上不是很大,但我会检查一下。我会试试新图书馆(我不是不知道)。谢谢!

标签: bigtable google-cloud-bigtable


【解决方案1】:

计算一张大表需要从 Bigtable 的每一行中读取一些内容。不存在仅获取表示计数的单个值的概念。

不幸的是,这类问题需要类似 map/reduce 的东西。幸运的是,count with Dataflow 非常简单。

【讨论】:

    【解决方案2】:

    另一种可能(虽然不是最好的)是使用原子计数器,即:

    1. 快乐基地:https://google-cloud-python-happybase.readthedocs.io/en/latest/happybase-table.html#google.cloud.happybase.table.Table.counter_inc
    2. 本机 API:https://googlecloudplatform.github.io/google-cloud-python/stable/bigtable-row.html#google.cloud.bigtable.row.AppendRow.increment_cell_value

    如果您在某些情况下将第二个表设计为计数器的二级索引,它可以具有良好的性能(如果您不通过同时读取和写入来破坏计数器,或者由于热点而陷入繁重的计数器 r/w) .

    尽管如此,Map/Reduce 无疑是 @solomon-duskis 提出的更强大的解决方案。

    【讨论】:

      猜你喜欢
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2016-02-29
      • 2017-02-10
      • 1970-01-01
      相关资源
      最近更新 更多