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;
using std::vector;
using std::string;
using std::to_string;
static std::string embeddedDir="/t/cryt/shadow";
char * globalEsp=NULL;
int num_of_pipe = 4;
//global map, for each client, we have one WrapperState which contains ProxyState.
static std::map<std::string, WrapperState*> clients;
static
std::string logfilePrefix = "final_load";
......@@ -42,32 +39,6 @@ logToFile glog(logfileName);
//This connection mimics the behaviour of MySQL-Proxy
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;
......@@ -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
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 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.
for(auto i=0u;i<item.getChoosenOnionName().size();i++){
onion o = item.getChoosenOnionO()[i];
......@@ -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){
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.
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
TableMetaTrans res_meta = loadTableMetaTrans(db,table);
......@@ -337,13 +296,13 @@ List<Item> * processRow(const std::vector<Item *> &row,
int
main(int argc, char* argv[]){
timer t_init;
init();
glog<<"init: "<<
std::to_string(t_init.lap()/1000000u)<<
"##"<<std::to_string(time(NULL))<<"\n";
create_embedded_thd(0);
std::string db="tdb",table="student";
std::string ip="localhost";
if(argc==4){
......@@ -351,7 +310,11 @@ main(int argc, char* argv[]){
db = std::string(argv[2]);
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();
const std::unique_ptr<AES_KEY> &TK = std::unique_ptr<AES_KEY>(getKey(std::string("113341234")));
Analysis analysis(db, *schema, TK, SECURITY_RATING::SENSITIVE);
......
#include "wrapper/common.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
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
static
std::string getTestQuery(SchemaInfo &schema, std::vector<FieldMetaTrans> &tfds,
......@@ -86,7 +59,7 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans>
}
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
std::vector<FieldMeta*> fms = getFieldMeta(*schema,db,table);
......@@ -97,15 +70,11 @@ static void store(std::string db, std::string table){
res.push_back(ft);
res.back().trans(fms[i]);
}
/*this is our strategy, each field should be able to choose the selected onion*/
storeStrategies(res);
//generate the backup query and then fetch the tuples
std::string backup_query = getTestQuery(*schema,res,db,table);
MySQLColumnData resraw = executeAndGetColumnData(globalConn,backup_query);
//then we should set the type and length of FieldMetaTrans
auto types = resraw.fieldTypes;
auto lengths = resraw.maxLengths;
......@@ -125,7 +94,6 @@ static void store(std::string db, std::string table){
item.setSaltLength(lengths[base_lengths++]);
}
}
//write the tuples into files
write_raw_data_to_files(resraw,res,db,table);
}
......@@ -140,7 +108,7 @@ main(int argc, char* argv[]){
db = std::string(argv[2]);
table = std::string(argv[3]);
}
init(ip,port);
globalConn = globalInit(ip,port);
store(db,table);
return 0;
}
......@@ -5,6 +5,36 @@
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){
s+=":";
for(auto item:vec_int){
......
......@@ -16,7 +16,11 @@ using std::vector;
using std::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{
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