为严重非规范化的NoSQL数据库设计唯一键(主键) [英] Designing Unique Keys(Primary Keys) for a heavily denormalized NoSQL database

查看:135
本文介绍了为严重非规范化的NoSQL数据库设计唯一键(主键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Java和Cassandra数据库开发与Discussion论坛相关的Web应用程序。

I am working on a web application related to Discussion forums using Java and Cassandra database.

我需要为存储用户详细信息的行构建keys &安培;存储用户发布的内容的另一组行。

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,但这些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 ..

谢谢
Marcos

Thanks Marcos

推荐答案

这是一个分布式应用程序吗?

Is this a distributed application?

然后你可以使用一个简单的同步计数器并初始化它在启动时使用下一个可用的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数据库设计唯一键(主键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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