Commit 34845ee4 authored by Vladimir Bashkirtsev's avatar Vladimir Bashkirtsev

Fixed RGW sync: we should check for abnormal download

parent fec49b99
......@@ -32,6 +32,7 @@ all: ceph-config
tar xf ceph-14.2.1.tar.gz
patch -Np1 -d ceph-14.2.1 < ceph-14.2.1-fix_tests.patch
patch -Np1 -d ceph-14.2.1 < ceph-14.2.1-fix_rgw_sync.patch
cd ceph-14.2.1 && ./do_cmake.sh -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_SYSCONFDIR=/etc -DCMAKE_INSTALL_LIBEXECDIR=/lib -DWITH_SPDK=OFF -DWITH_RDMA=OFF -DWITH_RADOSGW_AMQP_ENDPOINT=OFF
$(MAKE) -C ceph-14.2.1/build npm_config_cache=/build/.npm
hostname localhost
......
diff -uNr ceph-14.2.1/src/rgw/rgw_http_client.cc ceph-14.2.1-fix_rgw_sync/src/rgw/rgw_http_client.cc
--- ceph-14.2.1/src/rgw/rgw_http_client.cc 2019-04-26 03:45:48.000000000 +0930
+++ ceph-14.2.1-fix_rgw_sync/src/rgw/rgw_http_client.cc 2019-06-29 14:10:43.430981168 +0930
@@ -1141,7 +1141,8 @@
curl_easy_getinfo(e, CURLINFO_RESPONSE_CODE, (void **)&http_status);
int status = rgw_http_error_to_errno(http_status);
- if (result != CURLE_OK && http_status == 0) {
+ if (result != CURLE_OK && status == 0) {
+ dout(0) << "ERROR: curl error: " << curl_easy_strerror((CURLcode)result) << ", maybe network unstable" << dendl;
status = -EAGAIN;
}
int id = req_data->id;
diff -uNr ceph-14.2.1/src/rgw/rgw_rados.cc ceph-14.2.1-fix_rgw_sync/src/rgw/rgw_rados.cc
--- ceph-14.2.1/src/rgw/rgw_rados.cc 2019-04-26 03:45:48.000000000 +0930
+++ ceph-14.2.1-fix_rgw_sync/src/rgw/rgw_rados.cc 2019-06-29 14:08:41.470629630 +0930
@@ -4374,6 +4374,7 @@
string etag;
real_time set_mtime;
+ uint64_t expected_size = 0;
RGWObjState *dest_state = NULL;
@@ -4408,7 +4409,8 @@
goto set_err_state;
}
- ret = conn->complete_request(in_stream_req, &etag, &set_mtime, nullptr, nullptr, nullptr);
+ ret = conn->complete_request(in_stream_req, &etag, &set_mtime,
+ &expected_size, nullptr, nullptr);
if (ret < 0) {
goto set_err_state;
}
@@ -4416,6 +4418,12 @@
if (ret < 0) {
goto set_err_state;
}
+ if (cb.get_data_len() != expected_size) {
+ ret = -EIO;
+ ldout(cct, 0) << "ERROR: object truncated during fetching, expected "
+ << expected_size << " bytes but received " << cb.get_data_len() << dendl;
+ goto set_err_state;
+ }
if (compressor && compressor->is_compressed()) {
bufferlist tmp;
RGWCompressionInfo cs_info;
diff -uNr ceph-14.2.1/src/test/rgw/test_http_manager.cc ceph-14.2.1-fix_rgw_sync/src/test/rgw/test_http_manager.cc
--- ceph-14.2.1/src/test/rgw/test_http_manager.cc 2019-04-26 03:45:48.000000000 +0930
+++ ceph-14.2.1-fix_rgw_sync/src/test/rgw/test_http_manager.cc 2019-06-29 14:11:56.499191779 +0930
@@ -16,8 +16,39 @@
#include "global/global_init.h"
#include "common/ceph_argparse.h"
#include <curl/curl.h>
+#include <boost/asio/ip/tcp.hpp>
+#include <boost/asio/write.hpp>
+#include <thread>
#include <gtest/gtest.h>
+TEST(HTTPManager, ReadTruncated)
+{
+ using tcp = boost::asio::ip::tcp;
+ tcp::endpoint endpoint(tcp::v4(), 0);
+ boost::asio::io_context ioctx;
+ tcp::acceptor acceptor(ioctx);
+ acceptor.open(endpoint.protocol());
+ acceptor.bind(endpoint);
+ acceptor.listen();
+
+ std::thread server{[&] {
+ tcp::socket socket{ioctx};
+ acceptor.accept(socket);
+ std::string_view response =
+ "HTTP/1.1 200 OK\r\n"
+ "Content-Length: 1024\r\n"
+ "\r\n"
+ "short body";
+ boost::asio::write(socket, boost::asio::buffer(response));
+ }};
+ const auto url = std::string{"http://127.0.0.1:"} + std::to_string(acceptor.local_endpoint().port());
+
+ RGWHTTPClient client{g_ceph_context, "GET", url};
+ EXPECT_EQ(-EAGAIN, RGWHTTP::process(&client, null_yield));
+
+ server.join();
+}
+
TEST(HTTPManager, SignalThread)
{
auto cct = g_ceph_context;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment