RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* redis_migration.cc 00002 Wolfgang Sourdeau, 17 December 2012 00003 Copyright (c) 2012 Datacratic. All rights reserved. 00004 00005 Redis migration script from campaign:strategy schema to the new accounts 00006 schema 00007 */ 00008 00009 #include <iostream> 00010 00011 #include <boost/program_options/options_description.hpp> 00012 #include <boost/program_options/parsers.hpp> 00013 #include <boost/program_options/variables_map.hpp> 00014 00015 #include "soa/service/redis.h" 00016 00017 #include "redis_migration.h" 00018 #include "redis_rollback.h" 00019 00020 00021 using namespace std; 00022 using namespace boost::program_options; 00023 00024 00025 int main(int argc, char *argv[]) 00026 { 00027 string sourceHost("localhost"), targetHost(""); 00028 int sourcePort(6379), targetPort(0), delta(0); 00029 00030 options_description migration_options("Redis options"); 00031 migration_options.add_options() 00032 ("redis-host,h", value<string>(&sourceHost), 00033 "source Redis host") 00034 ("redis-port,p", value<int>(&sourcePort), 00035 "source Redis port") 00036 ("delta,d", value<int>(&delta), 00037 "acceptable inconsistency delta between 'budget'," 00038 " 'transfer' and 'available', in µUSD (0)") 00039 ("redis-target-host,i", value<string>(&targetHost), 00040 "target Redis host (optional)") 00041 ("redis-target-port,q", value<int>(&targetPort), 00042 "target Redis port (optional)"); 00043 options_description all_opt("redis_migrate"); 00044 all_opt.add(migration_options); 00045 all_opt.add_options() 00046 ("rollback,R", "rollback from the new schema to the old one") 00047 ("help,H", "print this message"); 00048 00049 variables_map vm; 00050 store(command_line_parser(argc, argv) 00051 .options(all_opt) 00052 //.positional(p) 00053 .run(), 00054 vm); 00055 notify(vm); 00056 00057 if (vm.count("help")) { 00058 cerr << all_opt << endl; 00059 return 1; 00060 } 00061 00062 bool rollback(vm.count("rollback") != 0); 00063 00064 Redis::Address sourceAddress = Redis::Address::tcp(sourceHost, sourcePort); 00065 if (targetHost == "") { 00066 targetHost = sourceHost; 00067 } 00068 if (targetPort == 0) { 00069 targetPort = sourcePort; 00070 } 00071 00072 cerr << sourceHost << ":" << sourcePort << endl; 00073 cerr << targetHost << ":" << targetPort << endl; 00074 Redis::Address targetAddress = Redis::Address::tcp(targetHost, targetPort); 00075 00076 if (rollback) { 00077 RTBKIT::RedisRollback rollback; 00078 rollback.perform(sourceAddress, targetAddress); 00079 } 00080 else { 00081 RTBKIT::RedisMigration migration; 00082 migration.perform(sourceAddress, delta, targetAddress); 00083 } 00084 00085 return 0; 00086 }