summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorDan Larkin-York <dan.larkin-york@mongodb.com>2022-06-24 12:16:36 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-06-24 12:41:01 +0000
commitbe7d9cd2d857f8179af2be6e274cd4ff16c27ce7 (patch)
tree94c70a4e72a10b359669b09aeb208b3512641e58 /src/mongo
parent09546e0661b4730bd78bb64b330fd8f3ef155c25 (diff)
downloadmongo-be7d9cd2d857f8179af2be6e274cd4ff16c27ce7.tar.gz
SERVER-66727 Use full-precision timestamp for time-series bucketing decision
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/timeseries/bucket_catalog.cpp14
-rw-r--r--src/mongo/db/timeseries/bucket_catalog.h11
2 files changed, 16 insertions, 9 deletions
diff --git a/src/mongo/db/timeseries/bucket_catalog.cpp b/src/mongo/db/timeseries/bucket_catalog.cpp
index 461a90bb213..7093a63d0eb 100644
--- a/src/mongo/db/timeseries/bucket_catalog.cpp
+++ b/src/mongo/db/timeseries/bucket_catalog.cpp
@@ -166,7 +166,7 @@ std::pair<OID, Date_t> generateBucketId(const Date_t& time, const TimeseriesOpti
// together into predictable chunks for sharding. This way we know from a measurement timestamp
// what the bucket timestamp will be, so we can route measurements to the right shard chunk.
auto roundedTime = timeseries::roundTimestampToGranularity(time, options.getGranularity());
- uint64_t const roundedSeconds = durationCount<Seconds>(roundedTime.toDurationSinceEpoch());
+ int64_t const roundedSeconds = durationCount<Seconds>(roundedTime.toDurationSinceEpoch());
bucketId.setTimestamp(roundedSeconds);
// Now, if we stopped here we could end up with bucket OID collisions. Consider the case where
@@ -265,7 +265,7 @@ StatusWith<std::shared_ptr<BucketCatalog::WriteBatch>> BucketCatalog::insert(
stats->numBucketsClosedDueToSize.fetchAndAddRelaxed(1);
return true;
}
- auto bucketTime = (*bucket).getTime();
+ auto bucketTime = (*bucket)->getTime();
if (time - bucketTime >= Seconds(*options.getBucketMaxSpanSeconds())) {
stats->numBucketsClosedDueToTimeForward.fetchAndAddRelaxed(1);
return true;
@@ -671,6 +671,8 @@ BucketCatalog::Bucket* BucketCatalog::_allocateBucket(const BucketKey& key,
stats->numBucketsOpenedDueToMetadata.fetchAndAddRelaxed(1);
}
+ bucket->_minTime = roundedTime;
+
// Make sure we set the control.min time field to match the rounded _id timestamp.
auto controlDoc = buildControlMinTimestampDoc(options.getTimeField(), roundedTime);
bucket->_minmax.update(
@@ -851,6 +853,10 @@ bool BucketCatalog::Bucket::allCommitted() const {
return _batches.empty() && !_preparedBatch;
}
+Date_t BucketCatalog::Bucket::getTime() const {
+ return _minTime;
+}
+
std::shared_ptr<BucketCatalog::WriteBatch> BucketCatalog::Bucket::_activeBatch(
OperationId opId, const std::shared_ptr<ExecutionStats>& stats) {
auto it = _batches.find(opId);
@@ -1126,10 +1132,6 @@ void BucketCatalog::BucketAccess::rollover(const std::function<bool(BucketAccess
}
}
-Date_t BucketCatalog::BucketAccess::getTime() const {
- return _bucket->id().asDateT();
-}
-
BucketCatalog::WriteBatch::WriteBatch(const OID& bucketId,
OperationId opId,
const std::shared_ptr<ExecutionStats>& stats)
diff --git a/src/mongo/db/timeseries/bucket_catalog.h b/src/mongo/db/timeseries/bucket_catalog.h
index f00475a0c71..59266a6d765 100644
--- a/src/mongo/db/timeseries/bucket_catalog.h
+++ b/src/mongo/db/timeseries/bucket_catalog.h
@@ -349,6 +349,11 @@ public:
*/
bool allCommitted() const;
+ /**
+ * Retrieve the time associated with the bucket
+ */
+ Date_t getTime() const;
+
private:
/**
* Determines the effect of adding 'doc' to this bucket. If adding 'doc' causes this bucket
@@ -393,6 +398,9 @@ public:
// Top-level field names of the measurements that have been inserted into the bucket.
StringSet _fieldNames;
+ // Minimum timestamp over contained measurements
+ Date_t _minTime;
+
// The minimum and maximum values for each field in the bucket.
timeseries::MinMax _minmax;
@@ -575,9 +583,6 @@ private:
*/
void rollover(const std::function<bool(BucketAccess*)>& isBucketFull);
- // Retrieve the time associated with the bucket (id)
- Date_t getTime() const;
-
private:
/**
* Returns the state of the bucket, or boost::none if there is no state for the bucket.