Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-58171

Changing time-series granularity does not update view definition

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 5.0.1, 5.1.0-rc0
    • Affects Version/s: 5.0.0-rc6
    • Component/s: None
    • Labels:
    • Fully Compatible
    • ALL
    • v5.0
    • Execution Team 2021-07-12, Execution Team 2021-07-26

      If the time-series granularity is increased via 'collMod', newly generated buckets will occupy larger time ranges. This means that queries on time fields also need to start considering larger ranges when scanning. That is currently not the case, as the bucketMaxSpanSeconds is hardcoded into the view pipeline, but it also needs to be updated in collMod.

      The result of this bug is that queries will return incorrect results on time-series collections that have modified their 'granularity' setting with 'collMod'.

       

      > db.createCollection("ts", {timeseries: {timeField: 't', granularity: 'seconds'}})
      { "ok" : 1 }
      > db.runCommand({listCollections: 1, filter: {name: 'ts'}})
      {
              "cursor" : {
                      "id" : NumberLong(0),
                      "ns" : "test.$cmd.listCollections",
                      "firstBatch" : [
                              {
                                      "name" : "ts",
                                      "type" : "timeseries",
                                      "options" : {
                                              "timeseries" : {
                                                      "timeField" : "t",
                                                      "granularity" : "seconds",
                                                      "bucketMaxSpanSeconds" : 3600
                                              }
                                      },
                                      "info" : {
                                              "readOnly" : false
                                      }
                              }
                      ]
              },
              "ok" : 1
      }
      > db.system.views.find()
      { "_id" : "test.ts", "viewOn" : "system.buckets.ts", "pipeline" : [ { "$_internalUnpackBucket" : { "timeField" : "t", "bucketMaxSpanSeconds" : 3600, "exclude" : [ ] } } ] }
      > db.runCommand({collMod: 'ts', timeseries: {granularity: 'minutes'}})
      { "ok" : 1 }
      > db.runCommand({listCollections: 1, filter: {name: 'ts'}})
      {
              "cursor" : {
                      "id" : NumberLong(0),
                      "ns" : "test.$cmd.listCollections",
                      "firstBatch" : [
                              {
                                      "name" : "ts",
                                      "type" : "timeseries",
                                      "options" : {
                                              "timeseries" : {
                                                      "timeField" : "t",
                                                      "granularity" : "minutes",
                                                      "bucketMaxSpanSeconds" : 86400
                                              }
                                      },
                                      "info" : {
                                              "readOnly" : false
                                      }
                              }
                      ]
              },
              "ok" : 1
      }
      > db.system.views.find()
      { "_id" : "test.ts", "viewOn" : "system.buckets.ts", "pipeline" : [ { "$_internalUnpackBucket" : { "timeField" : "t", "bucketMaxSpanSeconds" : 3600, "exclude" : [ ] } } ] }
      

      Notice that the metadata for the time-series collection is updated, but not the view pipeline.

            Assignee:
            dan.larkin-york@mongodb.com Dan Larkin-York
            Reporter:
            louis.williams@mongodb.com Louis Williams
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: