1 |
38716
|
eri.katsar
|
<?php
|
2 |
|
|
require_once('./js/log4php/Logger.php');
|
3 |
|
|
require_once('./paths.php');
|
4 |
|
|
require_once('./MYDB.php');
|
5 |
|
|
|
6 |
|
|
class MigrateCache {
|
7 |
|
|
private $log;
|
8 |
|
|
private $db;
|
9 |
|
|
private $cache = null; //predis
|
10 |
|
|
|
11 |
|
|
private $remotecache=null;
|
12 |
|
|
private $redis_host='beta.stats.openaire.eu';
|
13 |
|
|
private $redis_remote_host='localhost';
|
14 |
|
|
|
15 |
|
|
public function __construct(){
|
16 |
|
|
|
17 |
|
|
// $redis_host='beta.stats.openaire.eu';
|
18 |
|
|
global $redis_port;
|
19 |
|
|
global $redis_scheme;
|
20 |
|
|
global $host;
|
21 |
|
|
global $db_name;
|
22 |
|
|
|
23 |
|
|
|
24 |
|
|
//$redis_host='localhost';
|
25 |
|
|
/*$redis_remote_host='duffy.di.uoa.gr';
|
26 |
|
|
|
27 |
|
|
$redis_remote_port=$redis_port;
|
28 |
|
|
$redis_remote_scheme=$redis_scheme;
|
29 |
|
|
*/
|
30 |
|
|
|
31 |
|
|
$this->log = Logger::getLogger("__CLASS__");
|
32 |
|
|
Logger::configure('./js/log4php/log4php.xml');
|
33 |
|
|
|
34 |
|
|
if(class_exists("Predis\Client")){
|
35 |
|
|
|
36 |
|
|
try {
|
37 |
|
|
//todo changed timeout from 0 to -1
|
38 |
|
|
$this->cache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $this->redis_host,"port" => $redis_port,"read_write_timeout" => -1));
|
39 |
|
|
$this->log->info("redis host: ".$this->redis_host." and redis port: ".$redis_port);
|
40 |
|
|
} catch(Exception $e) {
|
41 |
|
|
$this->log->error("Error connecting to Redis server: ".$e->getMessage());
|
42 |
|
|
$this->cache = null;
|
43 |
|
|
}
|
44 |
|
|
}
|
45 |
|
|
else{
|
46 |
|
|
$this->log->info("cache does not exist"); //predis
|
47 |
|
|
exit;
|
48 |
|
|
}
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
}
|
52 |
|
|
public function migrate(){
|
53 |
|
|
|
54 |
|
|
global $redis_port;
|
55 |
|
|
global $redis_scheme;
|
56 |
|
|
global $host;
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
$backupKeys=$this->cache->hkeys('STATS_NUMBERS');
|
60 |
|
|
$this->log->info("migrating Stat Numbers from ".$this->redis_host." to ".$this->redis_remote_host." on ".$redis_port);
|
61 |
|
|
|
62 |
|
|
try {
|
63 |
|
|
|
64 |
|
|
//todo changed timeout from 0 to -1
|
65 |
|
|
$this->remotecache = new Predis\Client(array("scheme" => $redis_scheme,"host" => $this->redis_remote_host,"port" => $redis_port,"read_write_timeout" => -1));
|
66 |
|
|
$this->log->info("redis host: ".$this->redis_remote_host." and redis port: ".$redis_port);
|
67 |
|
|
} catch(Exception $e) {
|
68 |
|
|
$this->log->error("Error connecting to Redis server: ".$e->getMessage());
|
69 |
|
|
$this->cache = null;
|
70 |
|
|
}
|
71 |
|
|
$this->remotecache->connect();
|
72 |
|
|
|
73 |
|
|
for($x=0;$x<count($backupKeys);$x++)
|
74 |
|
|
{
|
75 |
|
|
$key=$backupKeys[$x];
|
76 |
|
|
$value=$this->cache->hget('STATS_NUMBERS',$key);
|
77 |
|
|
$this->log->info("saving : ".$key." : ".$value);
|
78 |
|
|
$this->remotecache->hmset('STATS_NUMBERS',$key,$value);
|
79 |
|
|
$this->log->info("query saved : ".$this->remotecache->hget('STATS_NUMBERS',$key));}
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
$this->log->info("Migrating data queries...");
|
84 |
|
|
$this->log->info("*******************************************");
|
85 |
|
|
|
86 |
|
|
$keys = $this->cache->keys("*");
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
for($x=0;$x<count($keys);$x++) {
|
90 |
|
|
|
91 |
|
|
if (strpos($keys[$x],'STATS')===false)
|
92 |
|
|
{
|
93 |
|
|
|
94 |
|
|
try
|
95 |
|
|
{
|
96 |
|
|
|
97 |
|
|
$values=$this->cache->hgetall($keys[$x]);
|
98 |
|
|
|
99 |
|
|
{
|
100 |
|
|
|
101 |
|
|
$this->log->info("Moving...");
|
102 |
|
|
|
103 |
|
|
$this->remotecache->hmset($keys[$x],$values);
|
104 |
|
|
|
105 |
|
|
$this->log->info("id : ".$keys[$x]);}
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
}
|
109 |
|
|
catch(Exception $e) {
|
110 |
|
|
|
111 |
|
|
$this->log->error('Error : '.$e->getMessage());
|
112 |
|
|
}
|
113 |
|
|
}
|
114 |
|
|
else
|
115 |
|
|
{ $this->log->info("Ignoring chart key: ".$keys[$x]); }
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
}
|
119 |
|
|
|
120 |
|
|
|
121 |
|
|
|
122 |
|
|
|
123 |
|
|
$this->remotecache->quit();
|
124 |
|
|
$this->cache->quit();
|
125 |
|
|
|
126 |
|
|
$this->log->info("Done migtating ! ");
|
127 |
|
|
|
128 |
|
|
}
|
129 |
|
|
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
$rc = new MigrateCache();
|
133 |
|
|
$rc->migrate();
|
134 |
|
|
?>
|