Skip to content

Refactoring the connection class to create buffers via factory#1234

Merged
mattklein123 merged 8 commits intoenvoyproxy:masterfrom
alyssawilk:buffer-management
Jul 12, 2017
Merged

Refactoring the connection class to create buffers via factory#1234
mattklein123 merged 8 commits intoenvoyproxy:masterfrom
alyssawilk:buffer-management

Conversation

@alyssawilk
Copy link
Copy Markdown
Contributor

This plus substantial refactors to the connection tests for code reuse, and some new tests using the new factories.

pulling this out from #1217 since it's well over 700 lines on its own.

Also did the read buffer along with the write buffer for consistency. Someone may need it some day and they shouldn't have to rewrite all the existing connection tests when they do.

alyssawilk added a commit to alyssawilk/envoy that referenced this pull request Jul 10, 2017
@alyssawilk alyssawilk mentioned this pull request Jul 10, 2017
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

overall very nice. Some quick comments. @dnoe can you also take a look at this one?

virtual ~Factory() {}

/**
* Creates and returns a unique pointer to a new buffer.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: @return ... (trying to use doxygen for new stuff).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

* Optionally sets a custom buffer factory for the dispatcher. This factory may be used by new
* connections on connection creation.
*/
virtual void setBufferFactory(Buffer::FactoryPtr&& factory) PURE;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you think it's worth having a setter on the interface? Seems like the factory could just be passed to the constructor of DispatcherImpl and then we avoid leaking the abstraction for changing it?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This would allow changing the factory to one with different behavior at runtime, but I'm not sure if that would ever be useful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, I thought it'd be useful for consistency but I'm happy to remove it - with a bit of test cleanup I don't think it needs to be set at runtime.


class OwnedImplFactory : public Factory {
public:
InstancePtr create() override;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: // Buffer::Factory above this line.

virtual void setBufferFactory(Buffer::FactoryPtr&& factory) PURE;

/**
* Returns the buffer factory for this dispatcher.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same @return doxygen comment here


Network::ListenerPtr listener = dispatcher.createSslListener(
connection_handler, *server_ctx, socket, listener_callbacks, stats_store,
void Initialize(uint32_t read_buffer_limit) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: initialize (lower case)

MOCK_METHOD2(move, void(Instance& rhs, uint64_t length));
MOCK_METHOD1(drain, void(uint64_t size));

void BaseMove(Instance& rhs) { Buffer::OwnedImpl::move(rhs); }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: lower case for method name start all through this class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ironically I reread the style guide before sending this one out but Google3 style habits are so hard to break :-P


namespace Envoy {

class MockBuffer : public Buffer::OwnedImpl {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nice addition, thanks.

return bytes_written;
}

int FailWrite(int) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this called? Not quite sure how it works?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's used in the other CL to force writes to "fail" and data to be buffered in the connection (eventually going over watermarks).

I'll remove it from this one since it's not currently used.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it's meant for testing only the usual convention is to name the method something like failWriteForTest(). This doesn't appear to be in the style doc, I'll create a PR that mentions this convention.

@mattklein123 mattklein123 requested a review from dnoe July 10, 2017 23:41
* Optionally sets a custom buffer factory for the dispatcher. This factory may be used by new
* connections on connection creation.
*/
virtual void setBufferFactory(Buffer::FactoryPtr&& factory) PURE;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This would allow changing the factory to one with different behavior at runtime, but I'm not sure if that would ever be useful.

// Network::BufferSource
Buffer::Instance& getReadBuffer() override { return read_buffer_; }
Buffer::Instance& getReadBuffer() override { return *read_buffer_; }
Buffer::Instance& getWriteBuffer() override { return *current_write_buffer_; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There's both a write_buffer_ and a current_write_buffer_. write_buffer_ is initialized via factory, but current_write_buffer_ is not (in fact it looks to me like it's always nullptr, so this line seems especially odd). This isn't a line changed in this PR, but it would be good to clarify...

@mattklein123 any idea what current_write_buffer_ was supposed to be for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's set in the cc file right before fitler_manager_.onWrite and cleared right after. There's a note that it's a bit of a hack to provide access under the stack of that call :-)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, that whole situation is not great but per @alyssawilk the comment should have the details.

MOCK_METHOD1(post, void(std::function<void()> callback));
MOCK_METHOD1(run, void(RunType type));
Buffer::Factory& getBufferFactory() override { return *buffer_factory_; }
void setBufferFactory(Buffer::FactoryPtr&& factory) override {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this only needed for the tests?

Copy link
Copy Markdown
Contributor

@dnoe dnoe left a comment

Choose a reason for hiding this comment

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

LGTM if @mattklein123 also approves

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

very nice, thanks.

@mattklein123 mattklein123 merged commit e0c1d7d into envoyproxy:master Jul 12, 2017
@alyssawilk alyssawilk deleted the buffer-management branch July 20, 2017 14:58
rshriram pushed a commit to rshriram/envoy that referenced this pull request Oct 30, 2018
Automatic merge from submit-queue.

Add notification for duplication

**What this PR does / why we need it**:

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
```

Add notification to match istio/istio#4358
jpsim pushed a commit that referenced this pull request Nov 28, 2022
Description: This tool was meant to be a bazel implementation detail so its public
accessor was removed in bazelbuild/bazel@f8b51ff

Using the cc API from bazel we can dynamically get this. This is still a
bit of a hack because we're writing our own args for this. We might be
able to fetch the args, based on bazel's crosstool, dynamically as well,
but ideally we remove this rule instead.

Fixes envoyproxy/envoy-mobile#1233

Signed-off-by: Keith Smiley <[email protected]>
Signed-off-by: JP Simard <[email protected]>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
Description: This tool was meant to be a bazel implementation detail so its public
accessor was removed in bazelbuild/bazel@f8b51ff

Using the cc API from bazel we can dynamically get this. This is still a
bit of a hack because we're writing our own args for this. We might be
able to fetch the args, based on bazel's crosstool, dynamically as well,
but ideally we remove this rule instead.

Fixes envoyproxy/envoy-mobile#1233

Signed-off-by: Keith Smiley <[email protected]>
Signed-off-by: JP Simard <[email protected]>
mathetake added a commit that referenced this pull request Mar 3, 2026
**Description**

This updates the Go version used here as well as some Go dependencies.

---------

Signed-off-by: Takeshi Yoneda <[email protected]>
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