MongoDb ObjectId中的4字节时间戳值会溢出吗? [英] Can a 4 byte timestamp value in MongoDb ObjectId overflow?

查看:94
本文介绍了MongoDb ObjectId中的4字节时间戳值会溢出吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果某个时期是 ffffffff ,那么此时创建的objectId类似于:

If at some time, the epoch is ffffffff, than the objectId created at this moment is something like :

ffffffff15580625bcb65364

然后,一秒钟后创建的ObjectId是什么?

Then, what could be the ObjectId created after 1 second?

推荐答案

然后,[Unix时代以32位翻转]之后创建的ObjectId是什么?

Then, what could be the ObjectId created after [the Unix epoch rolls over in 32 bits]?

这取决于具体的实现方式,其编程语言及其对数学计算的处理.

This would depend on the specific implementation, its programming language and their handling of math calculations.

某些实现和语言在检索自Unix纪元以来的秒数(以64位整数(今天非常普遍)),然后尝试使用大小超过32位的值时,可能会出错用于生成ObjectId.如果发生这种情况,驱动程序将不再能够生成ObjectId,因此,如果应用程序不使用其他生成策略提供_id值,则驱动程序可能无法插入文档.

It is possible that some implementations and languages would error when they retrieve the number of seconds since the Unix epoch as a 64-bit integer (which is quite common today) and then try to use a value which exceeds 32 bits in size for ObjectId generation. If this happens the driver will cease to be able to generate ObjectIds, consequently it may be unable to insert documents without _id values being provided by the application using some other generation strategy.

在其他实现中,时间戳本身可能会翻转为零,这时ObjectId生成将以很小的时间戳值成功完成.

In other implementations the timestamp itself may roll over to zero, at which point the ObjectId generation will succeed with a very small timestamp value.

然而,其他实现可能会截断时间戳(从最高或最低有效方面开始),以将其强制转换为ObjectId的32个可用位.

Yet other implementations may truncate (from either most or least significant side) the timestamp to coerce it into the 32 available bits of an ObjectId.

ObjectId值本身实际上没有具有准确的时间戳-要求它在集合中是唯一的,并且通常在增加".但是MongoDB-the-database不在乎是否将ObjectId值在某个时候换成零附近.

The ObjectId value itself doesn't actually have to have an accurate timestamp - it is required to be unique within the collection and it is "generally increasing" but MongoDB-the-database wouldn't care if ObjectId values wrapped to around zero at some point.

这篇关于MongoDb ObjectId中的4字节时间戳值会溢出吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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