You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/02/24 21:06:04 UTC

[GitHub] [pulsar] merlimat opened a new pull request #9702: [C++] SinglePartition message router is always picking the same partition

merlimat opened a new pull request #9702:
URL: https://github.com/apache/pulsar/pull/9702


   ### Motivation
   
   The `SinglePartitionMessageRouter` is supposed to pick a random partition for a given producer and to stick with that. The problem is that the C `rand()` call is always using the seed 0 and that ends up having multiple processes to always deterministically pick the same partition.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on a change in pull request #9702: [C++] SinglePartition message router is always picking the same partition

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on a change in pull request #9702:
URL: https://github.com/apache/pulsar/pull/9702#discussion_r582420498



##########
File path: pulsar-client-cpp/lib/SinglePartitionMessageRouter.cc
##########
@@ -18,9 +18,23 @@
  */
 #include "SinglePartitionMessageRouter.h"
 
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+#include <chrono>
+
 namespace pulsar {
 SinglePartitionMessageRouter::~SinglePartitionMessageRouter() {}
+
+SinglePartitionMessageRouter::SinglePartitionMessageRouter(const int numberOfPartitions,
+                                                           ProducerConfiguration::HashingScheme hashingScheme)
+    : MessageRouterBase(hashingScheme) {
+    boost::random::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
+    boost::random::uniform_int_distribution<int> dist;

Review comment:
       Should we use `std::random` from C++ standard library instead of `boost::random`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat commented on a change in pull request #9702: [C++] SinglePartition message router is always picking the same partition

Posted by GitBox <gi...@apache.org>.
merlimat commented on a change in pull request #9702:
URL: https://github.com/apache/pulsar/pull/9702#discussion_r582465760



##########
File path: pulsar-client-cpp/lib/SinglePartitionMessageRouter.cc
##########
@@ -18,9 +18,23 @@
  */
 #include "SinglePartitionMessageRouter.h"
 
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+#include <chrono>
+
 namespace pulsar {
 SinglePartitionMessageRouter::~SinglePartitionMessageRouter() {}
+
+SinglePartitionMessageRouter::SinglePartitionMessageRouter(const int numberOfPartitions,
+                                                           ProducerConfiguration::HashingScheme hashingScheme)
+    : MessageRouterBase(hashingScheme) {
+    boost::random::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
+    boost::random::uniform_int_distribution<int> dist;

Review comment:
       Good point. Fixed. 
   
   There are also other places where we use it. They should get converted as well .




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] merlimat merged pull request #9702: [C++] SinglePartition message router is always picking the same partition

Posted by GitBox <gi...@apache.org>.
merlimat merged pull request #9702:
URL: https://github.com/apache/pulsar/pull/9702


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [pulsar] BewareMyPower commented on a change in pull request #9702: [C++] SinglePartition message router is always picking the same partition

Posted by GitBox <gi...@apache.org>.
BewareMyPower commented on a change in pull request #9702:
URL: https://github.com/apache/pulsar/pull/9702#discussion_r582471899



##########
File path: pulsar-client-cpp/lib/SinglePartitionMessageRouter.cc
##########
@@ -18,9 +18,23 @@
  */
 #include "SinglePartitionMessageRouter.h"
 
+#include <boost/random/mersenne_twister.hpp>
+#include <boost/random/uniform_int_distribution.hpp>
+#include <chrono>
+
 namespace pulsar {
 SinglePartitionMessageRouter::~SinglePartitionMessageRouter() {}
+
+SinglePartitionMessageRouter::SinglePartitionMessageRouter(const int numberOfPartitions,
+                                                           ProducerConfiguration::HashingScheme hashingScheme)
+    : MessageRouterBase(hashingScheme) {
+    boost::random::mt19937 rng(std::chrono::high_resolution_clock::now().time_since_epoch().count());
+    boost::random::uniform_int_distribution<int> dist;

Review comment:
       Yeah, in `BackOff.cc` and `RoundRobinMessageRouter.cc`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org