NJrslv commented on code in PR #1629: URL: https://github.com/apache/cloudberry/pull/1629#discussion_r3008291976
########## gpcontrib/gp_stats_collector/src/UDSConnector.cpp: ########## @@ -0,0 +1,130 @@ +/*------------------------------------------------------------------------- + * + * 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. + * + * UDSConnector.cpp + * + * IDENTIFICATION + * gpcontrib/gp_stats_collector/src/UDSConnector.cpp + * + *------------------------------------------------------------------------- + */ + +#include "UDSConnector.h" +#include "Config.h" +#include "GpscStat.h" +#include "memory/gpdbwrappers.h" +#include "log/LogOps.h" + +#include <string> +#include <unistd.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/types.h> +#include <sys/fcntl.h> +#include <chrono> +#include <thread> + +extern "C" { +#include "postgres.h" +} + +static void inline log_tracing_failure(const gpsc::SetQueryReq &req, + const std::string &event) { + ereport(LOG, (errmsg("Query {%d-%d-%d} %s tracing failed with error %m", + req.query_key().tmid(), req.query_key().ssid(), + req.query_key().ccnt(), event.c_str()))); +} + +bool UDSConnector::report_query(const gpsc::SetQueryReq &req, + const std::string &event, + const Config &config) { + sockaddr_un address{}; + address.sun_family = AF_UNIX; + const auto &uds_path = config.uds_path(); + + if (uds_path.size() >= sizeof(address.sun_path)) { + ereport(WARNING, (errmsg("UDS path is too long for socket buffer"))); + GpscStat::report_error(); + return false; + } + strcpy(address.sun_path, uds_path.c_str()); + + const auto sockfd = socket(AF_UNIX, SOCK_STREAM, 0); Review Comment: Hi! These are AF_UNIX sockets (Unix sockets), not TCP. The networking stack is not involved, Unix domain sockets use in-kernel memory copies between processes, not the network stack path. I think the cost of socket()/connect()/close() on AF_UNIX is comparable to open()/write()/close() on a local file (we actually have a file to do IPC). Do you mean that even with AF_UNIX option there is a potential problem? Also, we were running regression tests with this extension enabled and haven't seen any regressions. -- 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]
