DynamoDB一致的读取导致架构错误 [英] DynamoDB consistent read results in schema error

查看:69
本文介绍了DynamoDB一致的读取导致架构错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用boto与python中的DynamoDB表进行交互.我希望所有读取/写入均达到法定人数一致性,以确保写入后立即发出的读取始终反映正确的数据.

注意:我的表设置为将"phone_number"作为哈希键,并将first_name + last_name作为辅助索引.并且出于这个问题的目的,数据库中存在一个(只有一个)项(first_name ="Paranoid",last_name ="Android",phone_number ="42")

以下代码按预期工作:

  customer = customer.get_item(phone_number ="42") 

这句话:

  customer = customers.get_item(phone_number ="42",consistent_read = True) 

失败,并出现以下错误:

  boto.dynamodb2.exceptions.ValidationException:ValidationException:400错误的请求{u'message':u'提供的键元素与架构不匹配,'u'__ type':u'com.amazon.coral.validate#ValidationException'} 

这可能是由于过去失败的请求导致某些隐藏数据损坏的结果吗?(例如,以最终一致性执行两次并发写入和不同写入)

谢谢.

解决方案

似乎您正在呼叫

我不确定您发起的原始通话为何正常工作.


为解决您对数据损坏和最终一致性的担忧,与向DynamoDB进行的任何API调用都可能导致在向您发送错误的项目数据之外,该API进入错误状态的情况非常不同.DynamoDB是一项经过高度测试的解决方案,可提供出色的可用性,并且会花费不菲的长度来处理您发送给它的数据.

对于DynamoDB,最终一致性是要注意的一点,但总的来说,取决于用例的具体情况,它不会引起很多问题.尽管AWS并未提供有关最终一致"外观的具体指标,但在日常使用中,即使最终一致性读取,也能够在不到一秒钟的时间内读出刚刚写入/修改的记录是正常的.

对于在同一对象上同时执行多次写入,DynamoDB写入始终保持高度一致.如果您担心,可以在DynamoDB中使用有条件写入关于同时修改单个项目会导致意外的行为,这将导致写入失败,并且您的应用程序逻辑可以处理出现的任何问题.

I am trying to interact with a DynamoDB table from python using boto. I want all reads/writes to be quorum consistency to ensure that reads sent out immediately after writes always reflect the correct data.

NOTE: my table is set up with "phone_number" as the hash key and first_name+last_name as a secondary index. And for the purposes of this question one (and only one) item exists in the db (first_name="Paranoid", last_name="Android", phone_number="42")

The following code works as expected:

customer = customers.get_item(phone_number="42")

While this statement:

customer = customers.get_item(phone_number="42", consistent_read=True)

fails with the following error:

boto.dynamodb2.exceptions.ValidationException: ValidationException: 400 Bad Request
{u'message': u'The provided key element does not match the schema', u'__type': u'com.amazon.coral.validate#ValidationException'}

Could this be the result of some hidden data corruption due to failed requests in the past? (for example two concurrent and different writes executed at eventual consistency)

Thanks in advance.

解决方案

It looks like you are calling the get_item method so the issue is with how you are passing parameters.

get_item(hash_key, range_key=None, attributes_to_get=None, consistent_read=False, item_class=<class 'boto.dynamodb.item.Item'>)

Which would mean you should be calling the API like:

customer = customers.get_item(hash_key="42", consistent_read=True)

I'm not sure why the original call you were making was working.


To address your concerns about data corruption and eventual consistency, it is highly unlike that any API call you could make to DynamoDB could result in it getting into a bad state outside of you sending it bad data for an item. DynamoDB is a highly tested solution that provides exceptional availability and goes to extraordinary lengths to take care of the data you send it.

Eventual consistency is something to be aware of with DynamoDB, but generally speaking it is not something that causes many issues depending on the specifics of the use case. While AWS does not provide specific metrics on what "eventually consistent" look like, in day-to-day use it is normal to be able to read out records that were just written/modified under a second even when eventually consistent reads.

As for performing multiple writes simultaneously on the same object, DynamoDB writes are always strongly consistent. You can utilize conditional writes with DynamoDB if you are worried about an individual item being modified at the same time resulting in unexpected behavior which will allow writes to fail and your application logic to deal with any issues that arise.

这篇关于DynamoDB一致的读取导致架构错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆