Files
scylladb/vector_search/utils.hh
Piotr Dulikowski d2b12329ab Merge 'Return HTTP error description in Vector Store client' from Szymon Wasik
The `service_error` struct: 6dc2c42f8b/service/vector_store_client.hh (L64)
currently stores just the error status code. For this reason whenever the HTTP error occurs, only the error code can be forwarded to the client. For example see here: 6dc2c42f8b/service/vector_store_client.cc (L580)
For this reason in the output of the drivers full description of the error is missing which forces user to take a look into Scylla server logs.

The objective of this PR is to extend the support for HTTP errors in Vector Store client to handle messages as well.

Moreover, it removes the quadratic reallocation in response_content_to_sstring() helper function that is used for getting the response in case of error.

Fixes: VECTOR-189

Closes scylladb/scylladb#26139

* github.com:scylladb/scylladb:
  vector_search: Avoid quadratic reallocation in response_content_to_sstring
  vector_store_client: Return HTTP error description, not just code

(cherry picked from commit 38a2829f69)

Closes scylladb/scylladb#29312
2026-04-03 17:53:40 +02:00

56 lines
1.5 KiB
C++

/*
* Copyright (C) 2025-present ScyllaDB
*/
/*
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
*/
#pragma once
#include <seastar/core/sstring.hh>
#include <seastar/core/temporary_buffer.hh>
#include <seastar/net/api.hh>
#include <vector>
namespace vector_search {
inline seastar::sstring response_content_to_sstring(const std::vector<seastar::temporary_buffer<char>>& buffers) {
size_t total_size = 0;
for (const auto& buf : buffers) {
total_size += buf.size();
}
auto result = seastar::uninitialized_string(total_size);
size_t pos = 0;
for (const auto& buf : buffers) {
std::copy(buf.get(), buf.get() + buf.size(), result.data() + pos);
pos += buf.size();
}
return result;
}
inline seastar::net::tcp_keepalive_params get_keepalive_parameters(std::chrono::milliseconds timeout) {
constexpr unsigned retry_count = 3;
constexpr auto min_interval = std::chrono::seconds(1);
// Divide total time by (count + 2) to balance Probing vs. Idle (~60/40)
auto target_duration = std::chrono::duration_cast<std::chrono::seconds>(timeout);
auto interval = target_duration / (retry_count + 2);
// Ensure minimum 1s interval
if (interval < min_interval) {
interval = min_interval;
}
auto idle = target_duration - (interval * retry_count);
return seastar::net::tcp_keepalive_params{
.idle = idle,
.interval = interval,
.count = retry_count,
};
}
} // namespace vector_search