Commit d8521abb authored by yiwenshao's avatar yiwenshao

in tools, modify final_load and final_store to use common init

parent 5ad1ab26
...@@ -24,12 +24,9 @@ using std::endl; ...@@ -24,12 +24,9 @@ using std::endl;
using std::vector; using std::vector;
using std::string; using std::string;
using std::to_string; using std::to_string;
static std::string embeddedDir="/t/cryt/shadow";
char * globalEsp=NULL; char * globalEsp=NULL;
int num_of_pipe = 4; int num_of_pipe = 4;
//global map, for each client, we have one WrapperState which contains ProxyState. //global map, for each client, we have one WrapperState which contains ProxyState.
static std::map<std::string, WrapperState*> clients;
static static
std::string logfilePrefix = "final_load"; std::string logfilePrefix = "final_load";
...@@ -42,32 +39,6 @@ logToFile glog(logfileName); ...@@ -42,32 +39,6 @@ logToFile glog(logfileName);
//This connection mimics the behaviour of MySQL-Proxy //This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn; Connect *globalConn;
/*for each field, convert the format to FieldMeta_Wrapper*/
static void init(){
std::string client="192.168.1.1:1234";
//one Wrapper per user.
clients[client] = new WrapperState();
//Connect phase
ConnectionInfo ci("localhost", "root", "letmein",3306);
const std::string master_key = "113341234";
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
embeddedDir = std::string(buffer)+"/shadow";
SharedProxyState *shared_ps =
new SharedProxyState(ci, embeddedDir , master_key,
determineSecurityRating());
assert(0 == mysql_thread_init());
//we init embedded database here.
clients[client]->ps = std::unique_ptr<ProxyState>(new ProxyState(*shared_ps));
clients[client]->ps->safeCreateEmbeddedTHD();
//Connect end!!
globalConn = new Connect(ci.server, ci.user, ci.passwd, ci.port);
}
//========================================================================================//
fullBackUp gfb; fullBackUp gfb;
...@@ -129,19 +100,7 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){ ...@@ -129,19 +100,7 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){
/*choosen onions should all be included in gfb. salt is also included /*choosen onions should all be included in gfb. salt is also included
it's hard to decide whether a FieldMetaTrans has salt because the senmantic is different from that of FieldMeta. it's hard to decide whether a FieldMetaTrans has salt because the senmantic is different from that of FieldMeta.
*/ */
for(auto &item:res){ for(auto &item:res){
/* for(auto i:item.getChoosenOnionName()){
field_names.push_back(i);
}
for(auto i:item.getChoosenFieldTypes()){
field_types.push_back(i);
}
for(auto i:item.getChoosenFieldLengths()){
field_lengths.push_back(i);
}
*/
//only choose onions that are used. //only choose onions that are used.
for(auto i=0u;i<item.getChoosenOnionName().size();i++){ for(auto i=0u;i<item.getChoosenOnionName().size();i++){
onion o = item.getChoosenOnionO()[i]; onion o = item.getChoosenOnionO()[i];
...@@ -193,7 +152,7 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){ ...@@ -193,7 +152,7 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){
static ResType load_files(std::string db, std::string table){ static ResType load_files(std::string db, std::string table){
timer t_load_files; timer t_load_files;
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(embeddedDir); std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(gembeddedDir);
//get all the fields in the tables. //get all the fields in the tables.
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table); std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
TableMetaTrans res_meta = loadTableMetaTrans(db,table); TableMetaTrans res_meta = loadTableMetaTrans(db,table);
...@@ -337,13 +296,13 @@ List<Item> * processRow(const std::vector<Item *> &row, ...@@ -337,13 +296,13 @@ List<Item> * processRow(const std::vector<Item *> &row,
int int
main(int argc, char* argv[]){ main(int argc, char* argv[]){
timer t_init; timer t_init;
init();
glog<<"init: "<< glog<<"init: "<<
std::to_string(t_init.lap()/1000000u)<< std::to_string(t_init.lap()/1000000u)<<
"##"<<std::to_string(time(NULL))<<"\n"; "##"<<std::to_string(time(NULL))<<"\n";
create_embedded_thd(0);
std::string db="tdb",table="student"; std::string db="tdb",table="student";
std::string ip="localhost"; std::string ip="localhost";
if(argc==4){ if(argc==4){
...@@ -351,7 +310,11 @@ main(int argc, char* argv[]){ ...@@ -351,7 +310,11 @@ main(int argc, char* argv[]){
db = std::string(argv[2]); db = std::string(argv[2]);
table = std::string(argv[3]); table = std::string(argv[3]);
} }
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(embeddedDir);
globalConn = globalInit(ip,3306);
create_embedded_thd(0);
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(gembeddedDir);
schema.get(); schema.get();
const std::unique_ptr<AES_KEY> &TK = std::unique_ptr<AES_KEY>(getKey(std::string("113341234"))); const std::unique_ptr<AES_KEY> &TK = std::unique_ptr<AES_KEY>(getKey(std::string("113341234")));
Analysis analysis(db, *schema, TK, SECURITY_RATING::SENSITIVE); Analysis analysis(db, *schema, TK, SECURITY_RATING::SENSITIVE);
......
#include "wrapper/common.hh" #include "wrapper/common.hh"
#include "wrapper/reuse.hh" #include "wrapper/reuse.hh"
static std::string embeddedDir="/t/cryt/shadow";
//global map, for each client, we have one WrapperState which contains ProxyState.
static std::map<std::string, WrapperState*> clients;
//This connection mimics the behaviour of MySQL-Proxy //This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn; Connect *globalConn;
static void init(std::string ip,int port){
std::string client="192.168.1.1:1234";
//one Wrapper per user.
clients[client] = new WrapperState();
//Connect phase
ConnectionInfo ci("localhost", "root", "letmein",port);
const std::string master_key = "113341234";
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
embeddedDir = std::string(buffer)+"/shadow";
SharedProxyState *shared_ps =
new SharedProxyState(ci, embeddedDir , master_key,
determineSecurityRating());
assert(0 == mysql_thread_init());
//we init embedded database here.
clients[client]->ps = std::unique_ptr<ProxyState>(new ProxyState(*shared_ps));
clients[client]->ps->safeCreateEmbeddedTHD();
//Connect end!!
globalConn = new Connect(ip, ci.user, ci.passwd, port);
}
//query for testing purposes //query for testing purposes
static static
std::string getTestQuery(SchemaInfo &schema, std::vector<FieldMetaTrans> &tfds, std::string getTestQuery(SchemaInfo &schema, std::vector<FieldMetaTrans> &tfds,
...@@ -86,7 +59,7 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans> ...@@ -86,7 +59,7 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans>
} }
static void store(std::string db, std::string table){ static void store(std::string db, std::string table){
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(embeddedDir); std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(gembeddedDir);
//get all the fields in the tables //get all the fields in the tables
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table); std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
...@@ -97,15 +70,11 @@ static void store(std::string db, std::string table){ ...@@ -97,15 +70,11 @@ static void store(std::string db, std::string table){
res.push_back(ft); res.push_back(ft);
res.back().trans(fms[i]); res.back().trans(fms[i]);
} }
/*this is our strategy, each field should be able to choose the selected onion*/ /*this is our strategy, each field should be able to choose the selected onion*/
storeStrategies(res); storeStrategies(res);
//generate the backup query and then fetch the tuples //generate the backup query and then fetch the tuples
std::string backup_query = getTestQuery(*schema,res,db,table); std::string backup_query = getTestQuery(*schema,res,db,table);
MySQLColumnData resraw = executeAndGetColumnData(globalConn,backup_query); MySQLColumnData resraw = executeAndGetColumnData(globalConn,backup_query);
//then we should set the type and length of FieldMetaTrans //then we should set the type and length of FieldMetaTrans
auto types = resraw.fieldTypes; auto types = resraw.fieldTypes;
auto lengths = resraw.maxLengths; auto lengths = resraw.maxLengths;
...@@ -125,7 +94,6 @@ static void store(std::string db, std::string table){ ...@@ -125,7 +94,6 @@ static void store(std::string db, std::string table){
item.setSaltLength(lengths[base_lengths++]); item.setSaltLength(lengths[base_lengths++]);
} }
} }
//write the tuples into files //write the tuples into files
write_raw_data_to_files(resraw,res,db,table); write_raw_data_to_files(resraw,res,db,table);
} }
...@@ -140,7 +108,7 @@ main(int argc, char* argv[]){ ...@@ -140,7 +108,7 @@ main(int argc, char* argv[]){
db = std::string(argv[2]); db = std::string(argv[2]);
table = std::string(argv[3]); table = std::string(argv[3]);
} }
init(ip,port); globalConn = globalInit(ip,port);
store(db,table); store(db,table);
return 0; return 0;
} }
...@@ -5,6 +5,36 @@ ...@@ -5,6 +5,36 @@
using std::ifstream; using std::ifstream;
//used to init global and embedded db
std::map<std::string, WrapperState*> gclients;
std::string gembeddedDir;
Connect * globalInit(std::string ip,int port) {
std::string client="192.168.1.1:1234";
//one Wrapper per user.
gclients[client] = new WrapperState();
//Connect phase
ConnectionInfo ci(ip, "root", "letmein",port);
const std::string master_key = "113341234";
char *buffer;
if((buffer = getcwd(NULL, 0)) == NULL){
perror("getcwd error");
}
gembeddedDir = std::string(buffer)+"/shadow";
SharedProxyState *shared_ps =
new SharedProxyState(ci, gembeddedDir , master_key,
determineSecurityRating());
assert(0 == mysql_thread_init());
//we init embedded database here.
gclients[client]->ps = std::unique_ptr<ProxyState>(new ProxyState(*shared_ps));
gclients[client]->ps->safeCreateEmbeddedTHD();
//Connect end!!
return new Connect(ip, ci.user, ci.passwd, port);
}
string metadata_files::serialize_vec_int(string s,vector<int> vec_int){ string metadata_files::serialize_vec_int(string s,vector<int> vec_int){
s+=":"; s+=":";
for(auto item:vec_int){ for(auto item:vec_int){
......
...@@ -16,7 +16,11 @@ using std::vector; ...@@ -16,7 +16,11 @@ using std::vector;
using std::string; using std::string;
using std::to_string; using std::to_string;
//used to init global and embedded db
extern std::map<std::string, WrapperState*> gclients;
Connect *
globalInit(std::string ip,int port);
extern std::string gembeddedDir;
class metadata_files{ class metadata_files{
public: public:
......
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