struct.error: 'I' format requires 0 <= number <= 4292967295
indexが4GBを超えた時に発生するエラーです。
エラーが発生した場合には、formatを'Q'に変更したり、indexを変更するなどの対応が必要です。
もし、db.path/id_buckが4GBを超えている場合、それはあなたが作成したindexが4GBを超えているのではなく、CodernityDBがDefaultで作成するmain indexによるものです。この場合はdb.createにwith_id_index=Falseを指定することで解決できるかもしれません。これはmain indexを作成させないようにするオプションです。
ただし、with_id_index=Falseを指定した場合は、id indexをUniqueHashIndexを用いてformat 'Q'で作成するか、Sharded indexesを使用してシャーディングを行う必要があります。Sharded Indexでformat 'I'を用いる場合には、10 shardsで10*4GBのindexを持つことが出来ます。shardの数はsh_numで設定します。
from CodernityDB.database import Database
from CodernityDB.hash_index import HashIndex, UniqueHashIndex
class BigIDIndex(UniqueHashIndex):
def __init__(self, *args, **kwargs):
kwargs['key_format'] = '<32s8sQIcQ'
super(BigIDIndex, self).__init__(*args, **kwargs)
class MyIDIndex(HashIndex):
def __init__(self, *args, **kwargs):
kwargs['key_format'] = 'Q'
super(MyIDIndex, self).__init__(*args, **kwargs)
def make_key_value(self, data):
a_val = data.get("x")
if a_val is not None:
return a_val, None
return None
def make_key(self, key):
return key
db = Database('/tmp/tut1')
db.create(with_id_index=False)
db.add_index(BigIDIndex(db.path, 'id'))
db.add_index(MyIDIndex(db.path, 'x'))
db.insert({'x': 1})
ValueError: bad marshal data, TypeError: 'str' object does not support item assignmentが発生することを確認していますが、今のところ解決策を見つけられていません。
膨大な量のデータをInsertする場合にはSharded Indexを利用するか、データを分けることを検討した方が良いかもしれません。
from CodernityDB.sharded_hash import ShardedUniqueHashIndex, ShardedHashIndex
from CodernityDB.tree_index import TreeBasedIndex
class CustomIdSharded(ShardedUniqueHashIndex):
custom_header = 'from CodernityDB.sharded_hash import ShardedUniqueHashIndex'
def __init__(self, *args, **kwargs):
kwargs['sh_nums'] = 10
super(CustomIdSharded, self).__init__(*args, **kwargs)
class TreeIndex(TreeBasedIndex):
def __init__(self, *args, **kwargs):
kwargs['node_capacity'] = 10
kwargs['key_format'] = 'I'
super(TreeIndex, self).__init__(*args, **kwargs)
def make_key_value(self, data):
t_val = data.get('x')
if t_val is not None:
return t_val, None
return None
def make_key(self, key):
return key
db = Database('/tmp/tut1')
db.create(with_id_index=False)
db.add_index(CustomIdSharded(db.path, 'id'))
db.add_index(TreeIndex(db.path, 'x'))
db.insert({'x': 1})
このエラーについて、詳しくはこちらを参照して下さい。