BigQuery:写后读一致性(流式插入)
BigQuery: Read After Write Consistency (Streaming Inserts)
如标题所述,BigQuery 在流式插入方面的一致性保证是什么?使用流式插入插入行后能否保证读取一致?
是也不是!!
- 是的,如果您在流插入后立即获取数据,读取是一致的!
- 如果您使用分区,则否,因为流数据存储在缓冲区中,BigQuery 最多可能需要 2 小时才能将数据存储在正确的分区中。
因此,这取决于您如何使用数据。
这取决于您使用的是哪种流 API 以及您希望使用哪种 DML 运行:
- 使用旧版流媒体时 API,“Data is available for real-time analysis using standard SQL queries immediately after BigQuery successfully acknowledges a tabledata.insertAll request”
- 使用新的存储写入 API,行为是可配置的:You can choose between default stream, committed mode, pending mode, and buffered mode, depending on your requirements:
- 提交模式和默认流:“记录可在您将它们写入流时立即读取”。不同之处在于默认流没有 exactly-once 保证,因此可能具有更高的吞吐量。
- 挂起模式:“在您提交流之前,记录以挂起状态缓冲。提交流后,写入流的所有数据都可用于读取“
- 缓冲模式:“在您刷新流之前,记录会被缓冲。刷新会将游标前进到指定的偏移量,并使该偏移量之前的所有记录都可见”
- 尽管如此,“rows that were written to a table recently by using streaming (the tabledata.insertall method or the Storage Write API) cannot be modified with UPDATE, DELETE, or MERGE statements" and "Some recently streamed rows might not be available for table copy typically for a few minutes. In rare cases, this can take up to 90 minutes”
- "Because BigQuery's streaming API is designed for high insertion rates, modifications to the underlying table metadata are eventually consistent when interacting with the streaming system"
所以一般来说,当使用默认流式传输时,数据在确认流式插入后立即可用于读取查询。
如标题所述,BigQuery 在流式插入方面的一致性保证是什么?使用流式插入插入行后能否保证读取一致?
是也不是!!
- 是的,如果您在流插入后立即获取数据,读取是一致的!
- 如果您使用分区,则否,因为流数据存储在缓冲区中,BigQuery 最多可能需要 2 小时才能将数据存储在正确的分区中。
因此,这取决于您如何使用数据。
这取决于您使用的是哪种流 API 以及您希望使用哪种 DML 运行:
- 使用旧版流媒体时 API,“Data is available for real-time analysis using standard SQL queries immediately after BigQuery successfully acknowledges a tabledata.insertAll request”
- 使用新的存储写入 API,行为是可配置的:You can choose between default stream, committed mode, pending mode, and buffered mode, depending on your requirements:
- 提交模式和默认流:“记录可在您将它们写入流时立即读取”。不同之处在于默认流没有 exactly-once 保证,因此可能具有更高的吞吐量。
- 挂起模式:“在您提交流之前,记录以挂起状态缓冲。提交流后,写入流的所有数据都可用于读取“
- 缓冲模式:“在您刷新流之前,记录会被缓冲。刷新会将游标前进到指定的偏移量,并使该偏移量之前的所有记录都可见”
- 尽管如此,“rows that were written to a table recently by using streaming (the tabledata.insertall method or the Storage Write API) cannot be modified with UPDATE, DELETE, or MERGE statements" and "Some recently streamed rows might not be available for table copy typically for a few minutes. In rare cases, this can take up to 90 minutes”
- "Because BigQuery's streaming API is designed for high insertion rates, modifications to the underlying table metadata are eventually consistent when interacting with the streaming system"
所以一般来说,当使用默认流式传输时,数据在确认流式插入后立即可用于读取查询。