From b5cfd0e90bedf5d2a049d16d39bcc78cafac3251 Mon Sep 17 00:00:00 2001 From: Tiago Peralta Date: Sun, 3 Dec 2017 03:10:35 +0000 Subject: [PATCH 1/4] Fixed statistics graphs --- templates/bootstrap/statistics/graphs/default.tpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/bootstrap/statistics/graphs/default.tpl b/templates/bootstrap/statistics/graphs/default.tpl index b2007f71..95261fcc 100644 --- a/templates/bootstrap/statistics/graphs/default.tpl +++ b/templates/bootstrap/statistics/graphs/default.tpl @@ -2,7 +2,7 @@ $(function () { var hashChart = Morris.Line({ element: 'hashrate-area-chart', - data: {$YOURMININGSTATS}, + data: {$YOURMININGSTATS nofilter}, xkey: 'time', ykeys: ['hashrate'], labels: ['Hashrate'], @@ -17,7 +17,7 @@ $(function () { var workersChart = Morris.Line({ element: 'workers-area-chart', - data: {$YOURMININGSTATS}, + data: {$YOURMININGSTATS nofilter}, xkey: 'time', ykeys: ['workers'], labels: ['Workers'], @@ -32,7 +32,7 @@ $(function () { var shareCharts= Morris.Line({ element: 'sharerate-area-chart', - data: {$YOURMININGSTATS}, + data: {$YOURMININGSTATS nofilter}, xkey: 'time', ykeys: ['sharerate'], labels: ['Sharerate'], From 064ab5ac836a1e6b87009a57df0d13ee99439146 Mon Sep 17 00:00:00 2001 From: Tiago Peralta Date: Fri, 8 Dec 2017 15:53:56 +0000 Subject: [PATCH 2/4] No need for composer.lock to be versioned --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f7530209..5986fa6f 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,7 @@ tests/_output/* # NetBeans Project Directory -/nbproject/* \ No newline at end of file +/nbproject/* + +# No need for composer.lock +composer.lock \ No newline at end of file From 52c3e2ff930e453d7a90c25c41bdfff2b9681345 Mon Sep 17 00:00:00 2001 From: Tiago Peralta Date: Fri, 8 Dec 2017 22:53:15 +0000 Subject: [PATCH 3/4] Implemented Read/Write Mysql Split (Master for writes, Slave for reads) --- include/autoloader.inc.php | 1 + include/classes/mysqlims.class.php | 85 ++++++++++++++++++++++++++++++ include/config/global.inc.dist.php | 12 +++++ include/database.inc.php | 9 ++-- 4 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 include/classes/mysqlims.class.php diff --git a/include/autoloader.inc.php b/include/autoloader.inc.php index 2cc2c64a..e7a260bb 100644 --- a/include/autoloader.inc.php +++ b/include/autoloader.inc.php @@ -9,6 +9,7 @@ require_once(CLASS_DIR . '/debug.class.php'); if ($config['mysql_filter']) { require_once(CLASS_DIR . '/strict.class.php'); } +require_once(INCLUDE_DIR . '/classes/mysqlims.class.php'); require_once(INCLUDE_DIR . '/database.inc.php'); require_once(INCLUDE_DIR . '/config/memcache_keys.inc.php'); require_once(INCLUDE_DIR . '/config/error_codes.inc.php'); diff --git a/include/classes/mysqlims.class.php b/include/classes/mysqlims.class.php new file mode 100644 index 00000000..e78fb534 --- /dev/null +++ b/include/classes/mysqlims.class.php @@ -0,0 +1,85 @@ +mysqliW = new mysqli_strict($main['host'], + $main['user'], $main['pass'], + $main['name'], $main['port']); + if ($slave && is_array($slave) && isset($slave['enabled']) && $slave['enabled'] + === true) { + $this->mysqliR = new mysqli_strict($slave['host'], + $slave['user'], $slave['pass'], + $slave['name'], $slave['port']); + } + } else { + $this->mysqliW = new mysqli($main['host'], + $main['user'], $main['pass'], + $main['name'], $main['port']); + if ($slave && is_array($slave) && isset($slave['enabled']) && $slave['enabled'] + === true) { + $this->mysqliR = new mysqli($slave['host'], + $slave['user'], $slave['pass'], + $slave['name'], $slave['port']); + } + } + + if ($this->mysqliW->connect_errno) { + throw new Exception("Failed to connect to MySQL: (".$this->mysqliW->connect_errno.") ".$this->mysqliW->connect_error); + } + + if ($this->mysqliR->connect_errno) { + throw new Exception("Failed to connect to MySQL: (".$this->mysqliR->connect_errno.") ".$this->mysqliR->connect_error); + } + } + + /* + * Override standard mysqli_prepare to select master/slave server + * @param $string query + * + * @return mysqli_stmt + */ + public function prepare($query) + { + if (stripos($query, "SELECT") && stripos($query, "FOR UPDATE") === false && $this->mysqliR !== null) { + return $this->mysqliR->prepare($query); + } else { + return $this->mysqliW->prepare($query); + } + } + + /* + * Override standard mysqli_query to select master/slave server + * @param string $query + * @param int $resultmode + * + * @return boolean + * @return mixed + */ + public function query($query, $resultmode = MYSQLI_STORE_RESULT) + { + if (stripos($query, "SELECT") && stripos($query, "FOR UPDATE") === false && $this->mysqliR !== null) {/* Use readonly server */ + return $this->mysqliR->query($query, $resultmode); + } else { + return $this->mysqliW->query($query, $resultmode); + } + } +} \ No newline at end of file diff --git a/include/config/global.inc.dist.php b/include/config/global.inc.dist.php index af61b1f3..89ef4f7e 100644 --- a/include/config/global.inc.dist.php +++ b/include/config/global.inc.dist.php @@ -60,6 +60,18 @@ $config['db']['name'] = 'mpos'; // $config['db']['shared']['workers'] = $config['db']['name']; // $config['db']['shared']['news'] = $config['db']['name']; + +/** + * Setup read-only/slave database server for selects (read queries) +**/ +$config['db-ro']['enabled'] = false; +$config['db-ro']['host'] = 'localhost'; +$config['db-ro']['user'] = 'someuser'; +$config['db-ro']['pass'] = 'somepass'; +$config['db-ro']['port'] = 3306; +$config['db-ro']['name'] = 'mpos'; + + /** * Local wallet RPC * RPC configuration for your daemon/wallet diff --git a/include/database.inc.php b/include/database.inc.php index c8db0cca..fcb3bdc3 100644 --- a/include/database.inc.php +++ b/include/database.inc.php @@ -3,13 +3,14 @@ $defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1; // Instantiate class, we are using mysqlng if ($config['mysql_filter']) { - $mysqli = new mysqli_strict($config['db']['host'], $config['db']['user'], $config['db']['pass'], $config['db']['name'], $config['db']['port']); + $mysqli = new mysqlims($config['db'],$config['db-ro'], true); } else { - $mysqli = new mysqli($config['db']['host'], $config['db']['user'], $config['db']['pass'], $config['db']['name'], $config['db']['port']); + $mysqli = new mysqlims($config['db'],$config['db-ro'], false); } -// Check if read-only and quit if it is on -if ($mysqli->query('/* MYSQLND_MS_MASTER_SWITCH */SELECT @@global.read_only AS read_only')->fetch_object()->read_only == 1) { +// Check if read-only and quit if it is on, disregard if slave is enabled + +if ($mysqli->query('/* MYSQLND_MS_MASTER_SWITCH */SELECT @@global.read_only AS read_only')->fetch_object()->read_only == 1 && $config['db-ro']['enabled'] === false ) { die('Database is in READ-ONLY mode'); } From 42335635734b954d071c7adae8fee4a4e797f90a Mon Sep 17 00:00:00 2001 From: Tiago Peralta Date: Fri, 8 Dec 2017 23:11:19 +0000 Subject: [PATCH 4/4] Removed var_dump from debugging.... --- include/classes/mysqlims.class.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/include/classes/mysqlims.class.php b/include/classes/mysqlims.class.php index e78fb534..b4537610 100644 --- a/include/classes/mysqlims.class.php +++ b/include/classes/mysqlims.class.php @@ -18,8 +18,6 @@ class mysqlims extends mysqli */ public function __construct($main, $slave = false, $strict = false) { - var_dump($main); - var_dump($slave); if ($strict) { $this->mysqliW = new mysqli_strict($main['host'], $main['user'], $main['pass'],