mysqljs / mysql

A pure node.js JavaScript Client implementing the MySQL protocol.
MIT License
18.22k stars 2.53k forks source link

PoolCluster: access to pool events, lack of docs #2468

Open singerb opened 3 years ago

singerb commented 3 years ago

I started experimenting with using PoolCluster to manage pools to multiple databases, including distinguishing readonly from readwrite (i.e. primary and replicas) via aliases and wildcards. I ran into trouble for a few reasons:

I know the documentation concerns have been raised before, but wanted to capture my thoughts on the other issues.

dougwilson commented 3 years ago

Hi @singerb thank you for your thoughts. The entire PoolCluster system was a contribution by another user and we graciously accepted. I understand they did not document it very well, but if folks like yourself can help by making PRs improving these docs, that would be a huge help to others 👍 . I didn't fully read through all your concerns/comments above, but they seem to be various items like asking for new features, fixes, and docs. I would highly recommend splitting each separate ask into a separate issue, as otherwise it makes the issue seem like a lot for those who may want to contribute just part of it, and of course the more things in a single issue, the more comments it get, and the harder it is in the future to understand what has been done, what has not been done, what has changed, etc.

iamlaobie commented 3 years ago

I have the same questions when I upgrade my project to poolCluster from single pool. I read source code and find connection initial method like this:

  const { charset, timezone } = options ;
  Object.keys(pool._nodes).forEach(key => {
    pool._nodes[key].pool.on('connection', (connection) => {
      if (timezone) connection.query(`SET SESSION time_zone = '${timezone}'`);
      if (charset) connection.query(`SET NAMES ${charset}`);
    });
  });