Commit 8f810943 authored by yiwenshao's avatar yiwenshao

able to use new version of load and store with the strategy funciont for load in wrapper/reuse.cc

parent fc14f7df
...@@ -6,10 +6,6 @@ static std::map<std::string, WrapperState*> clients; ...@@ -6,10 +6,6 @@ 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;
//must be static, or we get "no previous declaration"
//execute the query and get the rawReturnVale, this struct can be copied.
static void init(){ static void init(){
std::string client="192.168.1.1:1234"; std::string client="192.168.1.1:1234";
//one Wrapper per user. //one Wrapper per user.
...@@ -66,8 +62,6 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> & ...@@ -66,8 +62,6 @@ static void write_meta(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> &
mf.serialize(); mf.serialize();
} }
static static
void write_raw_data_to_files(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> &res ,string db,string table){ void write_raw_data_to_files(rawMySQLReturnValue& resraw,std::vector<FieldMetaTrans> &res ,string db,string table){
//write metafiles //write metafiles
...@@ -80,16 +74,16 @@ static void store(std::string db, std::string table){ ...@@ -80,16 +74,16 @@ static void store(std::string db, std::string table){
std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(embeddedDir); std::unique_ptr<SchemaInfo> schema = myLoadSchemaInfo(embeddedDir);
//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);
//transform the field so that selected onions can be used //transform the field so that selected onions can be used
std::vector<FieldMetaTrans> res; std::vector<FieldMetaTrans> res;
for(auto i=0u;i<fms.size();i++){ for(auto i=0u;i<fms.size();i++){
FieldMetaTrans ft; FieldMetaTrans ft;
res.push_back(ft); res.push_back(ft);
res.back().trans(fms[i]); res.back().trans(fms[i]);
std::vector<int> in{0};
//this is our strategy !!!!!
res.back().choose(in);
} }
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);
rawMySQLReturnValue resraw = executeAndGetResultRemote(globalConn,backup_query); rawMySQLReturnValue resraw = executeAndGetResultRemote(globalConn,backup_query);
...@@ -97,17 +91,14 @@ static void store(std::string db, std::string table){ ...@@ -97,17 +91,14 @@ static void store(std::string db, std::string table){
//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.lengths; auto lengths = resraw.lengths;
int base_types = 0; int base_types = 0;
int base_lengths = 0; int base_lengths = 0;
for(auto &item:res){ for(auto &item:res){
vector<int> tempTypes; vector<int> tempTypes;
vector<int> tempLengths; vector<int> tempLengths;
for(unsigned int i=0u;i<item.getChoosenOnionName().size();i++){ for(unsigned int i=0u;i<item.getChoosenOnionName().size();i++){
tempTypes.push_back(types[base_types]); tempTypes.push_back(types[base_types++]);
tempLengths.push_back(lengths[base_lengths]); tempLengths.push_back(lengths[base_lengths++]);
base_types++;
base_lengths++;
} }
item.setChoosenFieldTypes(tempTypes); item.setChoosenFieldTypes(tempTypes);
item.setChoosenFieldLengths(tempLengths); item.setChoosenFieldLengths(tempLengths);
......
...@@ -380,3 +380,23 @@ write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std: ...@@ -380,3 +380,23 @@ write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std:
fclose(item); fclose(item);
} }
} }
STORE_STRATEGY currentStrategy = STORE_STRATEGY::FIRST;
/*storage used when we store*/
void storeStrategies(std::vector<FieldMetaTrans>& res){
if(currentStrategy == STORE_STRATEGY::FIRST){
std::vector<int> in{0};
for(auto &item:res){
item.choose(in);
}
}else if(currentStrategy == STORE_STRATEGY::ALL){
}else{
exit(0);
}
}
...@@ -146,4 +146,9 @@ executeAndGetResultRemote(Connect * curConn,std::string query); ...@@ -146,4 +146,9 @@ executeAndGetResultRemote(Connect * curConn,std::string query);
void void
write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std::string prefix="data/"); write_row_data(rawMySQLReturnValue& resraw,std::string db,std::string table,std::string prefix="data/");
void storeStrategies(std::vector<FieldMetaTrans>& res);
enum class STORE_STRATEGY{
FIRST,
ALL
};
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