更新气溶胶中所有记录的ttl

我陷入了这样的情况:我已经使用default-ttl初始化了一个命名空间,这个命名空间的生存时间为30天。有大约500万条数据使用了这个(按30天计算的)ttl值。实际上,我的要求是ttl应该为零,但是它(ttl-30d)被保留而没有被意识到或认识到。

所以,现在我想用新的ttl值(零)来更新以前(老的)500万条数据。

我已经检查/尝试了“set-disable-eviction true”,但它没有起作用,它是根据(旧的)ttl值移除数据。

我该如何克服这个问题?(我想检索已删除的数据,我该怎么办?)

有人能帮帮我吗?

点赞
用户582436
用户582436

首先,eviction和expiration是两种不同的机制。你可以通过各种方式禁用evictions,例如你使用的set-disable-eviction配置参数。你无法禁用过期记录的清除。有一个很好的知识库FAQ什么是Expiration, Eviction和Stop-Writes?。不幸的是,已经清理过的过期记录将在其_void time_过去后消失。如果这些记录仅仅是被驱逐的(即在其void time之前由于超过内存或磁盘的名称空间high-water mark而被移除),则可以冷重启节点,那些具有未来TTL的记录将回来。如果它们是durably deleted,或者它们的TTL在过去(这样的记录被跳过),它们不会返回。

至于重置TTL,最简单的方法是通过一个记录UDF来实现,该UDF应用于使用扫描扫描您的名称空间中的所有记录。

对于您的情况,UDF非常简单:

ttl.lua

function to_zero_ttl(rec)
  local rec_ttl = record.ttl(rec)
  if rec_ttl > 0 then
    record.set_ttl(rec, -1)
    aerospike:update(rec)
  end
end

AQL中:

$ aql
Aerospike Query Client
Version 3.12.0
C Client Version 4.1.4
Copyright 2012-2017 Aerospike. All rights reserved.
aql> register module './ttl.lua'
OK, 1 module added.

aql> execute ttl.to_zero_ttl() on test.foo
2017-07-09 17:43:50
用户7252805
用户7252805

如果你有更复杂的逻辑,比如过滤器等,使用 Python 脚本会更容易。

zero_ttl_operation = [operations.touch(-1)]
query = client.query(namespace, set_name)
query.add_ops(zero_ttl_operation)
policy = {}
job = query.execute_background(policy)
print(f'executing job {job}')
while True:
    response = client.job_info(job, aerospike.JOB_SCAN, policy={'timeout': 60000})
    print(f'job status: {response}')
    if response['status'] != aerospike.JOB_STATUS_INPROGRESS:
        break
    time.sleep(0.5)

Aerospike 版本为 v6,Python SDK 版本为 v7。

2022-09-20 19:08:15