Commit 0fa3f2a9 authored by yiwenshao's avatar yiwenshao

add more global constants

parent 1f128066
......@@ -6,4 +6,8 @@ useOPE:false
useSWP:true
useDET:true
useSalt:true
#NA,MIN,MIDEAN,FULL
BS_STR:MIN
BS_IA:MIN
BS_IH:MIN
other:1
......@@ -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
std::string
getSelectField(SchemaInfo &schema, FieldMetaTrans &tf,std::string db,std::string table){
......@@ -161,11 +170,10 @@ static void store(std::string db, std::string table){
tf.setSaltLength(slength);
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
(void)getSelectQuery;
(void)getSelectField;
/*
write_raw_data_to_files(resraw,res,db,table);
*/
......
#include "util/constants.hh"
#include "util/util.hh"
#include <string>
#include <fstream>
......@@ -19,6 +20,8 @@ globalConstants initGlobalConstants(){
globalConstants res;
std::string line;
while(std::getline(infile,line)) {
if(line.size()==0) continue;
if(line[0]=='#') continue;
int index = line.find(":");
std::string head = line.substr(0,index);
if(head=="loadCount") {
......@@ -63,7 +66,50 @@ globalConstants initGlobalConstants(){
}
}else if(head=="other") {
;
}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);
}
}
......
......@@ -18,6 +18,9 @@ struct globalConstants{
bool useSWP;
bool useDET;
bool useSalt;
int BS_STR;
int BS_IA;
int BS_IH;
std::string logFile;/*file name for log*/
};
......
......@@ -196,7 +196,6 @@ string TableMetaTrans::serialize_vec_str(string s,vector<string> vec_str){
return s;
}
vector<string> TableMetaTrans::string_to_vec_str(string line){
int start=0,next=0;
vector<string> tmp;
......@@ -244,6 +243,65 @@ bool TableMetaTrans::make_path(string directory){
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){
FILE * localmeta = NULL;
......
......@@ -87,6 +87,7 @@ public:
void set_db_table(string idb,string itable){db=idb;table=itable;}
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/");
};
......
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