You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by ho...@apache.org on 2017/07/11 20:04:12 UTC

[incubator-openwhisk-package-kafka] branch master updated: Do not attempt to share DB across multiple processes (#198)

This is an automated email from the ASF dual-hosted git repository.

houshengbo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-package-kafka.git


The following commit(s) were added to refs/heads/master by this push:
     new dfb0ddb  Do not attempt to share DB across multiple processes (#198)
dfb0ddb is described below

commit dfb0ddb3a56146a7387ab3b2aa746ac30a346e95
Author: Justin Berstler <bj...@us.ibm.com>
AuthorDate: Tue Jul 11 16:04:10 2017 -0400

    Do not attempt to share DB across multiple processes (#198)
    
    This does not play well when using SSL connections to the DB. The fix is to make the DB client an instance property of the Database class, and also to ensure that all instances of Database are themselves instance properties of whatever class is using it.
---
 provider/consumer.py |  4 ++--
 provider/database.py | 19 ++++++++++---------
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/provider/consumer.py b/provider/consumer.py
index 9c27d0f..b7fd732 100644
--- a/provider/consumer.py
+++ b/provider/consumer.py
@@ -118,8 +118,6 @@ class ConsumerProcess (Process):
     retry_timeout = 1   # Timeout in seconds
     max_retries = 10    # Maximum number of times to retry firing trigger
 
-    database = Database()
-
     def __init__(self, trigger, params, sharedDictionary):
         Process.__init__(self)
 
@@ -161,6 +159,8 @@ class ConsumerProcess (Process):
         else:
             self.encodeKeyAsBase64 = False
 
+        self.database = Database()
+
         # always init consumer to None in case the consumer needs to shut down
         # before the KafkaConsumer is fully initialized/assigned
         self.consumer = None
diff --git a/provider/database.py b/provider/database.py
index 4d0f78a..ac75cf4 100644
--- a/provider/database.py
+++ b/provider/database.py
@@ -35,21 +35,22 @@ class Database:
     password = os.environ['DB_PASS']
     url = os.environ['DB_URL']
 
-    client = CouchDB(username, password, url=url)
-    client.connect()
-
     filters_design_doc_id = '_design/filters'
     only_triggers_view_id = 'only-triggers'
 
     instance = os.getenv('INSTANCE', 'messageHubTrigger-0')
     canaryId = "canary-{}".format(instance)
 
-    if dbname in client.all_dbs():
-        logging.info('Database exists - connecting to it.')
-        database = client[dbname]
-    else:
-        logging.warn('Database does not exist - creating it.')
-        database = client.create_database(dbname)
+    def __init__(self):
+        client = CouchDB(self.username, self.password, url=self.url)
+        client.connect()
+
+        if self.dbname in client.all_dbs():
+            logging.info('Database exists - connecting to it.')
+            self.database = client[self.dbname]
+        else:
+            logging.warn('Database does not exist - creating it.')
+            self.database = client.create_database(self.dbname)
 
 
     def disableTrigger(self, triggerFQN, status_code):

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].