platoneko commented on code in PR #14875: URL: https://github.com/apache/doris/pull/14875#discussion_r1042403237
########## be/src/io/fs/hdfs_file_system.cpp: ########## @@ -0,0 +1,287 @@ +// 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 "io/fs/hdfs_file_system.h" + +#include <fcntl.h> +#include <gen_cpp/PlanNodes_types.h> +#include <hdfs/hdfs.h> + +#include "gutil/hash/hash.h" +#include "io/fs/hdfs_file_reader.h" +#include "io/hdfs_builder.h" +#include "service/backend_options.h" + +namespace doris { +namespace io { + +#ifndef CHECK_HDFS_HANDLE +#define CHECK_HDFS_HANDLE(handle) \ + if (!handle) { \ + return Status::InternalError("init Hdfs handle error"); \ + } +#endif + +HdfsFileSystem::HdfsFileSystem(THdfsParams hdfs_params, const std::string& path) + : RemoteFileSystem(path, "", FileSystemType::HDFS), + _hdfs_params(hdfs_params), + _path(path), + _fs_handle(nullptr) { + _namenode = _hdfs_params.fs_name; + // if the format of _path is hdfs://ip:port/path, replace it to /path. + // path like hdfs://ip:port/path can't be used by libhdfs3. + if (_path.find(_namenode) != std::string::npos) { + _path = _path.substr(_namenode.size()); + } +} + +HdfsFileSystem::~HdfsFileSystem() { + if (_fs_handle && _fs_handle->from_cache) { + _fs_handle->dec_ref(); + } +} + +Status HdfsFileSystem::connect() { + std::lock_guard lock(_handle_mu); Review Comment: If we never reconnect HdfsFileSystem, no need to use mutex. -- 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: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org