Commit b05f9c8a authored by Julien Muchembled's avatar Julien Muchembled

storage: extend syntax of database argument to specific socket of a MySQL DB

parent 8cb16d74
...@@ -4,7 +4,8 @@ Change History ...@@ -4,7 +4,8 @@ Change History
0.9.2 (unreleased) 0.9.2 (unreleased)
------------------ ------------------
- storage: fix possible ConflictError when client is much faster than master - storage: a specific socket can be given to MySQL backend
- storage: a ConflictError could happen when client is much faster than master
0.9.1 (2011-09-24) 0.9.1 (2011-09-24)
------------------ ------------------
......
...@@ -31,8 +31,8 @@ partitions: 20 ...@@ -31,8 +31,8 @@ partitions: 20
# Some parameters makes no sense to be defined in [DEFAULT] section. # Some parameters makes no sense to be defined in [DEFAULT] section.
# They are: # They are:
# bind: The ip:port the node will listen on. # bind: The ip:port the node will listen on.
# database: Storage nodes only. The MySQL database credentials to use # database: Storage nodes only.
# (username:password@database). # Syntax for MySQL database is [user[:password]@]database[unix_socket]
# Those database must be created manualy. # Those database must be created manualy.
# Admin node # Admin node
......
...@@ -22,6 +22,7 @@ from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST ...@@ -22,6 +22,7 @@ from MySQLdb.constants.CR import SERVER_GONE_ERROR, SERVER_LOST
import neo.lib import neo.lib
from array import array from array import array
from hashlib import md5 from hashlib import md5
import re
import string import string
from neo.storage.database import DatabaseManager from neo.storage.database import DatabaseManager
...@@ -52,21 +53,16 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -52,21 +53,16 @@ class MySQLDatabaseManager(DatabaseManager):
def __init__(self, database): def __init__(self, database):
super(MySQLDatabaseManager, self).__init__() super(MySQLDatabaseManager, self).__init__()
self.user, self.passwd, self.db = self._parse(database) self.user, self.passwd, self.db, self.socket = self._parse(database)
self.conn = None self.conn = None
self._config = {} self._config = {}
self._connect() self._connect()
def _parse(self, database): def _parse(self, database):
""" Get the database credentials (username, password, database) """ """ Get the database credentials (username, password, database) """
# expected pattern : [user[:password]@]database # expected pattern : [user[:password]@]database[unix_socket]
username = None return re.match('(?:([^:]+)(?::(.*))?@)?([^./]+)(.+)?$',
password = None database).groups()
if '@' in database:
(username, database) = database.split('@')
if ':' in username:
(username, password) = username.split(':')
return (username, password, database)
def close(self): def close(self):
self.conn.close() self.conn.close()
...@@ -75,6 +71,8 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -75,6 +71,8 @@ class MySQLDatabaseManager(DatabaseManager):
kwd = {'db' : self.db, 'user' : self.user} kwd = {'db' : self.db, 'user' : self.user}
if self.passwd is not None: if self.passwd is not None:
kwd['passwd'] = self.passwd kwd['passwd'] = self.passwd
if self.socket:
kwd['unix_socket'] = self.socket
neo.lib.logging.info( neo.lib.logging.info(
'connecting to MySQL on the database %s with user %s', 'connecting to MySQL on the database %s with user %s',
self.db, self.user) self.db, self.user)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment