[CodeFormat] Clang-format cpp sources (#4965)

Clang-format all c++ source files.
This commit is contained in:
sduzh
2020-11-28 18:36:49 +08:00
committed by GitHub
parent f944bf4d44
commit 6fedf5881b
1331 changed files with 62548 additions and 68514 deletions

View File

@ -17,15 +17,13 @@
#include "runtime/user_function_cache.h"
#include <vector>
#include <regex>
#include <boost/algorithm/string/predicate.hpp> // boost::algorithm::ends_with
#include <boost/algorithm/string/classification.hpp> // boost::is_any_of
#include "gutil/strings/split.h"
#include <boost/algorithm/string/predicate.hpp> // boost::algorithm::ends_with
#include <regex>
#include <vector>
#include "env/env.h"
#include "gutil/strings/split.h"
#include "http/http_client.h"
#include "util/dynamic_util.h"
#include "util/file_utils.h"
@ -38,9 +36,8 @@ static const int kLibShardNum = 128;
// function cache entry, store information for
struct UserFunctionCacheEntry {
UserFunctionCacheEntry(int64_t fid_, const std::string& checksum_,
const std::string& lib_file_)
: function_id(fid_), checksum(checksum_), lib_file(lib_file_) { }
UserFunctionCacheEntry(int64_t fid_, const std::string& checksum_, const std::string& lib_file_)
: function_id(fid_), checksum(checksum_), lib_file(lib_file_) {}
~UserFunctionCacheEntry();
void ref() { _refs.fetch_add(1); }
@ -94,8 +91,7 @@ UserFunctionCacheEntry::~UserFunctionCacheEntry() {
}
}
UserFunctionCache::UserFunctionCache() {
}
UserFunctionCache::UserFunctionCache() {}
UserFunctionCache::~UserFunctionCache() {
std::lock_guard<std::mutex> l(_cache_lock);
@ -138,12 +134,13 @@ Status UserFunctionCache::_load_entry_from_lib(const std::string& dir, const std
auto it = _entry_map.find(function_id);
if (it != _entry_map.end()) {
LOG(WARNING) << "meet a same function id user function library, function_id=" << function_id
<< ", one_checksum=" << checksum << ", other_checksum=" << it->second->checksum;
<< ", one_checksum=" << checksum
<< ", other_checksum=" << it->second->checksum;
return Status::InternalError("duplicate function id");
}
// create a cache entry and put it into entry map
UserFunctionCacheEntry* entry = new UserFunctionCacheEntry(
function_id, checksum, dir + "/" + file);
UserFunctionCacheEntry* entry =
new UserFunctionCacheEntry(function_id, checksum, dir + "/" + file);
entry->is_downloaded = true;
entry->ref();
@ -160,7 +157,7 @@ Status UserFunctionCache::_load_cached_lib() {
std::string sub_dir = _lib_dir + "/" + std::to_string(i);
RETURN_IF_ERROR(FileUtils::create_dir(sub_dir));
auto scan_cb = [this, &sub_dir] (const char* file) {
auto scan_cb = [this, &sub_dir](const char* file) {
if (is_dot_or_dotdot(file)) {
return true;
}
@ -183,13 +180,9 @@ std::string get_real_symbol(const std::string& symbol) {
return str2;
}
Status UserFunctionCache::get_function_ptr(
int64_t fid,
const std::string& orig_symbol,
const std::string& url,
const std::string& checksum,
void** fn_ptr,
UserFunctionCacheEntry** output_entry) {
Status UserFunctionCache::get_function_ptr(int64_t fid, const std::string& orig_symbol,
const std::string& url, const std::string& checksum,
void** fn_ptr, UserFunctionCacheEntry** output_entry) {
auto symbol = get_real_symbol(orig_symbol);
if (fid == 0) {
// Just loading a function ptr in the current process. No need to take any locks.
@ -222,7 +215,7 @@ Status UserFunctionCache::get_function_ptr(
entry->fptr_map.emplace(symbol, *fn_ptr);
} else {
LOG(WARNING) << "fail to lookup symbol in library, symbol=" << symbol
<< ", file=" << entry->lib_file;
<< ", file=" << entry->lib_file;
}
}
}
@ -241,9 +234,9 @@ Status UserFunctionCache::get_function_ptr(
return status;
}
Status UserFunctionCache::_get_cache_entry(
int64_t fid, const std::string& url,
const std::string& checksum, UserFunctionCacheEntry** output_entry) {
Status UserFunctionCache::_get_cache_entry(int64_t fid, const std::string& url,
const std::string& checksum,
UserFunctionCacheEntry** output_entry) {
UserFunctionCacheEntry* entry = nullptr;
{
std::lock_guard<std::mutex> l(_cache_lock);
@ -251,8 +244,7 @@ Status UserFunctionCache::_get_cache_entry(
if (it != _entry_map.end()) {
entry = it->second;
} else {
entry = new UserFunctionCacheEntry(
fid, checksum, _make_lib_file(fid, checksum));
entry = new UserFunctionCacheEntry(fid, checksum, _make_lib_file(fid, checksum));
entry->ref();
_entry_map.emplace(fid, entry);
@ -289,8 +281,7 @@ void UserFunctionCache::_destroy_cache_entry(UserFunctionCacheEntry* entry) {
}
}
Status UserFunctionCache::_load_cache_entry(
const std::string& url, UserFunctionCacheEntry* entry) {
Status UserFunctionCache::_load_cache_entry(const std::string& url, UserFunctionCacheEntry* entry) {
if (entry->is_loaded.load()) {
return Status::OK();
}
@ -305,17 +296,15 @@ Status UserFunctionCache::_load_cache_entry(
}
// entry's lock must be held
Status UserFunctionCache::_download_lib(
const std::string& url, UserFunctionCacheEntry* entry) {
Status UserFunctionCache::_download_lib(const std::string& url, UserFunctionCacheEntry* entry) {
DCHECK(!entry->is_downloaded);
// get local path to save library
std::string tmp_file = entry->lib_file + ".tmp";
auto fp_closer = [] (FILE*fp) { fclose(fp); };
auto fp_closer = [](FILE* fp) { fclose(fp); };
std::unique_ptr<FILE, decltype(fp_closer)> fp(fopen(tmp_file.c_str(), "w"), fp_closer);
if (fp == nullptr) {
LOG(WARNING) << "fail to open file, file=" << tmp_file
<< ", error=" << ferror(fp.get());
LOG(WARNING) << "fail to open file, file=" << tmp_file << ", error=" << ferror(fp.get());
return Status::InternalError("fail to open file");
}
@ -323,12 +312,12 @@ Status UserFunctionCache::_download_lib(
HttpClient client;
RETURN_IF_ERROR(client.init(url));
Status status;
auto download_cb = [&status, &tmp_file, &fp, &digest] (const void* data, size_t length) {
auto download_cb = [&status, &tmp_file, &fp, &digest](const void* data, size_t length) {
digest.update(data, length);
auto res = fwrite(data, length, 1, fp.get());
if (res != 1) {
LOG(WARNING) << "fail to write data to file, file=" << tmp_file
<< ", error=" << ferror(fp.get());
<< ", error=" << ferror(fp.get());
status = Status::InternalError("fail to write data when download");
return false;
}
@ -339,7 +328,7 @@ Status UserFunctionCache::_download_lib(
digest.digest();
if (!boost::iequals(digest.hex(), entry->checksum)) {
LOG(WARNING) << "UDF's checksum is not equal, one=" << digest.hex()
<< ", other=" << entry->checksum;
<< ", other=" << entry->checksum;
return Status::InternalError("UDF's library checksum is not match");
}
// close this file
@ -350,7 +339,7 @@ Status UserFunctionCache::_download_lib(
if (ret != 0) {
char buf[64];
LOG(WARNING) << "fail to rename file from=" << tmp_file << ", to=" << entry->lib_file
<< ", errno=" << errno << ", errmsg=" << strerror_r(errno, buf, 64);
<< ", errno=" << errno << ", errmsg=" << strerror_r(errno, buf, 64);
return Status::InternalError("fail to rename file");
}
@ -382,4 +371,4 @@ void UserFunctionCache::release_entry(UserFunctionCacheEntry* entry) {
}
}
}
} // namespace doris