Cassandra与Lazyboy的TimeUUID

1 投票
1 回答
2222 浏览
提问于 2025-04-16 02:35

我想插入一个包含UUID1键的列,这样我就可以按日期排序。但是我总是收到错误信息“cassandra.ttypes.InvalidRequestException: InvalidRequestException(why='UUIDs must be exactly 16 bytes')”,我不知道为什么会这样。

下面是产生这个错误的代码:

from lazyboy import *
from lazyboy.key import Key
import uuid

class TestItemKey(Key):
    def __init__(self, key=None):
        Key.__init__(self, 'MXstore', 'TestCF', key)

class TestItem(record.Record):
    def __init__(self, *args, **kwargs):
        record.Record.__init__(self, *args, **kwargs)
        self.key = TestItemKey(uuid.uuid1().bytes)

connection.add_pool('MXstore', ['localhost:9160'])

tmp = {'foo' : 'bar'}
tmps = TestItem(tmp).save()

我哪里做错了呢?我使用的是lazyboy 0.705和Cassandra 0.6.4。存储配置是:

<Keyspaces>
    <Keyspace Name="MXstore">
        <ColumnFamily Name="TestCF" CompareWith="TimeUUIDType" />

        <ReplicaPlacementStrategy>org.apache.cassandra.locator.RackUnawareStrategy</ReplicaPlacementStrategy>
        <ReplicationFactor>3</ReplicationFactor>
        <EndPointSnitch>org.apache.cassandra.locator.EndPointSnitch</EndPointSnitch>
    </Keyspace>
</Keyspaces>

1 个回答

1

这个列的名字必须是uuid版本1。看起来你的键是uuid版本1。

撰写回答