是否可以从卡桑德拉(Cassandra)作为流字节从卡桑德拉(Cassandra)获取斑点?

发布于 2025-02-07 06:23:21 字数 83 浏览 2 评论 0 原文

是否可以从卡桑德拉(Cassandra)中选择斑点并将其作为流字节(将其作为流)选择? 我不想从数据库下载所有字节,然后通过WebAPI将其发送给用户。

Is it possible to select a blob from Cassandra and get it as a Stream byte?
I don't want to download all bytes from database and then send it via webapi to the user.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迎风吟唱 2025-02-14 06:23:21

我不确定我是否完全了解您的问题的目标,但是如果您的想法是您的斑点很大,并且希望能够跳到中间而不是阅读所有内容 - 然后仅发送特定的字节范围为用户,然后答案是否 - 您不能。正如您可能注意到的那样,Cassandra或Scylla不提供用于获取斑点部分的API。您需要在一个CQL操作中读取(并写)整个斑点,例如,不能阅读100万至200万个字节。

这是您被斑点尺寸限制的原因之一。硬限度为2GB大小,但是文档(例如建议即使1 MB(!)太大。

简单的解决方法是将斑点分成较小的块(例如100 kb)。例如,您可以将所有这些都放在由零件索引排序的一个分区中,这将是聚类键。如果零件的尺寸恒定,则可以轻松有效地跳过要阅读的位置的分区中。如果Blob甚至增长了Huger(例如,多Gigabyte视频文件),您也可以将其拆分为多个分区,以获得更好的负载平衡(因为不同的分区可以转到不同的节点)和提高效率。

I'm not sure I fully understand the goal of your question, but if your idea is that you have a very large blob and you want to be able to jump to its middle instead of reading all of it - and then send only specific byte ranges to the users, then the answer is no - you can't. As you probably noticed Cassandra or Scylla offer no API for fetching parts of a blob. You need to read (and write) the entire blob in one CQL operation, and can't for example read bytes 1 million through 2 million.

This is one of the reasons that you are limited in blob size. The hard limit is 2GB size, but the documentation such as https://docs.datastax.com/en/cql/3.1/cql/cql_reference/blob_r.html suggests that even 1 MB (!) is too large.

The simple workaround is to split your blob into pieces of smaller size (e.g, 100 KB). For example, you can put all of them in one partition ordered by the piece index which will be the clustering key. If the pieces are constant size, you can easily and efficiently skip in the partition right to the position you want to read. If the blob grows even huger (e.g., a multi-gigabyte video file) you can also split it to multiple partitions to get better load balancing (since different partitions can go to different nodes) and better efficiency.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文