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

Support listening on multiple ports #204

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hallfox
Copy link
Collaborator

@hallfox hallfox commented Feb 16, 2024

This extends the broker config to support listening to connections on multiple ports. This lays the groundwork for future extensions that will be added to TcpInterfaceListener. The broker will behave the same without the listener config, but with the listeners added the broker will open new listen operations for each one, ignoring the port field in the networkInterfaces. We also added an extra component for validating these new configs.

@hallfox hallfox requested a review from a team as a code owner February 16, 2024 23:55
@hallfox hallfox force-pushed the multi-session-listener branch 3 times, most recently from 1046055 to 679a99f Compare February 20, 2024 17:56
Copy link
Collaborator

@dorjesinpo dorjesinpo left a comment

Choose a reason for hiding this comment

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

Looks good and straightforward
Few comments, and probably will need to take another look after tests are fixed

@@ -661,7 +751,7 @@ void TCPSessionFactory::channelStateCallback(
// is fine to do this here (since we have no other ways to
// proactively-execute code in the IO threads created by the channelPool).
if (mwcsys::ThreadUtil::k_SUPPORT_THREAD_NAME) {
mwcsys::ThreadUtil::setCurrentThreadNameOnce(d_threadName);
mwcsys::ThreadUtil::setCurrentThreadNameOnce(d_config.name());
Copy link
Collaborator

Choose a reason for hiding this comment

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

d_threadName = "bmqIO_" + d_config.name().substr(0, 15 - 6);
What happens with the prefix? And with the d_threadName?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a mistake, reverting this.

src/groups/mqb/mqbnet/mqbnet_tcpsessionfactory.cpp Outdated Show resolved Hide resolved
</annotation>
<sequence>
<element name='name' type='string'/>
<element name='port' type='int'/>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We may need to retire the above port when all broker versions read new config.
We need to mark it as deprecated maybe?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I can mark it deprecated in the schema documentation. The behavior of what the broker should do is probably better documented in other documentation sources too.

OperationContext* context = new (*d_allocator_p) OperationContext();
d_listenContext_mp.load(context, d_allocator_p);
bsl::shared_ptr<OperationContext> contextSp;
contextSp.reset(context, bslstl::SharedPtrNilDeleter());
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, this insisting on the ManagedPtr looks strange

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I'm not in love with this pattern of trading around ManagedPtrs as references wrapped in a shared_ptr, either way now there's a reason to make it shared so this doesn't even work anymore 😄

@@ -528,7 +532,8 @@ class TCPSessionFactory {
/// Listen to the specified `port` for incoming connection and invoke
Copy link
Collaborator

Choose a reason for hiding this comment

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

The documentation comment here is out-of-date now: port argument replaced with listener; sentence should be changed.

@@ -468,6 +465,13 @@ class TCPSessionFactory {
/// event scheduler processes it.
void disableHeartbeat(const bsl::shared_ptr<ChannelInfo>& channelInfo);

/// \brief Check that the TCP interfaces are valid.
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is our first Doxygen \brief. Two things:

  1. CONTRIBUTING.md says we should use Javadoc style @brief.
  2. We currently have Doxygen AUTOBRIEF turned off, but it seems likely we'll need to turn it on when we start using straight Doxygen rather than BDE-flavor docs, or we'll need to go through every docstring and add @brief (yikes!). For the moment, it seems better to match the style of the rest of the docs here.

// Handle which can be used to
// stop listening. Empty unless
// listening.
// Handles which can be used to stop listening. Empty unless listening.
Copy link
Collaborator

Choose a reason for hiding this comment

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

/// ? Change above uses Doxygen style. Seems like it's best to use Doxygen style throughout, and let Doxygen itself choose whether to output docs on private members.

// Handle which can be used to
// stop listening. Empty unless
// listening.
// Handles which can be used to stop listening. Empty unless listening.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Handles which -> Handles that---had to look at the type to understand that handles isn't a verb here.

errorDescription << "Failed listening to port '" << it->port()
<< "' for TCPSessionFactory '"
<< d_config.name() << "' [rc: " << rc << "]";
return rc; // RETURN
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need cleanup for ports in earlier iterations of the loop that we have successfully listened on? Prior to this patch this wasn't a concern.


allocator_type get_allocator() const { return d_allocator; }

/// viewFn :: NetworkInterface -> T
Copy link
Collaborator

Choose a reason for hiding this comment

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

Haskell type notation 😂 But I'm not sure this is a useful docstring.

But had to look at the code to understand that T is an arbitrary Regular type to be used as a comparison key. More docs around the use and purpose of this private class, as well this function particularly, would be helpful.

UniqueProperty d_unique;

// PRIVATE STATIC FUNCTIONS
static int portView(const mqbcfg::TcpInterfaceListener& listener)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a view?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It could create a view, so technically no. The codegen'd API doesn't give me const ref access to this field, so it's a little unfortunate, but It's sufficient enough for our purposes.


class TcpInterfaceListener {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Documentation for publicly exposed class?

@hallfox hallfox changed the title Support listening on open ports Support listening on multiple ports Jul 25, 2024
@hallfox hallfox force-pushed the multi-session-listener branch 5 times, most recently from 38396bf to 4bb16fd Compare July 30, 2024 15:15
@@ -15,6 +15,7 @@ broker, as well as the generated corresponding messages component.
..
1. mqbcfg_messages
2. mqbcfg_brokerconfig
3. mqbcfg_tcpinterfaceconfigvalidator
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This adds another component/level, the synopsis can be updated

@hallfox hallfox force-pushed the multi-session-listener branch 9 times, most recently from ad17ee8 to 67b14e6 Compare August 8, 2024 18:35
- Add a new field for the broker config to list TCP interfaces with a
  port and name
- Change how the port configuration is read to ignore the port field on
  the TCP interface when the new listeners are specified
- Add a test fixture to support configuring clusters with multiple
  TCP interfaces open
- Add an integration test to verify end-to-end connection on a cluster
  with multiple ports

Signed-off-by: Taylor Foxhall <tfoxhall@bloomberg.net>
Copy link
Collaborator

@pniedzielski pniedzielski left a comment

Choose a reason for hiding this comment

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

Merge conflicts, can review again when you fix them.

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.

5 participants