Skip to content

Commit

Permalink
Removed CurlHandlerPool and simplified it
Browse files Browse the repository at this point in the history
  • Loading branch information
ggtakec committed Jul 27, 2024
1 parent 4fe2652 commit 792bed5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 224 deletions.
1 change: 0 additions & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ s3fs_SOURCES = \
metaheader.cpp \
mpu_util.cpp \
curl.cpp \
curl_handlerpool.cpp \
curl_multi.cpp \
curl_util.cpp \
s3objlist.cpp \
Expand Down
44 changes: 11 additions & 33 deletions src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include "curl_multi.h"
#include "curl_util.h"
#include "s3fs_auth.h"
#include "curl_handlerpool.h"
#include "s3fs_cred.h"
#include "s3fs_util.h"
#include "string_util.h"
Expand Down Expand Up @@ -97,8 +96,6 @@ std::mutex S3fsCurl::curl_warnings_lock;
std::mutex S3fsCurl::curl_handles_lock;
S3fsCurl::callback_locks_t S3fsCurl::callback_locks;
bool S3fsCurl::is_initglobal_done = false;
CurlHandlerPool* S3fsCurl::sCurlPool = nullptr;
int S3fsCurl::sCurlPoolSize = 32;
CURLSH* S3fsCurl::hCurlShare = nullptr;
bool S3fsCurl::is_cert_check = true; // default
bool S3fsCurl::is_dns_cache = true; // default
Expand Down Expand Up @@ -161,14 +158,6 @@ bool S3fsCurl::InitS3fsCurl()
if(!S3fsCurl::InitCryptMutex()){
return false;
}
// [NOTE]
// sCurlPoolSize must be over parallel(or multireq) count.
//
sCurlPoolSize = std::max({sCurlPoolSize, GetMaxParallelCount(), GetMaxMultiRequest()});
sCurlPool = new CurlHandlerPool(sCurlPoolSize);
if (!sCurlPool->Init()) {
return false;
}
return true;
}

Expand All @@ -179,11 +168,6 @@ bool S3fsCurl::DestroyS3fsCurl()
if(!S3fsCurl::DestroyCryptMutex()){
result = false;
}
if(!sCurlPool->Destroy()){
result = false;
}
delete sCurlPool;
sCurlPool = nullptr;
if(!S3fsCurl::DestroyShareCurl()){
result = false;
}
Expand Down Expand Up @@ -1975,7 +1959,7 @@ bool S3fsCurl::ResetHandle()
curl_warnings_once = true;
}

sCurlPool->ResetHandler(hCurl.get());
curl_easy_reset(hCurl.get());

if(CURLE_OK != curl_easy_setopt(hCurl, CURLOPT_NOSIGNAL, 1)){
return false;
Expand Down Expand Up @@ -2098,43 +2082,37 @@ bool S3fsCurl::ResetHandle()
return true;
}

bool S3fsCurl::CreateCurlHandle(bool only_pool, bool remake)
bool S3fsCurl::CreateCurlHandle(bool remake)
{
const std::lock_guard<std::mutex> lock(S3fsCurl::curl_handles_lock);

if(hCurl && remake){
if(!DestroyCurlHandleHasLock(false, true)){
if(!DestroyCurlHandleHasLock(true)){
S3FS_PRN_ERR("could not destroy handle.");
return false;
}
S3FS_PRN_INFO3("already has handle, so destroyed it or restored it to pool.");
}

if(!hCurl){
if(nullptr == (hCurl = sCurlPool->GetHandler(only_pool))){
if(!only_pool){
S3FS_PRN_ERR("Failed to create handle.");
return false;
}else{
// [NOTE]
// Further initialization processing is left to lazy processing to be executed later.
// (Currently we do not use only_pool=true, but this code is remained for the future)
return true;
}
hCurl.reset(curl_easy_init());
if(!hCurl){
S3FS_PRN_ERR("Failed to create handle.");
return false;
}
}
ResetHandle();

return true;
}

bool S3fsCurl::DestroyCurlHandle(bool restore_pool, bool clear_internal_data)
bool S3fsCurl::DestroyCurlHandle(bool clear_internal_data)
{
const std::lock_guard<std::mutex> lock(S3fsCurl::curl_handles_lock);
return DestroyCurlHandleHasLock(restore_pool, clear_internal_data);
return DestroyCurlHandleHasLock(clear_internal_data);
}

bool S3fsCurl::DestroyCurlHandleHasLock(bool restore_pool, bool clear_internal_data)
bool S3fsCurl::DestroyCurlHandleHasLock(bool clear_internal_data)
{
// [NOTE]
// If type is REQTYPE::IAMCRED or REQTYPE::IAMROLE, do not clear type.
Expand All @@ -2151,7 +2129,7 @@ bool S3fsCurl::DestroyCurlHandleHasLock(bool restore_pool, bool clear_internal_d

if(hCurl){
S3fsCurl::curl_progress.erase(hCurl.get());
sCurlPool->ReturnHandler(std::move(hCurl), restore_pool);
hCurl.reset();
}else{
return false;
}
Expand Down
8 changes: 3 additions & 5 deletions src/curl.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,6 @@ class S3fsCurl
std::mutex ssl_session;
} callback_locks;
static bool is_initglobal_done;
static CurlHandlerPool* sCurlPool;
static int sCurlPoolSize;
static CURLSH* hCurlShare;
static bool is_cert_check;
static bool is_dns_cache;
Expand Down Expand Up @@ -360,9 +358,9 @@ class S3fsCurl
static bool SetIPResolveType(const char* value);

// methods
bool CreateCurlHandle(bool only_pool = false, bool remake = false);
bool DestroyCurlHandle(bool restore_pool = true, bool clear_internal_data = true);
bool DestroyCurlHandleHasLock(bool restore_pool = true, bool clear_internal_data = true) REQUIRES(S3fsCurl::curl_handles_lock);
bool CreateCurlHandle(bool remake = false);
bool DestroyCurlHandle(bool clear_internal_data = true);
bool DestroyCurlHandleHasLock(bool clear_internal_data = true) REQUIRES(S3fsCurl::curl_handles_lock);

bool GetIAMCredentials(const char* cred_url, const char* iam_v2_token, const char* ibm_secret_access_key, std::string& response);
bool GetIAMRoleFromMetaData(const char* cred_url, const char* iam_v2_token, std::string& token);
Expand Down
111 changes: 0 additions & 111 deletions src/curl_handlerpool.cpp

This file was deleted.

72 changes: 0 additions & 72 deletions src/curl_handlerpool.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/curl_multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ void S3fsMultiCurl::RequestPerformWrapper(S3fsCurl* s3fscurl, std::promise<int>

if(!result){
result = s3fscurl->RequestPerform();
s3fscurl->DestroyCurlHandle(true, false);
s3fscurl->DestroyCurlHandle(false);
}

const std::lock_guard<std::mutex> lock(*s3fscurl->completed_tids_lock);
Expand Down
2 changes: 1 addition & 1 deletion src/fdcache_fdinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void* PseudoFdInfo::MultipartUploadThreadWorker(void* arg)
}else{
S3FS_PRN_ERR("failed uploading with error(%d) [path=%s][start=%lld][size=%lld][part=%d]", result, pthparam->path.c_str(), static_cast<long long>(pthparam->start), static_cast<long long>(pthparam->size), pthparam->part_num);
}
s3fscurl->DestroyCurlHandle(true, false);
s3fscurl->DestroyCurlHandle(false);

// set result
const std::lock_guard<std::mutex> lock(pthparam->ppseudofdinfo->upload_list_lock);
Expand Down

0 comments on commit 792bed5

Please sign in to comment.