Fix AWS MinIO

This commit is contained in:
2026-05-01 11:16:47 +10:00
parent c4ec6f0ed2
commit 1c8abf2a88
5 changed files with 536 additions and 29 deletions
+64 -22
View File
@@ -264,13 +264,21 @@ namespace ANSCENTER
}
// TryConnect — actual connection attempt (caller must hold _configMutex)
//
// First attempts the AWS virtual-host name (s3.<region>.<base>); for
// S3-compatible servers like MinIO/Ceph that hostname does not exist, so
// we fall back to the raw _baseDomain (path-style). The first attempt is
// therefore *expected* to fail on MinIO — we suppress its error-level log
// (logOnFailure=false) so the operator only sees errors when the fallback
// also fails.
bool ANSAWSS3::TryConnect(bool& awsPath) {
auto testConn = CreateConnection();
const bool fallbackPossible = (_fullAWSURL != _baseDomain);
auto testConn = CreateConnection(/*logOnFailure*/ !fallbackPossible);
if (!testConn) {
// Fallback: connect directly to baseDomain (MinIO, Ceph, etc.)
std::string savedFullURL = _fullAWSURL;
_fullAWSURL = _baseDomain;
testConn = CreateConnection();
testConn = CreateConnection(/*logOnFailure*/ true);
if (!testConn) {
_fullAWSURL = savedFullURL; // restore on failure
return false;
@@ -305,11 +313,18 @@ namespace ANSCENTER
attempt++;
// Quick DNS check — is internet available?
// Quick DNS check — is internet available? Try AWS virtual-host
// form first, then fall back to raw _baseDomain for MinIO/Ceph.
{
CkSocket dnsCheck;
CkString dnsResult;
if (!dnsCheck.DnsLookup(_fullAWSURL.c_str(), 3000, dnsResult)) {
bool resolved = dnsCheck.DnsLookup(_fullAWSURL.c_str(), 3000, dnsResult);
if (!resolved && _fullAWSURL != _baseDomain) {
CkSocket dnsCheck2;
CkString dnsResult2;
resolved = dnsCheck2.DnsLookup(_baseDomain.c_str(), 3000, dnsResult2);
}
if (!resolved) {
_logger.LogDebug("ANSAWSS3::RetryLoop",
"Retry #" + std::to_string(attempt) + " - no internet, retrying in 3s",
__FILE__, __LINE__);
@@ -343,7 +358,11 @@ namespace ANSCENTER
}
// ── Connection pool helpers ──
std::unique_ptr<S3Connection> ANSAWSS3::CreateConnection() {
// logOnFailure=false: caller knows this attempt may legitimately fail
// (e.g. TryConnect's first probe of the AWS virtual-host name on a MinIO
// server). Failures are still emitted to ANS_DBG; just not as error-level
// log entries that would scare ops dashboards.
std::unique_ptr<S3Connection> ANSAWSS3::CreateConnection(bool logOnFailure) {
auto conn = std::make_unique<S3Connection>();
// Apply request timeouts BEFORE Connect() so ConnectTimeoutMs takes
@@ -355,8 +374,11 @@ namespace ANSCENTER
// Connect
if (!conn->rest.Connect(_fullAWSURL.c_str(), _port, _bTls, _bAutoReconnect)) {
const std::string summary = SummarizeChilkatError(conn->rest.lastErrorText());
_logger.LogError("ANSAWSS3::CreateConnection", summary, __FILE__, __LINE__);
ANS_DBG("AWSS3", "Connect failed: %s", summary.c_str());
if (logOnFailure) {
_logger.LogError("ANSAWSS3::CreateConnection", summary, __FILE__, __LINE__);
}
ANS_DBG("AWSS3", "Connect failed%s: %s",
logOnFailure ? "" : " (probe, retry expected)", summary.c_str());
return nullptr;
}
@@ -369,8 +391,11 @@ namespace ANSCENTER
conn->socket.put_HttpProxyForHttp(_bProxy);
if (!conn->rest.UseConnection(conn->socket, true)) {
const std::string summary = SummarizeChilkatError(conn->rest.lastErrorText());
_logger.LogError("ANSAWSS3::CreateConnection - Proxy error", summary, __FILE__, __LINE__);
ANS_DBG("AWSS3", "Proxy error: %s", summary.c_str());
if (logOnFailure) {
_logger.LogError("ANSAWSS3::CreateConnection - Proxy error", summary, __FILE__, __LINE__);
}
ANS_DBG("AWSS3", "Proxy error%s: %s",
logOnFailure ? "" : " (probe, retry expected)", summary.c_str());
return nullptr;
}
}
@@ -385,8 +410,11 @@ namespace ANSCENTER
}
if (!conn->rest.SetAuthAws(conn->authAws)) {
const std::string summary = SummarizeChilkatError(conn->rest.lastErrorText());
_logger.LogError("ANSAWSS3::CreateConnection - Auth error", summary, __FILE__, __LINE__);
ANS_DBG("AWSS3", "Auth error: %s", summary.c_str());
if (logOnFailure) {
_logger.LogError("ANSAWSS3::CreateConnection - Auth error", summary, __FILE__, __LINE__);
}
ANS_DBG("AWSS3", "Auth error%s: %s",
logOnFailure ? "" : " (probe, retry expected)", summary.c_str());
return nullptr;
}
}
@@ -678,14 +706,28 @@ namespace ANSCENTER
_pool.clear();
}
// Check if internet is available (fast DNS check)
// Check if internet is available (fast DNS check). Try the AWS
// virtual-host form first; if that synthetic name doesn't exist
// (MinIO, Ceph, custom S3-compatible servers), fall back to the
// raw _baseDomain — that is the actual host the user gave us.
{
CkSocket dnsCheck;
CkString dnsResult;
if (!dnsCheck.DnsLookup(_fullAWSURL.c_str(), 3000, dnsResult)) {
bool resolved = dnsCheck.DnsLookup(_fullAWSURL.c_str(), 3000, dnsResult);
if (!resolved && _fullAWSURL != _baseDomain) {
CkSocket dnsCheck2;
CkString dnsResult2;
resolved = dnsCheck2.DnsLookup(_baseDomain.c_str(), 3000, dnsResult2);
if (resolved) {
ANS_DBG("AWSS3",
"DNS for '%s' failed but '%s' resolved — proceeding with path-style/MinIO fallback",
_fullAWSURL.c_str(), _baseDomain.c_str());
}
}
if (!resolved) {
// No internet — start background retry, return immediately
_logger.LogDebug("ANSAWSS3::Connect",
"No internet available, starting background retry for '" + _fullAWSURL + "'...",
"No internet available, starting background retry for '" + _fullAWSURL + "' / '" + _baseDomain + "'...",
__FILE__, __LINE__);
_stopRetry = false;
@@ -1705,7 +1747,7 @@ namespace ANSCENTER
int statusCode = conn->rest.get_ResponseStatusCode();
if (statusCode == 200) {
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + fileName;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + fileName;
_logger.LogDebug(kOp,
"Successfully uploaded: " + fileName + " | URL: " + uploadedFilePath,
__FILE__, __LINE__);
@@ -1786,7 +1828,7 @@ namespace ANSCENTER
int statusCode = conn->rest.get_ResponseStatusCode();
if (statusCode == 200) {
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + fileName;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + fileName;
_logger.LogDebug(kOp,
"Successfully uploaded: " + fileName + " | URL: " + uploadedFilePath,
__FILE__, __LINE__);
@@ -1890,7 +1932,7 @@ namespace ANSCENTER
// Build canonical path-style URL from parts — independent
// of the addressing style we actually used.
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + objectKey;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + objectKey;
_logger.LogDebug(kOp,
"Successfully uploaded to: " + objectKey + " | URL: " + uploadedFilePath,
__FILE__, __LINE__);
@@ -1959,7 +2001,7 @@ namespace ANSCENTER
int statusCode = conn->rest.get_ResponseStatusCode();
if (statusCode == 200) {
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + fileName;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + fileName;
_logger.LogDebug(kOp,
"Successfully uploaded file: " + fileName + " | URL: " + uploadedFilePath,
__FILE__, __LINE__);
@@ -2170,7 +2212,7 @@ namespace ANSCENTER
}
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + fileName;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + fileName;
_logger.LogDebug(kOp,
"Multipart upload completed for: " + fileName + " | URL: " + uploadedFilePath,
__FILE__, __LINE__);
@@ -2387,7 +2429,7 @@ namespace ANSCENTER
// Build canonical path-style URL from parts — independent
// of the addressing style we actually used.
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + objectKey;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + objectKey;
_logger.LogDebug(kOp,
"Multipart upload completed. S3 key: " + objectKey + " | URL: " + uploadedFilePath,
__FILE__, __LINE__);
@@ -2451,7 +2493,7 @@ namespace ANSCENTER
int statusCode = conn->rest.get_ResponseStatusCode();
if (statusCode == 200) {
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + fileName;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + fileName;
_logger.LogDebug(kOp,
"Successfully uploaded: " + fileName + " | URL: " + uploadedFilePath,
__FILE__, __LINE__);
@@ -2541,7 +2583,7 @@ namespace ANSCENTER
// Build the returned URL from parts (independent of
// addressing style) — always the canonical path-style URL.
std::string scheme = _bTls ? "https://" : "http://";
uploadedFilePath = scheme + _fullAWSURL + "/" + bucketName + "/" + objectKey;
uploadedFilePath = scheme + (_bAwsPath ? _fullAWSURL : _baseDomain) + "/" + bucketName + "/" + objectKey;
_logger.LogDebug(kOp,
"Successfully uploaded: " + objectKey + " (" + std::to_string(bufferLength) + " bytes) | URL: " + uploadedFilePath,
__FILE__, __LINE__);
+3 -1
View File
@@ -197,7 +197,9 @@ namespace ANSCENTER {
SPDLogger& _logger = SPDLogger::GetInstance("ANSAWSS3", false);
// Pool helpers
std::unique_ptr<S3Connection> CreateConnection();
// logOnFailure=false suppresses error-level logging on failure (still emits ANS_DBG).
// Used by TryConnect's first attempt, which is allowed to fail for path-style/MinIO servers.
std::unique_ptr<S3Connection> CreateConnection(bool logOnFailure = true);
std::unique_ptr<S3Connection> AcquireConnection();
void ReleaseConnection(std::unique_ptr<S3Connection> conn);