|
@@ -132,6 +132,8 @@ std::string describeDbFailure(const char* what,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// From client 2.12.4 a failed READ throws instead of answering "nothing there".
|
|
// From client 2.12.4 a failed READ throws instead of answering "nothing there".
|
|
|
|
|
+// The file calls (upload, download, getFileInfo, listFiles, setFileTtl) have
|
|
|
|
|
+// thrown since well before that, which is why this is not named for reads.
|
|
|
// Before, a blip was indistinguishable from a genuine absence: get() returned
|
|
// Before, a blip was indistinguishable from a genuine absence: get() returned
|
|
|
// nullopt, the list reads returned empty and getCollectionConfig() returned the
|
|
// nullopt, the list reads returned empty and getCollectionConfig() returned the
|
|
|
// DEFAULTS. Upstream changed it because a consumer turned one such blip into a
|
|
// DEFAULTS. Upstream changed it because a consumer turned one such blip into a
|
|
@@ -146,7 +148,7 @@ std::string describeDbFailure(const char* what,
|
|
|
//
|
|
//
|
|
|
// A genuine absence still comes back as nullopt/empty and does not throw, so
|
|
// A genuine absence still comes back as nullopt/empty and does not throw, so
|
|
|
// "not found" keeps its own code and only a real failure gets the transient one.
|
|
// "not found" keeps its own code and only a real failure gets the transient one.
|
|
|
-Error dbReadError(const char* what,
|
|
|
|
|
|
|
+Error dbCallError(const char* what,
|
|
|
const std::string& collection,
|
|
const std::string& collection,
|
|
|
const std::string& id,
|
|
const std::string& id,
|
|
|
const database::Client::Error& e) {
|
|
const database::Client::Error& e) {
|
|
@@ -160,7 +162,7 @@ Result<nlohmann::json> StorageClient::get(const std::string& collection, const s
|
|
|
try {
|
|
try {
|
|
|
opt = impl_->client_->get(collection, id);
|
|
opt = impl_->client_->get(collection, id);
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("Get", collection, id, e);
|
|
|
|
|
|
|
+ return dbCallError("Get", collection, id, e);
|
|
|
} catch (const std::exception& e) {
|
|
} catch (const std::exception& e) {
|
|
|
return Error(ErrorCode::DatabaseError,
|
|
return Error(ErrorCode::DatabaseError,
|
|
|
"Get failed: " + collection + "/" + id + ": " + e.what());
|
|
"Get failed: " + collection + "/" + id + ": " + e.what());
|
|
@@ -339,7 +341,7 @@ Result<QueryResult> StorageClient::query(const std::string& collection, const Qu
|
|
|
return Error(ErrorCode::CollectionNotFound,
|
|
return Error(ErrorCode::CollectionNotFound,
|
|
|
"Query failed for '" + collection + "': " + e.what());
|
|
"Query failed for '" + collection + "': " + e.what());
|
|
|
}
|
|
}
|
|
|
- return dbReadError("Query", collection, "", e);
|
|
|
|
|
|
|
+ return dbCallError("Query", collection, "", e);
|
|
|
} catch (const std::exception& e) {
|
|
} catch (const std::exception& e) {
|
|
|
return Error(ErrorCode::CollectionNotFound,
|
|
return Error(ErrorCode::CollectionNotFound,
|
|
|
"Query failed for '" + collection + "': " + e.what());
|
|
"Query failed for '" + collection + "': " + e.what());
|
|
@@ -485,7 +487,7 @@ Result<CollectionInfo> StorageClient::getCollectionInfo(const std::string& name)
|
|
|
try {
|
|
try {
|
|
|
upstream = impl_->client_->getCollectionInfo(name);
|
|
upstream = impl_->client_->getCollectionInfo(name);
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("getCollectionInfo", name, "", e);
|
|
|
|
|
|
|
+ return dbCallError("getCollectionInfo", name, "", e);
|
|
|
}
|
|
}
|
|
|
if (!upstream.has_value()) {
|
|
if (!upstream.has_value()) {
|
|
|
return Error(ErrorCode::CollectionNotFound, "No such collection: " + name);
|
|
return Error(ErrorCode::CollectionNotFound, "No such collection: " + name);
|
|
@@ -527,7 +529,7 @@ Result<CollectionConfig> StorageClient::getCollectionConfig(const std::string& c
|
|
|
try {
|
|
try {
|
|
|
upstream = impl_->client_->getCollectionConfig(collection);
|
|
upstream = impl_->client_->getCollectionConfig(collection);
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("getCollectionConfig", collection, "", e);
|
|
|
|
|
|
|
+ return dbCallError("getCollectionConfig", collection, "", e);
|
|
|
}
|
|
}
|
|
|
CollectionConfig cfg;
|
|
CollectionConfig cfg;
|
|
|
cfg.timestamp_precision = upstream.timestampPrecision;
|
|
cfg.timestamp_precision = upstream.timestampPrecision;
|
|
@@ -558,7 +560,7 @@ Result<std::vector<StorageClient::IndexInfo>> StorageClient::listIndexes(const s
|
|
|
try {
|
|
try {
|
|
|
defs = impl_->client_->listIndexes(collection);
|
|
defs = impl_->client_->listIndexes(collection);
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("listIndexes", collection, "", e);
|
|
|
|
|
|
|
+ return dbCallError("listIndexes", collection, "", e);
|
|
|
}
|
|
}
|
|
|
std::vector<IndexInfo> out;
|
|
std::vector<IndexInfo> out;
|
|
|
for (const auto& def : defs) {
|
|
for (const auto& def : defs) {
|
|
@@ -588,7 +590,7 @@ Result<std::vector<std::string>> StorageClient::listCollections() {
|
|
|
try {
|
|
try {
|
|
|
upstream_names = impl_->client_->listCollections();
|
|
upstream_names = impl_->client_->listCollections();
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("listCollections", "", "", e);
|
|
|
|
|
|
|
+ return dbCallError("listCollections", "", "", e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> out;
|
|
std::vector<std::string> out;
|
|
@@ -640,7 +642,7 @@ Result<nlohmann::json> StorageClient::getVersion(const std::string& collection,
|
|
|
try {
|
|
try {
|
|
|
entry = impl_->client_->getDocumentVersion(collection, id, static_cast<uint64_t>(version));
|
|
entry = impl_->client_->getDocumentVersion(collection, id, static_cast<uint64_t>(version));
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("getVersion", collection, id, e);
|
|
|
|
|
|
|
+ return dbCallError("getVersion", collection, id, e);
|
|
|
}
|
|
}
|
|
|
if (!entry) return Error(ErrorCode::DocumentNotFound, "Version not found");
|
|
if (!entry) return Error(ErrorCode::DocumentNotFound, "Version not found");
|
|
|
return entry->data;
|
|
return entry->data;
|
|
@@ -656,7 +658,7 @@ Result<VersionListResult> StorageClient::listVersions(const std::string& collect
|
|
|
static_cast<uint32_t>(limit),
|
|
static_cast<uint32_t>(limit),
|
|
|
static_cast<uint32_t>(offset));
|
|
static_cast<uint32_t>(offset));
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("listVersions", collection, id, e);
|
|
|
|
|
|
|
+ return dbCallError("listVersions", collection, id, e);
|
|
|
}
|
|
}
|
|
|
VersionListResult out;
|
|
VersionListResult out;
|
|
|
out.total_count = static_cast<int64_t>(h.totalCount);
|
|
out.total_count = static_cast<int64_t>(h.totalCount);
|
|
@@ -700,7 +702,7 @@ Result<std::vector<ViewInfo>> StorageClient::listViews() {
|
|
|
try {
|
|
try {
|
|
|
defs = impl_->client_->listViews();
|
|
defs = impl_->client_->listViews();
|
|
|
} catch (const Client::Error& e) {
|
|
} catch (const Client::Error& e) {
|
|
|
- return dbReadError("listViews", "", "", e);
|
|
|
|
|
|
|
+ return dbCallError("listViews", "", "", e);
|
|
|
}
|
|
}
|
|
|
std::vector<ViewInfo> out;
|
|
std::vector<ViewInfo> out;
|
|
|
for (const auto& v : defs) {
|
|
for (const auto& v : defs) {
|
|
@@ -733,8 +735,25 @@ Result<FileUploadInfo> StorageClient::uploadFile(const std::vector<uint8_t>& dat
|
|
|
// member, deliberately: adding a member would change that struct's size
|
|
// member, deliberately: adding a member would change that struct's size
|
|
|
// and an already-installed binary would bind to the new library with the
|
|
// and an already-installed binary would bind to the new library with the
|
|
|
// old layout. Keep calling the two-argument form when there is no TTL.
|
|
// old layout. Keep calling the two-argument form when there is no TTL.
|
|
|
- auto result = ttl_ms > 0 ? impl_->client_->uploadFile(data, upstream, msToSec(ttl_ms))
|
|
|
|
|
- : impl_->client_->uploadFile(data, upstream);
|
|
|
|
|
|
|
+ // uploadFile throws on a failed status - it always has - and 2.12.3 made
|
|
|
|
|
+ // that both more likely and more useful: the size limit now refuses
|
|
|
|
|
+ // mid-stream rather than after buffering the whole body, and the refusal
|
|
|
|
|
+ // arrives as InvalidArgument carrying reason "file_too_large" or
|
|
|
|
|
+ // "mime_type_not_allowed" instead of a bare Internal. Unguarded, that
|
|
|
|
|
+ // exception left this adapter: from the runner it crossed QuickJS, and
|
|
|
|
|
+ // "the file is too big" was never going to reach the person who uploaded it.
|
|
|
|
|
+ dbc::Client::FileUploadResult result;
|
|
|
|
|
+ try {
|
|
|
|
|
+ result = ttl_ms > 0 ? impl_->client_->uploadFile(data, upstream, msToSec(ttl_ms))
|
|
|
|
|
+ : impl_->client_->uploadFile(data, upstream);
|
|
|
|
|
+ } catch (const Client::Error& e) {
|
|
|
|
|
+ // describeDbFailure appends the reason, so the message says
|
|
|
|
|
+ // "[file_too_large]" rather than only that an upload failed.
|
|
|
|
|
+ return dbCallError("File upload", "files", meta.name, e);
|
|
|
|
|
+ } catch (const std::exception& e) {
|
|
|
|
|
+ return Error(ErrorCode::DatabaseError,
|
|
|
|
|
+ "File upload failed: " + meta.name + ": " + e.what());
|
|
|
|
|
+ }
|
|
|
if (result.id.empty()) {
|
|
if (result.id.empty()) {
|
|
|
return Error(ErrorCode::DatabaseError, "File upload failed: " + meta.name);
|
|
return Error(ErrorCode::DatabaseError, "File upload failed: " + meta.name);
|
|
|
}
|
|
}
|
|
@@ -763,7 +782,7 @@ Result<std::vector<uint8_t>> StorageClient::downloadFile(const std::string& id)
|
|
|
return Error(ErrorCode::DocumentNotFound,
|
|
return Error(ErrorCode::DocumentNotFound,
|
|
|
"File not found: " + id + " (" + e.what() + ")");
|
|
"File not found: " + id + " (" + e.what() + ")");
|
|
|
}
|
|
}
|
|
|
- return dbReadError("downloadFile", "files", id, e);
|
|
|
|
|
|
|
+ return dbCallError("downloadFile", "files", id, e);
|
|
|
} catch (const std::exception& e) {
|
|
} catch (const std::exception& e) {
|
|
|
return Error(ErrorCode::DocumentNotFound,
|
|
return Error(ErrorCode::DocumentNotFound,
|
|
|
"File not found: " + id + " (" + e.what() + ")");
|
|
"File not found: " + id + " (" + e.what() + ")");
|
|
@@ -775,7 +794,12 @@ Result<std::vector<uint8_t>> StorageClient::downloadFile(const std::string& id)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Result<FileInfo> StorageClient::getFileInfo(const std::string& id) {
|
|
Result<FileInfo> StorageClient::getFileInfo(const std::string& id) {
|
|
|
- auto record = impl_->client_->getFileInfo(id);
|
|
|
|
|
|
|
+ std::optional<database::Client::FileRecord> record;
|
|
|
|
|
+ try {
|
|
|
|
|
+ record = impl_->client_->getFileInfo(id);
|
|
|
|
|
+ } catch (const Client::Error& e) {
|
|
|
|
|
+ return dbCallError("getFileInfo", "files", id, e);
|
|
|
|
|
+ }
|
|
|
if (!record) {
|
|
if (!record) {
|
|
|
return Error(ErrorCode::DocumentNotFound, "File not found: " + id);
|
|
return Error(ErrorCode::DocumentNotFound, "File not found: " + id);
|
|
|
}
|
|
}
|
|
@@ -798,7 +822,12 @@ Result<FileInfo> StorageClient::getFileInfo(const std::string& id) {
|
|
|
Result<std::vector<FileInfo>> StorageClient::listFilesForWorkflow(const std::string& workflow_id,
|
|
Result<std::vector<FileInfo>> StorageClient::listFilesForWorkflow(const std::string& workflow_id,
|
|
|
uint32_t limit, uint32_t offset) {
|
|
uint32_t limit, uint32_t offset) {
|
|
|
if (workflow_id.empty()) return std::vector<FileInfo>{};
|
|
if (workflow_id.empty()) return std::vector<FileInfo>{};
|
|
|
- auto listed = impl_->client_->listFiles("", workflow_id, limit, offset);
|
|
|
|
|
|
|
+ dbc::Client::FileListResult listed;
|
|
|
|
|
+ try {
|
|
|
|
|
+ listed = impl_->client_->listFiles("", workflow_id, limit, offset);
|
|
|
|
|
+ } catch (const Client::Error& e) {
|
|
|
|
|
+ return dbCallError("listFiles", "files", workflow_id, e);
|
|
|
|
|
+ }
|
|
|
std::vector<FileInfo> out;
|
|
std::vector<FileInfo> out;
|
|
|
out.reserve(listed.files.size());
|
|
out.reserve(listed.files.size());
|
|
|
for (const auto& f : listed.files) {
|
|
for (const auto& f : listed.files) {
|
|
@@ -817,9 +846,28 @@ Result<std::vector<FileInfo>> StorageClient::listFilesForWorkflow(const std::str
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Result<void> StorageClient::setFileTtl(const std::string& id, int64_t ttl_ms) {
|
|
Result<void> StorageClient::setFileTtl(const std::string& id, int64_t ttl_ms) {
|
|
|
- if (!impl_->client_->setFileTtl(id, msToSec(ttl_ms))) {
|
|
|
|
|
- return Error(ErrorCode::DocumentNotFound,
|
|
|
|
|
- "No such file in this project, or it has already expired: " + id);
|
|
|
|
|
|
|
+ // The one call in the file API that still cannot tell an outage from an
|
|
|
|
|
+ // absence. Upstream's setFileTtl returns plain false on ANY failed status
|
|
|
|
|
+ // and never throws, and unlike the other writes it has no Failure&
|
|
|
|
|
+ // overload, so there is no channel to report a reason through - the 2.12.4
|
|
|
|
|
+ // sweep could not reach it. The catch below is therefore belt-and-braces
|
|
|
|
|
+ // rather than live today.
|
|
|
|
|
+ //
|
|
|
|
|
+ // So this does not claim the file is gone. It used to answer
|
|
|
|
|
+ // DocumentNotFound, which during a blip asserted something it had no way
|
|
|
|
|
+ // of knowing; the retention worker only counts successes, and a file that
|
|
|
|
|
+ // keeps its existing expiry is the harmless direction either way.
|
|
|
|
|
+ bool ok = false;
|
|
|
|
|
+ try {
|
|
|
|
|
+ ok = impl_->client_->setFileTtl(id, msToSec(ttl_ms));
|
|
|
|
|
+ } catch (const Client::Error& e) {
|
|
|
|
|
+ return dbCallError("setFileTtl", "files", id, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!ok) {
|
|
|
|
|
+ return Error(ErrorCode::DatabaseError,
|
|
|
|
|
+ "Could not set the expiry of " + id +
|
|
|
|
|
+ " - no such file in this project, it has already expired, or the "
|
|
|
|
|
+ "database could not be reached; upstream does not distinguish these");
|
|
|
}
|
|
}
|
|
|
return {};
|
|
return {};
|
|
|
}
|
|
}
|