Skip to content
This repository was archived by the owner on Apr 8, 2025. It is now read-only.

Commit 054149a

Browse files
Jinming-Huvinjiang
authored andcommitted
Fix crash bug in execute_batch
1 parent 65a4ec2 commit 054149a

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

Microsoft.WindowsAzure.Storage/includes/wascore/protocol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ namespace azure { namespace storage { namespace protocol {
8686
storage_uri generate_table_uri(const cloud_table_client& service_client, const cloud_table& table, const table_query& query, const continuation_token& token);
8787
web::http::http_request execute_table_operation(const cloud_table& table, table_operation_type operation_type, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context);
8888
web::http::http_request execute_operation(const table_operation& operation, table_payload_format payload_format, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context);
89-
web::http::http_request execute_batch_operation(Concurrency::streams::stringstreambuf& response_buffer, const cloud_table& table, const table_batch_operation& batch_operation, table_payload_format payload_format, bool is_query, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context);
89+
web::http::http_request execute_batch_operation(const cloud_table& table, const table_batch_operation& batch_operation, table_payload_format payload_format, bool is_query, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context);
9090
web::http::http_request execute_query(table_payload_format payload_format, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context);
9191
web::http::http_request get_table_acl(web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context);
9292
web::http::http_request set_table_acl(web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context);
@@ -229,7 +229,7 @@ namespace azure { namespace storage { namespace protocol {
229229
public:
230230
static utility::string_t parse_etag(const web::http::http_response& response);
231231
static continuation_token parse_continuation_token(const web::http::http_response& response, const request_result& result);
232-
static std::vector<table_result> parse_batch_results(const web::http::http_response& response, Concurrency::streams::stringstreambuf& response_buffer, bool is_query, size_t batch_size);
232+
static std::vector<table_result> parse_batch_results(const web::http::http_response& response, const concurrency::streams::container_buffer<std::vector<uint8_t>>& response_buffer, bool is_query, size_t batch_size);
233233
static std::vector<table_entity> parse_query_results(const web::json::value& obj);
234234
};
235235

Microsoft.WindowsAzure.Storage/src/cloud_table.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ namespace azure { namespace storage {
192192
throw std::invalid_argument(protocol::error_batch_operation_retrieve_mix);
193193
}
194194

195-
// TODO: Pre-create a stream for the response to pass to response handler in other functions too so the response doesn't need to be copied
196-
Concurrency::streams::stringstreambuf response_buffer;
195+
concurrency::streams::container_buffer<std::vector<uint8_t>> response_buffer;
197196

198197
std::shared_ptr<core::storage_command<std::vector<table_result>>> command = std::make_shared<core::storage_command<std::vector<table_result>>>(uri);
199-
command->set_build_request(std::bind(protocol::execute_batch_operation, response_buffer, *this, operation, options.payload_format(), is_query, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
198+
command->set_build_request(std::bind(protocol::execute_batch_operation, *this, operation, options.payload_format(), is_query, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
200199
command->set_authentication_handler(service_client().authentication_handler());
201200
command->set_location_mode(is_query ? core::command_location_mode::primary_or_secondary : core::command_location_mode::primary_only);
201+
command->set_destination_stream(response_buffer.create_ostream());
202202
command->set_preprocess_response(std::bind(protocol::preprocess_response<std::vector<table_result>>, std::vector<table_result>(), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
203203
command->set_postprocess_response([response_buffer, operations, is_query] (const web::http::http_response& response, const request_result&, const core::ostream_descriptor&, operation_context context) mutable -> pplx::task<std::vector<table_result>>
204204
{

Microsoft.WindowsAzure.Storage/src/table_request_factory.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,12 @@ namespace azure { namespace storage { namespace protocol {
441441
return request;
442442
}
443443

444-
web::http::http_request execute_batch_operation(Concurrency::streams::stringstreambuf& response_buffer, const cloud_table& table, const table_batch_operation& batch_operation, table_payload_format payload_format, bool is_query, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context)
444+
web::http::http_request execute_batch_operation(const cloud_table& table, const table_batch_operation& batch_operation, table_payload_format payload_format, bool is_query, web::http::uri_builder& uri_builder, const std::chrono::seconds& timeout, operation_context context)
445445
{
446446
utility::string_t batch_boundary_name = core::generate_boundary_name(_XPLATSTR("batch"));
447447
utility::string_t changeset_boundary_name = core::generate_boundary_name(_XPLATSTR("changeset"));
448448

449449
web::http::http_request request = table_base_request(web::http::methods::POST, uri_builder, timeout, context);
450-
// Need to reset the response buffer before each batch operation is executed.
451-
response_buffer.collection().resize(0);
452-
response_buffer.seekpos(0, std::ios_base::out);
453-
request.set_response_stream(Concurrency::streams::ostream(response_buffer));
454450

455451
web::http::http_headers& request_headers = request.headers();
456452
request_headers.add(web::http::header_names::accept_charset, header_value_charset_utf8);

Microsoft.WindowsAzure.Storage/src/table_response_parsers.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ namespace azure { namespace storage { namespace protocol {
6868
return token;
6969
}
7070

71-
std::vector<table_result> table_response_parsers::parse_batch_results(const web::http::http_response& response, Concurrency::streams::stringstreambuf& response_buffer, bool is_query, size_t batch_size)
71+
std::vector<table_result> table_response_parsers::parse_batch_results(const web::http::http_response& response, const concurrency::streams::container_buffer<std::vector<uint8_t>>& response_buffer, bool is_query, size_t batch_size)
7272
{
7373
std::vector<table_result> batch_result;
7474
batch_result.reserve(batch_size);
7575

76-
std::string& response_body = response_buffer.collection();
76+
// TODO: We make a copy of the response here, we may optimize it in the future
77+
const std::vector<uint8_t>& response_collection = response_buffer.collection();
78+
const std::string response_body(response_collection.begin(), response_collection.end());
7779

7880
// TODO: Make this Casablanca code more robust
7981

0 commit comments

Comments
 (0)