Bugzilla – Attachment 26485 Details for
Bug 11974
Enable non-default unix socket location for database connections.
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 11974 - Enable unix socket connections for database connections.
Bug-11974---Enable-unix-socket-connections-for-dat.patch (text/plain), 4.31 KB, created by
Olli-Antti Kivilahti
on 2014-03-20 13:11:49 UTC
(
hide
)
Description:
Bug 11974 - Enable unix socket connections for database connections.
Filename:
MIME Type:
Creator:
Olli-Antti Kivilahti
Created:
2014-03-20 13:11:49 UTC
Size:
4.31 KB
patch
obsolete
>From 66a12ece2c9ac59cfeddc79f2711052c8d560fc5 Mon Sep 17 00:00:00 2001 >From: Olli-Antti Kivilahti <olli-antti.kivilahti@jns.fi> >Date: Thu, 20 Mar 2014 14:35:57 +0200 >Subject: [PATCH] Bug 11974 - Enable unix socket connections for database > connections. > >----------------- >- BUSINESS CASE - >----------------- >Currently Koha doesn't support using a non-default unix socket for database connections. >Using unix sockets is generally ~30-40% faster compared to using TCP packets. Because >Koha abuses the database a lot, this will make a difference. > >------------ >- SOLUTION - >------------ >Mysql uses unix sockets for localhost connections only, but DBI::Mysql cannot automatically >find the non-default socket path, thus it needs to be explicitly given. > >This patch modifies the C4::Context->dbh() routine to check for the presence of >mysql_socket in koha-conf.xml and prioritize the socket connection. >If making the socket connection fails, dbh() defaults to the TCP-connection if available. > >This patch works on MariaDB and Mysql, hence the configuration variable name mysql_socket. > >------------- >- TEST PLAN - >------------- >DEFAULT: >1. edit koha-conf.xml >1.1. uncomment row <mysql_socket>... and put your socket path here, > by default /var/run/mysqld/mysqld.sock . > or create the xml-entry <mysql_socket>/var/run/mysqld/mysqld.sock</mysql_socket> >2. load any koha's web-page. Shouldn't get any errors. > >SOCKET ONLY: >replicate DEFAULT and do the following instructions: >3. From koha-conf.xml, remove hostname or set to bad name. >4. load any koha's web page. >5. Mysql/MariaDB connection works faster than ever! > >BAD SOCKET: >1. but a bad path as your mysql_socket, eg /var/run/mysqld/mysqld.sockBADBAD >2. load any koha's web-page. see your koha-error_log or koha-opac-error_log for the error. > You can still use Koha normally, but it is recommended to fix bad socket ASAP. > >TOTAL DESTRUCTION: >replicate BAD SOCKET and do the following instructions: >3. from koha-conf.xml remove hostname or change to a bad one. >4. load any koha's web page. Enjoy the "Software error". > >Thank you for testing! >--- > C4/Context.pm | 19 ++++++++++++++++--- > etc/koha-conf.xml | 1 + > 2 files changed, 17 insertions(+), 3 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index 5a76137..332fa3b 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -806,9 +806,22 @@ sub _new_dbh > my $db_port = $context->config("port") || ''; > my $db_user = $context->config("user"); > my $db_passwd = $context->config("pass"); >- # MJR added or die here, as we can't work without dbh >- my $dbh = DBI->connect("DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port", >- $db_user, $db_passwd, {'RaiseError' => $ENV{DEBUG}?1:0 }) or die $DBI::errstr; >+ my $db_mysql_socket = $context->config("mysql_socket") || ''; >+ >+ my $dbh; >+ #if a unix socket is given use that instead of TCP (as it is way faster!) ONLY Mysql-derivatives >+ # Instead of dying, just warn about the error because we can fall back to a TCP-connection. >+ if ($db_mysql_socket && ($db_driver =~ /mysql/i || $db_driver =~ /mariadb/i)) { >+ # MJR added or die here, as we can't work without dbh >+ $dbh = DBI->connect("DBI:$db_driver:dbname=$db_name;mysql_socket=$db_mysql_socket", >+ $db_user, $db_passwd, {'RaiseError' => $ENV{DEBUG}?1:0 }) or warn $DBI::errstr; >+ } >+ #Try making a TCP connection >+ if ((! defined ($dbh)) && $db_host) { >+ # MJR added or die here, as we can't work without dbh >+ $dbh = DBI->connect("DBI:$db_driver:dbname=$db_name;host=$db_host;port=$db_port", >+ $db_user, $db_passwd, {'RaiseError' => $ENV{DEBUG}?1:0 }) or die $DBI::errstr; >+ } > > # Check for the existence of a systempreference table; if we don't have this, we don't > # have a valid database and should not set RaiseError in order to allow the installer >diff --git a/etc/koha-conf.xml b/etc/koha-conf.xml >index 72da2de..8f1be34 100644 >--- a/etc/koha-conf.xml >+++ b/etc/koha-conf.xml >@@ -271,6 +271,7 @@ __PAZPAR2_TOGGLE_XML_POST__ > <database>__DB_NAME__</database> > <hostname>__DB_HOST__</hostname> > <port>__DB_PORT__</port> >+<!-- <mysql_socket>__put your non-default mysql/mariadb socket path here. eg /tmp/mysqld.sock__</mysql_socket> --> > <user>__DB_USER__</user> > <pass>__DB_PASS__</pass> > <biblioserver>biblios</biblioserver> >-- >1.8.1.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 11974
:
26484
|
26485
|
26486
|
26487
|
26505
|
63940
|
63941
|
63942
|
63943
|
73131