• Bug#1108915: unblock: pdns/4.9.7-1 [pre-approval] (3/6)

    From Chris Hofstaedtler@1:229/2 to All on Tue Jul 8 09:30:02 2025
    [continued from previous message]

    +
    + int _lower_bound(const MDBInVal& in, MDBOutVal& key, MDBOutVal& data) // used by prefix() and lower_bound()
    + {
    key.d_mdbval = in.d_mdbval;

    int rc = mdb_cursor_get(d_cursor, const_cast<MDB_val*>(&key.d_mdbval), &data.d_mdbval, MDB_SET_RANGE);
    diff -Nru pdns-4.9.4/ext/lmdb-safe/lmdb-typed.hh pdns-4.9.7/ext/lmdb-safe/lmdb-typed.hh
    --- pdns-4.9.4/ext/lmdb-safe/lmdb-typed.hh 2025-02-06 16:17:38.000000000 +0100
    +++ pdns-4.9.7/ext/lmdb-safe/lmdb-typed.hh 2025-07-07 09:42:15.000000000 +0200
    @@ -284,14 +284,19 @@
    // }

    //! Get item with id, from main table directly
    - bool get(uint32_t id, T& t)
    + int get2(uint32_t itemId, T& value)
    {
    - MDBOutVal data;
    - if((*d_parent.d_txn)->get(d_parent.d_parent->d_main, id, data))
    - return false;
    -
    - serFromString(data.get<std::string>(), t);
    - return true;
    + MDBOutVal data{};
    + int rc;
    + rc = (*d_parent.d_txn)->get(d_parent.d_parent->d_main, itemId, data); >> + if (rc == 0) {
    + serFromString(data.get<std::string>(), value);
    + }
    + return rc;
    + }
    + bool get(uint32_t itemId, T& value)
    + {
    + return get2(itemId, value) == 0;
    }

    //! Get item through index N, then via the main database
    @@ -309,17 +314,24 @@
    // because we know we only want one item, pass onlyOldest=true to consistently get the same one out of a set of duplicates
    get_multi<N>(key, ids, true);

    - if (ids.size() == 0) {
    + switch (ids.size()) {
    + case 0:
    return 0;
    - }
    -
    - if (ids.size() == 1) {
    - if (get(ids[0], out)) {
    + case 1: {
    + auto rc = get2(ids[0], out);
    + if (rc == 0) {
    return ids[0];
    }
    + if (rc == MDB_NOTFOUND) {
    + /* element not present, or has been marked deleted */
    + return 0;
    + }
    + throw std::runtime_error("in index get, failed (" + std::to_string(rc) + ")");
    + break;
    + }
    + default:
    + throw std::runtime_error("in index get, found more than one item"); >> }
    -
    - throw std::runtime_error("in index get, found more than one item"); >> }

    // //! Cardinality of index N
    diff -Nru pdns-4.9.4/modules/gmysqlbackend/smysql.cc pdns-4.9.7/modules/gmysqlbackend/smysql.cc
    --- pdns-4.9.4/modules/gmysqlbackend/smysql.cc 2025-02-06 16:17:38.000000000 +0100
    +++ pdns-4.9.7/modules/gmysqlbackend/smysql.cc 2025-07-07 09:42:15.000000000 +0200
    @@ -116,7 +116,12 @@
    releaseStatement();
    throw SSqlException("Attempt to bind more parameters than query has: " + d_query);
    }
    - d_req_bind[d_paridx].buffer_type = MYSQL_TYPE_LONG;
    + if constexpr (sizeof(long) == 4) {
    + d_req_bind[d_paridx].buffer_type = MYSQL_TYPE_LONG; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
    + }
    + else {
    + d_req_bind[d_paridx].buffer_type = MYSQL_TYPE_LONGLONG; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
    + }
    d_req_bind[d_paridx].buffer = new long[1];
    *((long*)d_req_bind[d_paridx].buffer) = value;
    d_paridx++;
    @@ -129,7 +134,12 @@
    releaseStatement();
    throw SSqlException("Attempt to bind more parameters than query has: " + d_query);
    }
    - d_req_bind[d_paridx].buffer_type = MYSQL_TYPE_LONG;
    + if constexpr (sizeof(long) == 4) {
    + d_req_bind[d_paridx].buffer_type = MYSQL_TYPE_LONG; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
    + }
    + else {
    + d_req_bind[d_paridx].buffer_type = MYSQL_TYPE_LONGLONG; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
    + }
    d_req_bind[d_paridx].buffer = new unsigned long[1];
    d_req_bind[d_paridx].is_unsigned = 1;
    *((unsigned long*)d_req_bind[d_paridx].buffer) = value;
    diff -Nru pdns-4.9.4/modules/lmdbbackend/lmdbbackend.cc pdns-4.9.7/modules/lmdbbackend/lmdbbackend.cc
    --- pdns-4.9.4/modules/lmdbbackend/lmdbbackend.cc 2025-02-06 16:17:38.000000000 +0100
    +++ pdns-4.9.7/modules/lmdbbackend/lmdbbackend.cc 2025-07-07 09:42:15.000000000 +0200
    @@ -656,8 +656,6 @@

    string syncMode = toLower(getArg("sync-mode"));

    - d_random_ids = mustDo("random-ids");
    -
    if (syncMode == "nosync")
    d_asyncFlag = MDB_NOSYNC;
    else if (syncMode == "nometasync")
    @@ -667,17 +665,14 @@
    else
    throw std::runtime_error("Unknown sync mode " + syncMode + " requested for LMDB backend");

    - uint64_t mapSize = 0;
    + d_mapsize = 0;
    try {
    - mapSize = std::stoll(getArg("map-size"));
    + d_mapsize = std::stoll(getArg("map-size"));
    }
    catch (const std::exception& e) {
    throw std::runtime_error(std::string("Unable to parse the 'map-size' LMDB value: ") + e.what());
    }

    - LMDBLS::s_flag_deleted = mustDo("flag-deleted");
    - d_handle_dups = false;
    -
    if (mustDo("lightning-stream")) {
    d_random_ids = true;
    d_handle_dups = true;
    @@ -687,6 +682,11 @@
    throw std::runtime_error(std::string("running with Lightning Stream support requires shards=1"));
    }
    }
    + else {
    + d_random_ids = mustDo("random-ids");
    + d_handle_dups = false;
    + LMDBLS::s_flag_deleted = mustDo("flag-deleted");
    + }

    bool opened = false;

    @@ -723,7 +723,7 @@
    throw std::runtime_error("Somehow, we are not at schema version 5. Giving up");
    }

    - d_tdomains = std::make_shared<tdomains_t>(getMDBEnv(getArg("filename").c_str(), MDB_NOSUBDIR | d_asyncFlag, 0600, mapSize), "domains_v5");
    + d_tdomains = std::make_shared<tdomains_t>(getMDBEnv(getArg("filename").c_str(), MDB_NOSUBDIR | d_asyncFlag, 0600, d_mapsize), "domains_v5");
    d_tmeta = std::make_shared<tmeta_t>(d_tdomains->getEnv(), "metadata_v5");
    d_tkdb = std::make_shared<tkdb_t>(d_tdomains->getEnv(), "keydata_v5");
    d_ttsig = std::make_shared<ttsig_t>(d_tdomains->getEnv(), "tsig_v5"); >> @@ -770,7 +770,7 @@
    }

    if (!opened) {
    - d_tdomains = std::make_shared<tdomains_t>(getMDBEnv(getArg("filename").c_str(), MDB_NOSUBDIR | d_asyncFlag, 0600, mapSize), "domains_v5");
    + d_tdomains = std::make_shared<tdomains_t>(getMDBEnv(getArg("filename").c_str(), MDB_NOSUBDIR | d_asyncFlag, 0600, d_mapsize), "domains_v5");
    d_tmeta = std::make_shared<tmeta_t>(d_tdomains->getEnv(), "metadata_v5");
    d_tkdb = std::make_shared<tkdb_t>(d_tdomains->getEnv(), "keydata_v5"); >> d_ttsig = std::make_shared<ttsig_t>(d_tdomains->getEnv(), "tsig_v5"); >> @@ -1211,7 +1211,7 @@
    auto& shard = d_trecords[id % s_shards];
    if (!shard.env) {
    shard.env = getMDBEnv((getArg("filename") + "-" + std::to_string(id % s_shards)).c_str(),
    - MDB_NOSUBDIR | d_asyncFlag, 0600);
    + MDB_NOSUBDIR | d_asyncFlag, 0600, d_mapsize);
    shard.dbi = shard.env->openDB("records_v5", MDB_CREATE);
    }
    auto ret = std::make_shared<RecordsRWTransaction>(shard.env->getRWTransaction());
    @@ -1228,7 +1228,7 @@

    [continued in next message]

    --- SoupGate-Win32 v1.05
    * Origin: you cannot sedate... all the things you hate (1:229/2)