我正在使用 Java 和 Cassandra 数据库开发与论坛相关的 Web 应用程序.
I am working on a web application related to Discussion forums using Java and Cassandra database.
我需要为存储用户详细信息的行和 &另一组存储用户发布的内容的行.
I need to construct 'keys' for the rows storing the user's details and & another set of rows storing the content posted by the user.
一种选择是获取 Java 语言提供的随机生成的 UUID,但这些都是 16 字节长.由于 NoSQL 数据库涉及大量的非规范化,我担心如果可以生成更小的密钥,是否会浪费大量磁盘空间、RAM 和其他资源.
One option is to get the randomly generated UUID provided by Java language, but these are 16 bytes long. and since NoSQL database involves heavy denormalization, I am concerned whether I would be wasting lots of disk space, RAM and other resources if the key could be generated in smaller sizes.
我需要生成两种类型的密钥,一种用于用户和其他用于用户发布的内容.
I need to generate two types of keys, one for the Users & other for Content Posted by Users.
对于用户发布的内容,timestamp+userId
会是一个很好的键.其中 timestamp
是发布内容的服务器时间,userId
是指用户行的键.
For the Content posted by users, would timestamp+userId
be a good key. where timestamp
is the server time at which content was posted and userId
refers to key of user row.
任何建议,意见表示赞赏..
Any suggestions, comments appreciated ..
谢谢马科斯
这是分布式应用吗?
然后您可以使用一个简单的同步计数器,并在启动时使用下一个可用 id 对其进行初始化.
Then you could use a simple synchronized counter and initialize it on startup with the next available id.
另一方面,数据库应该能够处理由 java 创建的 UUID 哈希.这是创建诸如 sessionIds 之类的东西的标准,它需要是唯一的.您的问题有些相似,因为您上下文中的会话将代表一组用户输入.
On the other hand a database should be able to handle the UUID hashes as created by java. This is a standard for creating things like sessionIds, that need to be unique. Your problem is somewhat similar since a session in your context would represent a set of user input.
这篇关于为高度非规范化的 NoSQL 数据库设计唯一键(主键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!