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

const getter returns garbage while non-const getter works correctly

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Storage Execution
    • ALL

      ClusteredIndexSpec is defined by the idl clustered_collections_options.idl:

          ClusteredIndexSpec:
              description: "The specifications for a given clusteredIndex"
              strict: true
              fields:
                  v:
                      description: 'Index spec version'
                      type: safeInt
                      default: 2
                      unstable: false
                  key:
                      description: 'Key to index on'
                      type: object_owned
                      unstable: false
                  name:
                      description: 'Descriptive name for the index'
                      type: string
                      optional: true
                      unstable: false
                  unique:
                      type: safeBool
                      unstable: false
      

      There are two getter methods that get defined for the indexSpec in build/opt/mongo/db/catalog/clustered_collection_options_gen.h:

      const mongo::ClusteredIndexSpec& getIndexSpec() const { return _indexSpec; }
      mongo::ClusteredIndexSpec& getIndexSpec() { return _indexSpec; }
      

      When I try to extract the name, the following code prints garbage:

      auto nameOptional = collection->getClusteredInfo()->getIndexSpec().getName();
      if (nameOptional) {
          logd("--XYZ-- ------ {}", *nameOptional);
      }
      

      Whereas the following gives me the correct name:

      auto indexSpec = collection->getClusteredInfo()->getIndexSpec();
      auto nameOptional = indexSpec.getName();
      if (nameOptional) {
          logd("--XYZ-- ------ {}", *nameOptional);
      }
      

      I don't understand why, and it seems like a bug.

            Assignee:
            backlog-server-execution [DO NOT USE] Backlog - Storage Execution Team
            Reporter:
            sulabh.mahajan@mongodb.com Sulabh Mahajan
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: