【问题标题】:Amazon Keyspaces sync_table() doesn't see a table immediatelyAmazon Keyspaces sync_table() 不会立即看到表
【发布时间】:2021-07-08 05:05:35
【问题描述】:

我是cassandra-driver==3.25.0 的新手。我从Model 创建了一个模型并尝试同步它。问题:

  1. 我打电话给sync_table
  2. 我看到该表开始在 Keyspaces 中创建并且定义正确
  3. 但是sync_table 会从这行代码table = cluster.metadata.keyspaces[ks_name].tables[raw_cf_name] 引发异常KeyError {__table_name__}
  4. 我可以再次拨打sync_table,一段时间后就可以正常使用了

所以我假设它可能会从 Keyspaces 延迟,所以cassandra-driver 在同步表上有某种等待,或者你能指出文档吗?

class Users(Model):
    __keyspace__ = 'aura'
    __table_name__ = 'users'
    __connection__ = 'aws_keyspace'

    user_id = columns.UUID(primary_key=True)
    tags = columns.Map(key_type=columns.Text(), value_type=columns.Text())

cluster = Cluster(...)
session = cluster.connect()
connection.register_connection('aws_keyspace', session=session, default=True)
sync_table(Users)

完全例外:

Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "models.py", line 69, in <module>
    sync_table(AttachmentsByUsers)
  File "python3.6/site-packages/cassandra/cqlengine/management.py", line 190, in sync_table
    _sync_table(m, connection=connection)
  File "python3.6/site-packages/cassandra/cqlengine/management.py", line 274, in _sync_table
    table = cluster.metadata.keyspaces[ks_name].tables[raw_cf_name]
KeyError: 'users'

【问题讨论】:

    标签: python cassandra cassandra-driver amazon-keyspaces


    【解决方案1】:

    Amazon Keyspaces 以非阻塞方式创建表。由于它是异步的,您可能不会立即看到该表。此链接提供有关如何监视系统表以检查表何时可用的指南。 https://docs.aws.amazon.com/keyspaces/latest/devguide/functional-differences.html#functional-differences.table-keyspace-management

    以下查询将在 CQL 中显示您的表的状态

    SELECT keyspace_name, table_name, status FROM system_schema_mcs.tables
    WHERE keyspace_name = 'mykeyspace' AND table_name = 'mytable';
    

    如果表仍在创建中,查询的输出将如下所示:

    keyspace_name table_name status
    mykeyspace mytable CREATING

    如果表已成功创建并处于活动状态,则查询输出如下所示:

    keyspace_name table_name status
    mykeyspace mytable ACTIVE

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-15
      • 2021-11-11
      • 2019-01-14
      • 2021-01-31
      • 2021-10-14
      • 1970-01-01
      • 2022-08-22
      • 2020-08-08
      相关资源
      最近更新 更多