Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique ptr for body stream #214

Merged
merged 27 commits into from
Jun 29, 2020
Merged

Conversation

vhvb1989
Copy link
Member

@vhvb1989 vhvb1989 commented Jun 25, 2020

Changing stream body * to unique_ptr .

Storage unit tests passing.

I updated the protocol and convenient layer. I understand it is auto generated. But hopefully it can be used as reference of a working configuration.

@vhvb1989 vhvb1989 self-assigned this Jun 25, 2020
@vhvb1989 vhvb1989 marked this pull request as ready for review June 25, 2020 05:16
@Jinming-Hu Jinming-Hu force-pushed the unique-ptr-for-body-stream branch from ba3385e to 9eed070 Compare June 25, 2020 13:57
@Jinming-Hu Jinming-Hu force-pushed the unique-ptr-for-body-stream branch from 9eed070 to 21d18f9 Compare June 25, 2020 16:08
if (isContentLengthHeaderInResponse != headers.end())
{
// Response with Content-Length
auto bodySize = atoi(headers.at("Content-Length").data());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

atoi cannot handle value > INT_MAX, which is 2GB-1. use std::stoull or std::stoll instead

}

// Response with no Content-Length and no Transfer-Encoding header. Throw
throw;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can happen, I met once just now.
We cannot just throw;, it will crash the whole program.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it looks like in case of no Transfer-Encoding or Content-Length, we should just read until the connection is closed.

https://tools.ietf.org/html/rfc7230#section-3.3.3

  1. Otherwise, this is a response message without a declared message
    body length, so the message body length is determined by the
    number of octets received prior to the server closing the
    connection.

I going to remove the throw for now.

I need to improve the reading strategies to avoid code duplication, I will make a new issue for it

Copy link
Member

@Jinming-Hu Jinming-Hu Jun 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, just looked through the link. It seems that this HTTP1.1 is very complex and Azure Core team is re-implementating the HTTP stack from scratch.

I have no objections to that. I just feel it's a huge load of work to make it HTTP1.1 compatible and there's going to be many many glitches.

@@ -3131,7 +3131,7 @@ namespace Azure { namespace Storage { namespace Blobs {

static Azure::Core::Http::Request SetAccessTierConstructRequest(
const std::string& url,
const SetAccessTierOptions& options)
SetAccessTierOptions& options)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JinmingHu-MSFT , all options can still be const. Why did we remove it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was const, how can we move that std::unique_ptr?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would let body out of the options and as an extra argument for Constructing the Request, just like is it now an extra arg for some other functions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vhvb1989 I'm also okay with this way.

But there's this conclusion that Azure Core team and Azure Storage team and Jeffrey all agreed on in the meeting months ago, that in protocol layer interface, there're only two parameters, url and options.

I'm not sure if we can just overturn that decision.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I remember.
However, we didn't consider having a unique_ptr in the options (that needs to be moved).
I also find kind of weird to have a body as an option. It has a benefit for non-body requests like GET/HEAD, but we could easily use nullptr as arg.

Having cost for options IMO is the best wat to make sure options won't be mutated. So I wouldn't change that.

I would like to bring this to our meeting @gilbertw , @JeffreyRichter

As for now, let's use options without const as the last agreement.
Thank you @JinmingHu-MSFT

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vhvb1989 Let's bring this up in the weekly meeting, so that we can make a decision together. Once we have a conclusion, i'm going to change the code. But before that, let's just keep it as it is now.

#include <vector>

namespace Azure { namespace Storage {

class MemoryStream : public Azure::Core::Http::BodyStream {
public:
explicit MemoryStream(const uint8_t* data, std::size_t length) : m_data(data), m_length(length) {}
explicit MemoryStream(const uint8_t* data, std::size_t length) : m_data(data), m_length(length)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JinmingHu-MSFT , is there a reason to have this memoryStream and the one from Azure::Core ?
I would say let's have just one

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

replied in that issue.

@vhvb1989
Copy link
Member Author

/check-enforcer override

Comment on lines +141 to +142
constexpr uint64_t fixedSize = 1024 * 15;
uint8_t tempBuffer[fixedSize];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both Azure Core SDK and Azure Storage SDK are supposed to be portable. So we cannot assume that on every platforms with all kinds of hardware configuration, the stack size is at least 16KB.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants