gavinchou commented on code in PR #67536: URL: https://github.com/apache/doris/pull/67536#discussion_r4244496000
########## be/test/util/disk_info_test.cpp: ########## @@ -0,0 +1,41 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "util/disk_info.h" + +#include <gtest/gtest-message.h> +#include <gtest/gtest-test-part.h> + +#include "gtest/gtest_pred_impl.h" + +namespace doris { + +TEST(DiskInfoTest, StripPartitionSuffix) { Review Comment: This test does not exercise `get_disk_devices()` or the `/dev/mapper/<lv> -> dev_t -> dm-N` mapping that fixes the reported bug, so it would pass even if the LVM lookup remained broken. It also codifies `nvme0n1p1 -> nvme0n1p`, but `nvme0n1p` is not a device name that `/proc/diskstats` can update. Please add a fixture-driven test of the actual mount/partition mapping, including the LVM success path and the unavailable-device-node case, and avoid treating the current NVMe normalization as the expected result. ########## be/src/util/disk_info.cpp: ########## @@ -206,11 +214,19 @@ Status DiskInfo::get_disk_devices(const std::vector<std::string>& paths, strncmp(path.c_str(), mount_path, mount_size) != 0) { continue; } - std::string dev(basename(dev_path)); - boost::trim_right_if(dev, boost::is_any_of("0123456789")); - if (_s_disk_name_to_disk_id.find(dev) != std::end(_s_disk_name_to_disk_id)) { + // Match by the device's actual major:minor (as /proc/partitions saw it), + // not by name. LVM/device-mapper mounts show up in /proc/mounts as + // /dev/mapper/<vg-lv>, a different name than the dm-N entry + // get_device_names() indexed, so a basename comparison never matches + // and the disk metrics for that mount stay empty. + struct stat dev_stat; + if (stat(dev_path, &dev_stat) != 0) { Review Comment: `dev_path` is the source string from `/proc/mounts`, not a path that is guaranteed to exist as a block device in the BE mount namespace. In an unprivileged container, `/proc/mounts` can identify a bind-mounted filesystem as `/dev/sdb1` even though `/dev/sdb1` is not exposed inside the container. The old basename match still installed metrics; this new `stat()` returns `ENOENT`, silently skips the mount, and returns OK with no disk metrics. Please use `st_dev` from the canonicalized data path, or parse the major:minor field from `/proc/self/mountinfo`, instead of statting the mount-source string. Add a regression test for an unavailable source device node. ########## be/src/util/disk_info.h: ########## @@ -69,6 +69,13 @@ class DiskInfo { static Status get_disk_devices(const std::vector<std::string>& paths, std::set<std::string>* devices); + // Strips the trailing partition number from a /proc/partitions device name, + // e.g. sda2 -> sda. dm-N (device-mapper / LVM logical volumes) is left as-is: + // the trailing number there names a distinct device, not a partition, so + // trimming it would collapse dm-0 and dm-1 into the same disk. + // Exposed for testing. + static std::string strip_partition_suffix(std::string name); Review Comment: This declaration is only defined in `disk_info.cpp`. On macOS, `be/src/util/CMakeLists.txt` excludes that file and builds `disk_info_mac.cpp`, which does not define the symbol, while the new test is still included by the BE UT glob and calls it. The macOS BE UT target will therefore fail to link with an undefined `DiskInfo::strip_partition_suffix` symbol. Please either provide a platform-neutral definition built on both platforms, or make the API and test Linux-only. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
