Reputation: 1813
For Mongo Bson type Timestamp, there is a constructor: BsonTimestamp(final int seconds, final int increment)
, how to understand the increment
? what is the design consideration?
Upvotes: 2
Views: 2728
Reputation: 65323
Timestamp is an internal BSON type used by MongoDB to reflect the operation time (ts
) for entries in the replication oplog.
The BSON Timestamp type is designed for the specific use case of logging ordered batches of time-based operations:
time_t
) are an integer value representing seconds since the Unix epochordinal
) indicating ordering within a given secondThe design requirement for Timestamps is based on preserving strict ordering for oplog entries rather than time precision (eg milliseconds or microseconds). The leading time component gives a course granularity of seconds; appending an incrementing ordinal value ensures strict ordering of unique Timestamp values within a given second. Using an ordered sequence instead of time precision avoids pushing down the potential conflict of two operations that might occur in the same millisecond (or microsecond).
For application use cases you should use the BSON Date type instead of a Timestamp. A BSON Date is the same size (in bits) as a Timestamp, but provides more granularity for time:
BSON Date is a 64-bit integer that represents the number of milliseconds since the Unix epoch (Jan 1, 1970). This results in a representable date range of about 290 million years into the past and future.
Upvotes: 3