Commit 0fa3f2a9 authored by yiwenshao's avatar yiwenshao

add more global constants

parent 1f128066
...@@ -6,4 +6,8 @@ useOPE:false ...@@ -6,4 +6,8 @@ useOPE:false
useSWP:true useSWP:true
useDET:true useDET:true
useSalt:true useSalt:true
#NA,MIN,MIDEAN,FULL
BS_STR:MIN
BS_IA:MIN
BS_IH:MIN
other:1 other:1
...@@ -85,6 +85,15 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans> ...@@ -85,6 +85,15 @@ void write_raw_data_to_files(MySQLColumnData& resraw,std::vector<FieldMetaTrans>
} }
} }
} }
static void
write_meta_new(std::vector<FieldMetaTrans> &res,string db,string table){
std::string filename = std::string("data/") +db+"/"+table+"/metadata.data";
TableMetaTrans mf(db,table,res);
mf.set_db_table(db,table);
mf.serializeNew(filename);
}
static static
std::string std::string
getSelectField(SchemaInfo &schema, FieldMetaTrans &tf,std::string db,std::string table){ getSelectField(SchemaInfo &schema, FieldMetaTrans &tf,std::string db,std::string table){
...@@ -161,11 +170,10 @@ static void store(std::string db, std::string table){ ...@@ -161,11 +170,10 @@ static void store(std::string db, std::string table){
tf.setSaltLength(slength); tf.setSaltLength(slength);
write_field_data_to_files(resraw,tf,db,table,tf.getOriginalFieldMeta()->getFieldName()); write_field_data_to_files(resraw,tf,db,table,tf.getOriginalFieldMeta()->getFieldName());
} }
write_meta_new(res,db,table);
//generate the backup query and then fetch the tuples //generate the backup query and then fetch the tuples
(void)getSelectQuery; (void)getSelectQuery;
(void)getSelectField; (void)getSelectField;
/* /*
write_raw_data_to_files(resraw,res,db,table); write_raw_data_to_files(resraw,res,db,table);
*/ */
......
#include "util/constants.hh" #include "util/constants.hh"
#include "util/util.hh"
#include <string> #include <string>
#include <fstream> #include <fstream>
...@@ -19,6 +20,8 @@ globalConstants initGlobalConstants(){ ...@@ -19,6 +20,8 @@ globalConstants initGlobalConstants(){
globalConstants res; globalConstants res;
std::string line; std::string line;
while(std::getline(infile,line)) { while(std::getline(infile,line)) {
if(line.size()==0) continue;
if(line[0]=='#') continue;
int index = line.find(":"); int index = line.find(":");
std::string head = line.substr(0,index); std::string head = line.substr(0,index);
if(head=="loadCount") { if(head=="loadCount") {
...@@ -63,7 +66,50 @@ globalConstants initGlobalConstants(){ ...@@ -63,7 +66,50 @@ globalConstants initGlobalConstants(){
} }
}else if(head=="other") { }else if(head=="other") {
; ;
}else{ }else if(head == "BS_STR"){
std::string sub = line.substr(index+1);
if(sub=="NA"){
res.BS_STR = 0;
}else if(sub=="MIN"){
res.BS_STR = 1;
}else if(sub=="MIDEAN"){
res.BS_STR = 2;
}else if(sub=="FULL"){
res.BS_STR = 3;
}else{
POINT
assert(0);
}
}else if(head == "BS_IA"){
std::string sub = line.substr(index+1);
if(sub=="NA"){
res.BS_IA = 0;
}else if(sub=="MIN"){
res.BS_IA = 1;
}else if(sub=="MIDEAN"){
res.BS_IA = 2;
}else if(sub=="FULL"){
res.BS_IA = 3;
}else{
POINT
assert(0);
}
}else if(head == "BS_IH"){
std::string sub = line.substr(index+1);
if(sub=="NA"){
res.BS_IH = 0;
}else if(sub=="MIN"){
res.BS_IH = 1;
}else if(sub=="MIDEAN"){
res.BS_IH = 2;
}else if(sub=="FULL"){
res.BS_IH = 3;
}else{
POINT
assert(0);
}
}else{
POINT
assert(0); assert(0);
} }
} }
......
...@@ -18,6 +18,9 @@ struct globalConstants{ ...@@ -18,6 +18,9 @@ struct globalConstants{
bool useSWP; bool useSWP;
bool useDET; bool useDET;
bool useSalt; bool useSalt;
int BS_STR;
int BS_IA;
int BS_IH;
std::string logFile;/*file name for log*/ std::string logFile;/*file name for log*/
}; };
......
...@@ -196,7 +196,6 @@ string TableMetaTrans::serialize_vec_str(string s,vector<string> vec_str){ ...@@ -196,7 +196,6 @@ string TableMetaTrans::serialize_vec_str(string s,vector<string> vec_str){
return s; return s;
} }
vector<string> TableMetaTrans::string_to_vec_str(string line){ vector<string> TableMetaTrans::string_to_vec_str(string line){
int start=0,next=0; int start=0,next=0;
vector<string> tmp; vector<string> tmp;
...@@ -244,6 +243,65 @@ bool TableMetaTrans::make_path(string directory){ ...@@ -244,6 +243,65 @@ bool TableMetaTrans::make_path(string directory){
return true; return true;
} }
void
TableMetaTrans::serializeNew(std::string fullpath){
FILE * localmeta = NULL;
localmeta = fopen((fullpath).c_str(),"w");
string s = string("database:")+db;
s+="\n";
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("table:")+table;
s+="\n";
fwrite(s.c_str(),1,s.size(),localmeta);
for(unsigned int i=0u;i<fts.size();i++) {//serilize every field
s=string("INDEX:")+fts[i].getFieldPlainName()+"\n";
fwrite(s.c_str(),1,s.size(),localmeta);
//then for each index, that is, for each plain field
s = serialize_vec_str("ChoosenOnionName",fts[i].getChoosenOnionName());
fwrite(s.c_str(),1,s.size(),localmeta);
std::vector<int> tmp;
for(auto item:fts[i].getChoosenOnionO()){
tmp.push_back(static_cast<int>(item));
}
s = serialize_vec_int("choosenOnionO",tmp);
fwrite(s.c_str(),1,s.size(),localmeta);
if(fts[i].getHasSalt()){
s = std::string("hasSalt:true\n");
fwrite(s.c_str(),1,s.size(),localmeta);
s = std::string("saltName:")+fts[i].getSaltName()+"\n";
fwrite(s.c_str(),1,s.size(),localmeta);
s = std::string("saltType:")+std::to_string(fts[i].getSaltType())+"\n";
fwrite(s.c_str(),1,s.size(),localmeta);
s = std::string("saltLength:")+std::to_string(fts[i].getSaltLength())+"\n";
fwrite(s.c_str(),1,s.size(),localmeta);
}else{
s = std::string("hasSalt:false\n");
fwrite(s.c_str(),1,s.size(),localmeta);
}
s = serialize_vec_int("choosenFieldTypes",fts[i].getChoosenFieldTypes());
fwrite(s.c_str(),1,s.size(),localmeta);
s = serialize_vec_int("choosenFieldLengths",fts[i].getChoosenFieldLengths());
FieldMetaTrans::FILEFORMAT fmf = fts[i].getFeidlStoreFormat();
if(fmf == FieldMetaTrans::FILEFORMAT::ESP_STRING){
s+="fieldFileFormat:ESP_STRING\n";
}else if(fmf == FieldMetaTrans::FILEFORMAT::NUM_STRING){
s+="fieldFileFormat:NUM_STRING\n";
}else if(fmf == FieldMetaTrans::FILEFORMAT::NUM_BINARY){
s+="fieldFileFormat:NUM_BINARY\n";
}else{
s+="fieldFileFormat:NA\n";
}
s+="\n";
fwrite(s.c_str(),1,s.size(),localmeta);
}
fwrite("**********************************************************************\n",1,71,localmeta);
fclose(localmeta);
}
void TableMetaTrans::serialize(std::string filename,std::string prefix){ void TableMetaTrans::serialize(std::string filename,std::string prefix){
FILE * localmeta = NULL; FILE * localmeta = NULL;
......
...@@ -87,6 +87,7 @@ public: ...@@ -87,6 +87,7 @@ public:
void set_db_table(string idb,string itable){db=idb;table=itable;} void set_db_table(string idb,string itable){db=idb;table=itable;}
void serialize(std::string filename="metadata.data", std::string prefix="data/"); void serialize(std::string filename="metadata.data", std::string prefix="data/");
void serializeNew(std::string fullpath);
void deserialize(std::string filename="metadata.data", std::string prefix="data/"); void deserialize(std::string filename="metadata.data", std::string prefix="data/");
}; };
......
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