Skip to content

Conversation

@scw00
Copy link
Member

@scw00 scw00 commented Nov 4, 2017

Fix #2692 , #2693

Move the postbuf into HttpSM.

@scw00 scw00 force-pushed the redirect_post_buffer branch 6 times, most recently from b02d00e to 961b379 Compare November 4, 2017 08:38
tunnel.reset();

tunnel.allocate_redirect_postdata_producer_buffer();

Copy link
Member Author

@scw00 scw00 Nov 4, 2017

Choose a reason for hiding this comment

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

This line will cause the post buf truncated.

We should not deallocate postbuf. postdata_copy_buffer_start because it is the same as we doing postbuf.ua_buffer_reader->consume.

@scw00 scw00 force-pushed the redirect_post_buffer branch from 961b379 to 24e044f Compare November 4, 2017 10:10
#define DEFAULT_BUFFER_NUMBER 128
#define DEFAULT_HUGE_BUFFER_NUMBER 32
#define MAX_MIOBUFFER_READERS 5
#define MAX_MIOBUFFER_READERS 6
Copy link
Member

Choose a reason for hiding this comment

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

IMO, the max value 5 is enough.

// copy the post data into a new producer buffer for static producer
tunnel.postbuf->postdata_producer_buffer->write(tunnel.postbuf->postdata_copy_buffer_start);
int64_t post_bytes = tunnel.postbuf->postdata_producer_reader->read_avail();
MIOBuffer *postdata_producer_buffer = new_empty_MIOBuffer();
Copy link
Member

Choose a reason for hiding this comment

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

It saves the memory to avoid allocate a new IOBufferBlock because it always get data by clone().


if (this->postdata_copy_buffer == nullptr) {
ink_assert(this->postdata_copy_buffer_start == nullptr);
this->postdata_copy_buffer = new_MIOBuffer(BUFFER_SIZE_INDEX_4K);
Copy link
Member

Choose a reason for hiding this comment

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

IMO, new_empty_MIOBuffer() is more better, the same as postdata_producer_buffer above.

@oknet oknet added this to the 8.0.0 milestone Nov 4, 2017
@scw00 scw00 force-pushed the redirect_post_buffer branch from 24e044f to bd84fd9 Compare November 4, 2017 10:52
@oknet
Copy link
Member

oknet commented Nov 4, 2017

The PostDataBuffers is designed to save the post payload while retry to make a new request.

The HttpTunnel is designed to move the data from producer to one or more consumers. It should not keep any data after tunnel.reset().

Any data that is received from ua_session or server_session, the owner of these data is HttpSM.

According to the above analysis, the PR moves the PostDataBuffers from HttpTunnel to HttpSM.

With the PR,

  1. Incoming data is saved into the PostDataBuffers by HttpTunnel
  2. Tunnel is reset if request is redirected. But the HttpSM still keeps the post payload.
  3. HttpSM make a new request and clone the post payload for new HttpTunnel.

oknet
oknet previously approved these changes Nov 4, 2017
HttpSM::postbuf_read_ndone()
{
return this->_postbuf.postdata_copy_buffer_start->read_avail();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rename this method to something like postbuf_buffer_avail?

Same reasoning as above suggestion to rename postbuf_read_avail.

Copy link
Member Author

@scw00 scw00 Nov 5, 2017

Choose a reason for hiding this comment

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

As the comment above!

DebugSM("http_redirect", "[HttpSM::do_redirect]");
if (!enable_redirection || redirection_tries > t_state.txn_conf->number_of_redirections) {
tunnel.deallocate_redirect_postdata_buffers();
// tunnel.deallocate_redirect_postdata_buffers();
Copy link
Contributor

Choose a reason for hiding this comment

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

We can remove the comment.

}

if (this->ua_buffer_reader != nullptr) {
this->ua_buffer_reader->mbuf->dealloc_reader(this->ua_buffer_reader);
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to check that this->ua_buffer_reader->mbuf != nullptr?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, the ua_buffer_reader may be released in tunnel.

{
// the this->ua_buffer_reader may be realeased in tunnel::deallocate_buffers.
// we always set a new reader instead of the old value;
// ink_assert(this->ua_buffer_reader == nullptr);
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably we should remove this comment and guarantee that this->ua_buffer_reader != nullptr before we return.

The following assume it is not null:

  • PostDataBuffers::copy_partial_post_data
  • HttpSM::postbuf_read_avail

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds reasonable !

HttpSM::postbuf_read_avail()
{
return this->_postbuf.ua_buffer_reader->read_avail();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we rename this method to something like postbuf_reader_avail?

Referencing a debug log message in HttpTunnel.cc:

1163 Debug("http_redirect", "[HttpTunnel::producer_handler] post exceeds buffer limit, buffer_avail=%" PRId64
1164                              " reader_avail=%" PRId64 " limit=%" PRId64 "",
1165             sm->postbuf_read_ndone(), sm->postbuf_read_avail(), HttpConfig::m_master.post_copy_size);

Here the message uses "buffer_avail" and "reader_avail", and it seems clearer.

Copy link
Member Author

@scw00 scw00 Nov 5, 2017

Choose a reason for hiding this comment

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

good point ! I'll fix that .

void copy_partial_post_data();

~PostDataBuffers();
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Just an observation. By omitting the default constructor definition here, we are losing the following debug message from HttpTunnel.h

266      Debug("http_redirect", "[PostDataBuffers::PostDataBuffers]"); 

This may not have been a very useful debug message though.

Copy link
Member Author

Choose a reason for hiding this comment

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

IMO, postbuf in HttpSM is not a pointer. It is always allocated with HttpSM.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, sounds good. Just checking.

@scw00 scw00 force-pushed the redirect_post_buffer branch from acbbe9a to daafeda Compare November 5, 2017 06:32
Copy link
Contributor

@d2r d2r left a comment

Choose a reason for hiding this comment

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

👍 (non-binding)

@zwoop
Copy link
Contributor

zwoop commented Nov 8, 2017

Candidate for 7.1.2 ?

@bryancall
Copy link
Contributor

@scw00
We should have an autest for this to make sure POSTs work with redirection.

@zwoop zwoop merged commit b9988fd into apache:master Nov 8, 2017
@scw00
Copy link
Member Author

scw00 commented Nov 8, 2017

@bryancall . I'll give another pr on this weekends.

@scw00
Copy link
Member Author

scw00 commented Nov 9, 2017

@zwoop! Yes it is candidate for 7.1.2, but please waiting for my autest pr.

@zwoop
Copy link
Contributor

zwoop commented Nov 10, 2017

Alrighty, let me know what other PRs this depends on when ready.

@d2r
Copy link
Contributor

d2r commented Nov 27, 2017

@scw00 #2800 was merged. Do we want to back-port this?

@d2r
Copy link
Contributor

d2r commented Dec 6, 2017

@scw00 @zwoop Ping

@scw00
Copy link
Member Author

scw00 commented Dec 7, 2017

Yes we can port this pr to 7.1.x @zwoop now.

@zwoop zwoop modified the milestones: 8.0.0, 7.1.3 Jan 22, 2018
@zwoop
Copy link
Contributor

zwoop commented Jan 22, 2018

Cherry-picked to 7.1.3

@scw00 scw00 deleted the redirect_post_buffer branch March 15, 2018 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants