动态表描述和扫描计数中的值不正确



我在使用dynamodb时遇到了问题。我正在尝试验证其中包含的数据,但是扫描似乎只返回数据的子集,这是我与Python boto绑定一起使用的代码

#!/usr/bin/python
#Check the scanned length of a table against the Table Description
import boto.dynamodb
#Connect
TABLENAME = "MyTableName"
sdbconn = boto.dynamodb.connect_to_region(
    "eu-west-1",
    aws_access_key_id='-snipped-',
    aws_secret_access_key='-snipped-')
#Initial Scan
results = sdbconn.layer1.scan(TABLENAME,count=True)
previouskey = results['LastEvaluatedKey']
#Create Counting Variable
count = results['Count']
#DynamoDB scan results are limited to 1MB but return a Key value to carry on for the next MB
#so loop untill it does not return a continuation point
while previouskey != False:
    results = sdbconn.layer1.scan(TABLENAME,exclusive_start_key=previouskey,count=True)
    print(count)
    count = count + results['Count']
    try:
        #get next key
        previouskey = results['LastEvaluatedKey']
    except:
        #no key returned so thats all folks!
        print(previouskey)
        print("Reached End")
        previouskey = False
#these presumably should match, they dont on the MyTableName Table, not even close
print(sdbconn.describe_table(TABLENAME)['Table']['ItemCount'])
print(count)

print(sdbconn.describe_table)给了我1748175和 print(count)给了我583021。我的印象是这些应该总是匹配的?(我知道 6 小时更新)过去 300 小时内只添加了 24 行有谁知道这是否是 DynamoDB 的问题?还是我的代码有一个错误的假设?

终于想通了,它与本地二级索引有关,它们在表描述中显示为唯一项目,该表有两个LSI,导致它显示实际存在的项目数量的3倍

最新更新