Commit 4b849d18 authored by yiwenshao's avatar yiwenshao

able to process multiple table in tools/final_load&store,to be tested

parent cacaa34f
...@@ -15,13 +15,13 @@ work(unsigned long id, void *input){ ...@@ -15,13 +15,13 @@ work(unsigned long id, void *input){
if(task->stop == 1) return 1; if(task->stop == 1) return 1;
char * query = (char*)(task->arg1); char * query = (char*)(task->arg1);
(void)query; (void)query;
// printf("id=%lu %s\n",id,query);
return 0; return 0;
} }
int int
main(){ main(){
userFunction = work; userFunction = work;
//create threads, and each thread is waitting for the jobs, each thread has one queue.
bioInit(); bioInit();
std::vector<std::string> input{ std::vector<std::string> input{
"a", "a",
...@@ -37,14 +37,18 @@ main(){ ...@@ -37,14 +37,18 @@ main(){
}; };
int type = 0; int type = 0;
for(int i=0;i<10000;i++) { for(int i=0;i<10000;i++) {
//send to thread, whose number is type; arg1 is (input[i%10].c_str()) and arg2 is NULL
//the thread can extract the two arguments from JOB
bioCreateBackgroundJob(type,(input[i%10].c_str()),NULL,0); bioCreateBackgroundJob(type,(input[i%10].c_str()),NULL,0);
type+=1; type+=REDIS_BIO_NUM_OPS;
type%=10; type%=10;
} }
//Send 1 to stop the threads
for(int i=0;i<10;i++) { for(int i=0;i<10;i++) {
bioCreateBackgroundJob(type,NULL,NULL,1); bioCreateBackgroundJob(type,NULL,NULL,1);
type+=1; type+=1;
type%=10; type%=REDIS_BIO_NUM_OPS;
} }
printf("tobe joined\n"); printf("tobe joined\n");
bioKillThreads(); bioKillThreads();
......
...@@ -40,7 +40,7 @@ logToFile glog(logfileName); ...@@ -40,7 +40,7 @@ logToFile glog(logfileName);
//This connection mimics the behaviour of MySQL-Proxy //This connection mimics the behaviour of MySQL-Proxy
Connect *globalConn; Connect *globalConn;
fullBackUp gfb; fullBackUp *gfb;
struct batch{ struct batch{
vector<string> field_names; vector<string> field_names;
...@@ -48,7 +48,20 @@ struct batch{ ...@@ -48,7 +48,20 @@ struct batch{
vector<int> field_lengths; vector<int> field_lengths;
}; };
batch ggbt; batch *ggbt;
static
std::vector<std::string>
getDbTables(std::string db) {
executeAndGetColumnData(globalConn,std::string("use ")+db);
MySQLColumnData resraw = executeAndGetColumnData(globalConn,"show tables");
return resraw.columnData[0];
}
/*should choose the right decryption onion*/ /*should choose the right decryption onion*/
static static
...@@ -78,14 +91,14 @@ std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, ...@@ -78,14 +91,14 @@ std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms,
if(use_salt) if(use_salt)
addSaltToReturn(myReturnMeta.get(),pos++); addSaltToReturn(myReturnMeta.get(),pos++);
//used to record choosen field lengths, onion names , and field types //used to record choosen field lengths, onion names , and field types
ggbt.field_types.push_back(tfds[i].getChoosenFieldTypes()[index]); ggbt->field_types.push_back(tfds[i].getChoosenFieldTypes()[index]);
ggbt.field_names.push_back(tfds[i].getChoosenOnionName()[index]); ggbt->field_names.push_back(tfds[i].getChoosenOnionName()[index]);
ggbt.field_lengths.push_back(tfds[i].getChoosenFieldLengths()[index]); ggbt->field_lengths.push_back(tfds[i].getChoosenFieldLengths()[index]);
if(use_salt){ if(use_salt){
ggbt.field_types.push_back(tfds[i].getSaltType()); ggbt->field_types.push_back(tfds[i].getSaltType());
ggbt.field_names.push_back(tfds[i].getSaltName()); ggbt->field_names.push_back(tfds[i].getSaltName());
ggbt.field_lengths.push_back(tfds[i].getSaltLength()); ggbt->field_lengths.push_back(tfds[i].getSaltLength());
} }
} }
return myReturnMeta; return myReturnMeta;
...@@ -97,7 +110,7 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){ ...@@ -97,7 +110,7 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){
vector<string> field_names; vector<string> field_names;
vector<int> field_types; vector<int> field_types;
vector<int> field_lengths; vector<int> field_lengths;
/*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){
...@@ -125,33 +138,32 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){ ...@@ -125,33 +138,32 @@ void initGfb(std::vector<FieldMetaTrans> &res,std::string db,std::string table){
} }
} }
gfb.field_names = field_names; gfb->field_names = field_names;
gfb.field_types = field_types; gfb->field_types = field_types;
gfb.field_lengths = field_lengths; gfb->field_lengths = field_lengths;
//then we should read the vector //then we should read the vector
std::string prefix = std::string("data/")+db+"/"+table+"/"; std::string prefix = std::string("data/")+db+"/"+table+"/";
for(unsigned int i=0u; i<gfb.field_names.size(); i++) { for(unsigned int i=0u; i<gfb->field_names.size(); i++) {
std::string filename = prefix + gfb.field_names[i]; std::string filename = prefix + gfb->field_names[i];
std::vector<std::string> column; std::vector<std::string> column;
if(IS_NUM(gfb.field_types[i])){ if(IS_NUM(gfb->field_types[i])){
loadFileNoEscapeLimitCount(filename,column,constGlobalConstants.loadCount); loadFileNoEscapeLimitCount(filename,column,constGlobalConstants.loadCount);
}else{ }else{
loadFileEscapeLimitCount(filename,column,gfb.field_lengths[i],constGlobalConstants.loadCount); loadFileEscapeLimitCount(filename,column,gfb->field_lengths[i],constGlobalConstants.loadCount);
} }
std::reverse(column.begin(),column.end()); std::reverse(column.begin(),column.end());
gfb.annoOnionNameToFileVector[gfb.field_names[i]] = std::move(column); gfb->annoOnionNameToFileVector[gfb->field_names[i]] = std::move(column);
} }
//init another map //init another map
for(unsigned int i=0;i<gfb.field_names.size();i++){ for(unsigned int i=0;i<gfb->field_names.size();i++){
gfb.annoOnionNameToType[gfb.field_names[i]] = gfb.field_types[i]; gfb->annoOnionNameToType[gfb->field_names[i]] = gfb->field_types[i];
} }
} }
/*load file, decrypt, and then return data plain fields in the type ResType*/ /*load file, decrypt, and then return data plain fields in the type ResType*/
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(gembeddedDir); 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);
...@@ -176,22 +188,28 @@ static ResType load_files(std::string db, std::string table){ ...@@ -176,22 +188,28 @@ static ResType load_files(std::string db, std::string table){
std::to_string(t_load_files.lap()/1000000u)<< std::to_string(t_load_files.lap()/1000000u)<<
"##"<<std::to_string(time(NULL))<<"\n"; "##"<<std::to_string(time(NULL))<<"\n";
vector<string> field_names = ggbt.field_names; vector<string> field_names = ggbt->field_names;
vector<int> field_types = ggbt.field_types; vector<int> field_types = ggbt->field_types;
vector<int> field_lengths = ggbt.field_lengths; vector<int> field_lengths = ggbt->field_lengths;
//why do we need this?? //why do we need this??
create_embedded_thd(0); create_embedded_thd(0);
rawMySQLReturnValue resraw; rawMySQLReturnValue resraw;
vector<vector<string>> res_field; vector<vector<string>> res_field;
for(auto item:field_names){ for(auto item:field_names){
res_field.push_back(gfb.annoOnionNameToFileVector[item]); res_field.push_back(gfb->annoOnionNameToFileVector[item]);
}
//check here
for(auto item:res_field){
if(item.size()==0) {
return ResType(false, 0, 0);
}
} }
//then transform it to ress_fields //then transform it to ress_fields
unsigned int length = res_field[0].size(); unsigned int length = res_field[0].size();
vector<vector<string>> ress_field; vector<vector<string>> ress_field;
for(unsigned int i=0u;i<length;i++){ for(unsigned int i=0u;i<length;i++) {
vector<string> row; vector<string> row;
for(unsigned int j=0u;j<res_field.size();j++){ for(unsigned int j=0u;j<res_field.size();j++){
row.push_back(res_field[j][i]); row.push_back(res_field[j][i]);
...@@ -236,9 +254,9 @@ void local_wrapper(const Item &i, const FieldMeta &fm, Analysis &a, ...@@ -236,9 +254,9 @@ void local_wrapper(const Item &i, const FieldMeta &fm, Analysis &a,
const onion o = it.first->getValue(); const onion o = it.first->getValue();
OnionMeta * const om = it.second; OnionMeta * const om = it.second;
std::string annoOnionName = om->getAnonOnionName(); std::string annoOnionName = om->getAnonOnionName();
if(gfb.annoOnionNameToFileVector.find(annoOnionName)!=gfb.annoOnionNameToFileVector.end()){ if(gfb->annoOnionNameToFileVector.find(annoOnionName)!=gfb->annoOnionNameToFileVector.end()){
enum_field_types type = static_cast<enum_field_types>(gfb.annoOnionNameToType[annoOnionName]); enum_field_types type = static_cast<enum_field_types>(gfb->annoOnionNameToType[annoOnionName]);
std::vector<std::string> &tempFileVector = gfb.annoOnionNameToFileVector[annoOnionName]; std::vector<std::string> &tempFileVector = gfb->annoOnionNameToFileVector[annoOnionName];
std::string in = tempFileVector.back(); std::string in = tempFileVector.back();
if(IS_NUM(type)){ if(IS_NUM(type)){
unsigned int len = annoOnionName.size(); unsigned int len = annoOnionName.size();
...@@ -259,8 +277,8 @@ void local_wrapper(const Item &i, const FieldMeta &fm, Analysis &a, ...@@ -259,8 +277,8 @@ void local_wrapper(const Item &i, const FieldMeta &fm, Analysis &a,
} }
std::string saltName = fm.getSaltName(); std::string saltName = fm.getSaltName();
if (fm.getHasSalt()) { if (fm.getHasSalt()) {
if(gfb.annoOnionNameToFileVector.find(saltName)!=gfb.annoOnionNameToFileVector.end()){ if(gfb->annoOnionNameToFileVector.find(saltName)!=gfb->annoOnionNameToFileVector.end()){
std::vector<std::string> &tempFileVector = gfb.annoOnionNameToFileVector[saltName]; std::vector<std::string> &tempFileVector = gfb->annoOnionNameToFileVector[saltName];
std::string in = tempFileVector.back(); std::string in = tempFileVector.back();
l.push_back( new (current_thd->mem_root) l.push_back( new (current_thd->mem_root)
Item_int(static_cast<ulonglong>(valFromStr(in))) Item_int(static_cast<ulonglong>(valFromStr(in)))
...@@ -296,14 +314,10 @@ List<Item> * processRow(const std::vector<Item *> &row, ...@@ -296,14 +314,10 @@ 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;
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";
std::string db="tdb",table="-1";
std::string db="tdb",table="student";
std::string ip="localhost"; std::string ip="localhost";
if(argc==4){ if(argc==4){
ip = std::string(argv[1]); ip = std::string(argv[1]);
...@@ -323,17 +337,35 @@ main(int argc, char* argv[]){ ...@@ -323,17 +337,35 @@ main(int argc, char* argv[]){
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";
std::vector<std::string> tables;
if(table==std::string("-1")){
tables = getDbTables(db);
std::map<std::string,int> annIndex;
for(unsigned int i=0u;i<tables.size();++i) {
annIndex[tables[i]]=i;
}
const DatabaseMeta & dbm = analysis.getDatabaseMeta(db);
auto &tableMetas = dbm.getChildren();
for(auto & kvtable:tableMetas){
auto annoname = kvtable.second->getAnonTableName();
auto plainname = kvtable.first.getValue();
tables[annIndex[annoname]]=plainname;
}
}else{
tables.push_back(table);
}
for(auto &table:tables) {
gfb = new fullBackUp;
ggbt = new batch;
glog<<"====================start table: "<<table<<"============================"<<"\n";
/*choose decryption onion, load and decrypt to plain text*/ /*choose decryption onion, load and decrypt to plain text*/
ResType res = load_files(db,table); ResType res = load_files(db,table);
if(res.success()) {
glog<<"load_files: "<< glog<<"load_files: "<<
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";
std::string annoTableName = analysis.getTableMeta(db,table).getAnonTableName(); std::string annoTableName = analysis.getTableMeta(db,table).getAnonTableName();
const std::string head = std::string("INSERT INTO `")+db+"`.`"+annoTableName+"` "; const std::string head = std::string("INSERT INTO `")+db+"`.`"+annoTableName+"` ";
/*reencryption to get the encrypted insert!!!*/ /*reencryption to get the encrypted insert!!!*/
unsigned int i=0u; unsigned int i=0u;
while(true){ while(true){
...@@ -362,16 +394,19 @@ main(int argc, char* argv[]){ ...@@ -362,16 +394,19 @@ main(int argc, char* argv[]){
break; break;
} }
} }
glog<<"reencryptionAndInsert: "<< glog<<"reencryptionAndInsert: "<<
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";
for(auto item:gcountMap) { for(auto item:gcountMap) {
glog<<"onionComputed: "<< glog<<"onionComputed: "<<
TypeText<onion>::toText(item.first)<<"::"<< TypeText<onion>::toText(item.first)<<"::"<<
std::to_string(item.second)<<"\n"; std::to_string(item.second)<<"\n";
} }
}
glog<<"====================finish table: "<<table<<"============================"<<"\n";
gcountMap.clear();
delete gfb;
delete ggbt;
}
return 0; return 0;
} }
...@@ -72,12 +72,22 @@ struct FieldMeta_Wrapper{ ...@@ -72,12 +72,22 @@ struct FieldMeta_Wrapper{
/*Transformed version of FieldMeta*/ /*Transformed version of FieldMeta*/
class FieldMetaTrans{ class FieldMetaTrans{
public://??
enum class FILEFORMAT{
ESP_STRING,
NUM_STRING,
NUM_BINARY
};
private:
FieldMeta *originalFm; FieldMeta *originalFm;
bool hasSalt; bool hasSalt;
std::string saltName; std::string saltName;
int saltType; int saltType;
int saltLength; int saltLength;
FILEFORMAT fieldStoreFormat;
std::vector<OnionMeta*> onionsOm; std::vector<OnionMeta*> onionsOm;
std::vector<onion> onionsO; std::vector<onion> onionsO;
std::vector<std::string> onionsName; std::vector<std::string> onionsName;
...@@ -89,6 +99,8 @@ class FieldMetaTrans{ ...@@ -89,6 +99,8 @@ class FieldMetaTrans{
std::vector<int> choosenFieldTypes; std::vector<int> choosenFieldTypes;
std::vector<int> choosenFieldLengths; std::vector<int> choosenFieldLengths;
public: public:
FILEFORMAT getFeidlStoreFormat(){return fieldStoreFormat;}
bool setFieldStoreFormat(FILEFORMAT f){fieldStoreFormat = f;return true;}
FieldMeta *getOriginalFieldMeta(){return originalFm;} FieldMeta *getOriginalFieldMeta(){return originalFm;}
void showChoosenOnionO(){std::cout<<"for field "<<originalFm->getFieldName()<<std::endl; void showChoosenOnionO(){std::cout<<"for field "<<originalFm->getFieldName()<<std::endl;
for(auto item:choosenOnionO){ for(auto item:choosenOnionO){
......
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