Skip to content

Conversation

@ywkaras
Copy link
Contributor

@ywkaras ywkaras commented Jan 6, 2022

No description provided.

@ywkaras ywkaras self-assigned this Jan 6, 2022
@ywkaras ywkaras requested review from jrushford and rob05c January 6, 2022 23:20
@rob05c
Copy link
Member

rob05c commented Jan 6, 2022

I have very mixed feelings about this.

An ideal solution isn't apparent. Every option has pros and a lot of cons.

HostRecord(const HostRecord &) = delete;
HostRecord &operator=(const HostRecord &) = delete;

I'm a big fan of deleting the copy and move - HostRecord conceptually should never be copied after initialization.

struct HostRecord : public ATSConsistentHashNode, public HostRecordCfg {

Not such a big fan of the multiple inheritance. I think the pains of multiple inheritance go without saying.

But the multiple inheritance can easily be avoided by using composition instead. I see the complexity as the bigger question.

Bigger picture, this adds another layer of abstraction, for a very small object. It's an awful lot of complexity for what really ought to be a dead-simple POD class.

Is it really worth all this complexity, the added readability and maintainability costs, to reduce the chance of one small type of bug? I honestly don't know.

struct ATSConsistentHashNode {
std::atomic<bool> available;
char *name;
std::atomic<bool> available{false};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should initialize available to true. All newly created host's should be available

return *this;
}
struct HostRecord : public ATSConsistentHashNode, public HostRecordCfg {
std::mutex _mutex;
Copy link
Contributor

Choose a reason for hiding this comment

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

@ywkaras I originally defined the constructor, copy constructor and assignment operator to avoid copying the state of the mutex in the POD. It's my understanding that this should be done, am I wrong about that?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh, I see. never mind, you added = delete

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine now, I didn't notice you deleted the operator = and copy constructor. This make for less maintenance if someone adds a field.

@ywkaras
Copy link
Contributor Author

ywkaras commented Jan 10, 2022

I guess I was figuring that, since the PR makes the code more than 30 lines shorter, it was making it less complicated. But maybe I just think too simplistically since I didn't go to graduate school.

@rob05c
Copy link
Member

rob05c commented Jan 10, 2022

I guess I was figuring that, since the PR makes the code more than 30 lines shorter, it was making it less complicated

I don't agree that lines of code is a strong indicator of complexity, or difficulty to read and maintain. Thirty lines fewer of assembly would not be less complex, but 30 lines more of Go probably would be.

I do see an additional layer of abstraction, another class, and multiple inheritance as more complex.

But as I said, I have mixed feelings, and I do agree there are advantages. I won't object if @jrushford or anyone else wants to approve.

@ywkaras
Copy link
Contributor Author

ywkaras commented Jan 10, 2022

It's accurate to observe that I'm using inheritance for something that is not intuitively an is-a relationship. I could instead have a HostRecordCfg substructure, instead of a base class, but that would mean more changes to the existing code. But it's fairly common to use inheritance in "tricky" ways in C++: https://stackoverflow.com/questions/4041447/how-is-stdtuple-implemented

@rob05c rob05c removed their request for review January 10, 2022 19:15
@ywkaras ywkaras marked this pull request as ready for review January 10, 2022 19:31
@ywkaras ywkaras added this to the 10.0.0 milestone Jan 10, 2022
@ywkaras ywkaras requested review from jrushford and removed request for SolidWallOfCode and bryancall January 10, 2022 21:46
Copy link
Contributor

@jrushford jrushford 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 to me

@ywkaras ywkaras merged commit 71e4aba into apache:master Jan 11, 2022
zwoop pushed a commit that referenced this pull request Jan 18, 2022
@zwoop
Copy link
Contributor

zwoop commented Jan 18, 2022

Cherry-picked to v9.2.x

@zwoop zwoop modified the milestones: 10.0.0, 9.2.0 Jan 18, 2022
moonchen pushed a commit to moonchen/trafficserver that referenced this pull request Mar 17, 2022
* asf/9.2.x:
  Updated ChangeLog
  TSHttpTxnCacheLookupStatusGet: handle cannot respond cases (apache#8545)
  Update to Proxy Verifier version v2.3.0 (apache#8608)
  Don't use Http1ClientTransaction as an event handler (apache#8609)
  Eliminate erroneous self-loop error on transparent mode (apache#8586)
  Clean up of next hop HostRecord class. (apache#8585)
  Propagate accept options to HTTP/2 (apache#8594)
  add --with-mimalloc option (apache#8233)
  Fix transparent mode documentation (apache#8593)
  Docs: Slack instead of irc (apache#8599)
  LogFilter: fix NULL termination check (apache#8603)
  Fixes a scoping bug that leads to "sticky" weights (apache#8606)
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.

4 participants