Commit 52077725 authored by yiwenshao's avatar yiwenshao

simplify debug/store

parent 82747d8f
...@@ -5,7 +5,7 @@ class metadata_file{ ...@@ -5,7 +5,7 @@ class metadata_file{
vector<string> field_types; vector<string> field_types;
vector<int> field_lengths; vector<int> field_lengths;
vector<string> field_names; vector<string> field_names;
vector<int> choosen_onions; vector<int> choosen_onions;/*choosen onion for decryption, only one per field.The value could be 0,1,2,3...*/
public: public:
void set_db(std::string idb){db=idb;} void set_db(std::string idb){db=idb;}
std::string get_db(){return db;} std::string get_db(){return db;}
......
...@@ -25,80 +25,6 @@ static metadata_file load_meta(string db="tdb", string table="student", string f ...@@ -25,80 +25,6 @@ static metadata_file load_meta(string db="tdb", string table="student", string f
mf.set_table(table); mf.set_table(table);
mf.deserialize(filename); mf.deserialize(filename);
return mf; return mf;
/*
string line;
meta_file res;
while(std::getline(infile,line)){
int index = line.find(":");
string head = line.substr(0,index);
if(head=="database"){
res.db = line.substr(index+1);
// mf.set_db(line.substr(index+1));
}else if(head=="table"){
res.table = line.substr(index+1);
// mf.set_table(line.substr(index+1));
}else if(head=="num_of_fields"){
res.num_of_fields = std::stoi(line.substr(index+1));
// mf.set_num_of_fields(std::stoi(line.substr(index+1)));
}else if(head=="field_types"){
string types = line.substr(index+1);
int start=0,next=0;
// std::vector<std::string> tmp;
while((next=types.find(' ',start))!=-1){
string item = types.substr(start,next-start);
res.field_types.push_back(item);
// tmp.push_back(item);
start = next+1;
}
string item = types.substr(start);
// tmp.push_back(item);
res.field_types.push_back(item);
// mf.set_field_types(tmp);
}else if(head=="field_lengths"){
string lengths = line.substr(index+1);
int start=0,next=0;
// std::vector<int> tmp;
while((next=lengths.find(' ',start))!=-1){
string item = lengths.substr(start,next-start);
res.field_lengths.push_back(std::stoi(item));
// tmp.push_back(std::stoi(item));
start = next+1;
}
string item = lengths.substr(start);
res.field_lengths.push_back(std::stoi(item));
// tmp.push_back(std::stoi(item));
// mf.set_field_lengths(tmp);
}else if(head=="field_names"){
// std::vector<std::string> tmp;
string names = line.substr(index+1);
int start=0,next=0;
while((next=names.find(' ',start))!=-1){
string item = names.substr(start,next-start);
res.field_names.push_back(item);
// tmp.push_back(item);
start = next+1;
}
string item = names.substr(start);
res.field_names.push_back(item);
// tmp.push_back(item);
// mf.set_field_names(tmp);
}else if(head=="choosen_onions"){
// std::vector<int> tmp;
string c_onions = line.substr(index+1);
int start=0,next=0;
while((next=c_onions.find(' ',start))!=-1){
string item = c_onions.substr(start,next-start);
res.choosen_onions.push_back(std::stoi(item));
// tmp.push_back(std::stoi(item));
start = next+1;
}
string item = c_onions.substr(start);
res.choosen_onions.push_back(std::stoi(item));
// tmp.push_back(std::stoi(item));
// mf.set_choosen_onions(tmp);
}
}
//return res;*/
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
#include "debug/common.hh" #include "debug/common.hh"
static void write_meta(rawMySQLReturnValue& resraw,string db,string table){ static void write_meta(rawMySQLReturnValue& resraw,string db,string table){
//write metadata
// FILE * localmeta = NULL;
metadata_file mf; metadata_file mf;
mf.set_db_table(db,table); mf.set_db_table(db,table);
mf.set_num_of_fields(resraw.fieldNames.size()); mf.set_num_of_fields(resraw.fieldNames.size());
...@@ -16,46 +14,6 @@ static void write_meta(rawMySQLReturnValue& resraw,string db,string table){ ...@@ -16,46 +14,6 @@ static void write_meta(rawMySQLReturnValue& resraw,string db,string table){
mf.set_field_names(resraw.fieldNames); mf.set_field_names(resraw.fieldNames);
mf.set_choosen_onions(resraw.choosen_onions); mf.set_choosen_onions(resraw.choosen_onions);
mf.serilize(); mf.serilize();
/*
string prefix = string("data/")+db+"/"+table;
make_path(prefix);
localmeta = fopen((prefix+"/metadata.data").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);
s = string("num_of_fields:")+to_string(resraw.fieldNames.size())+"\n";
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("field_types:");
for(auto item:resraw.fieldTypes){
s+=std::to_string(item)+=" ";
}
s.back()='\n';
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("field_lengths:");
for(auto item : resraw.lengths){
s+=to_string(item)+=" ";
}
s.back()='\n';
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("field_names:");
for(auto item : resraw.fieldNames){
s+=item+=" ";
}
s.back()='\n';
fwrite(s.c_str(),1,s.size(),localmeta);
s = string("choosen_onions:");
for(auto item : resraw.choosen_onions){
s+=to_string(item)+=" ";
}
s.back()='\n';
fwrite(s.c_str(),1,s.size(),localmeta);
fclose(localmeta);
*/
} }
...@@ -101,7 +59,7 @@ static void store(std::string db, std::string table){ ...@@ -101,7 +59,7 @@ static void store(std::string db, std::string table){
item.choosenOnions.push_back(0); item.choosenOnions.push_back(0);
} }
//generate the backup query and then fetch the tuples //generate the backup query and then fetch the tuples
std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res); // std::shared_ptr<ReturnMeta> rm = getReturnMeta(fms,res);
std::string backq = getTestQuery(*schema,res,db,table); std::string backq = getTestQuery(*schema,res,db,table);
rawMySQLReturnValue resraw = executeAndGetResultRemote(globalConn,backq); rawMySQLReturnValue resraw = executeAndGetResultRemote(globalConn,backq);
...@@ -113,7 +71,7 @@ static void store(std::string db, std::string table){ ...@@ -113,7 +71,7 @@ static void store(std::string db, std::string table){
} }
int int
main(int argc, char* argv[]) { main(int argc, char* argv[]){
init(); init();
std::string db="tdb",table="student"; std::string db="tdb",table="student";
store(db,table); store(db,table);
......
...@@ -239,82 +239,6 @@ static std::unique_ptr<SchemaInfo> myLoadSchemaInfo() { ...@@ -239,82 +239,6 @@ static std::unique_ptr<SchemaInfo> myLoadSchemaInfo() {
return schema; return schema;
} }
static void
addToReturn(ReturnMeta *const rm, int pos, const OLK &constr,
bool has_salt, const std::string &name) {
const bool test = static_cast<unsigned int>(pos) == rm->rfmeta.size();
TEST_TextMessageError(test, "ReturnMeta has badly ordered"
" ReturnFields!");
const int salt_pos = has_salt ? pos + 1 : -1;
std::pair<int, ReturnField>
pair(pos, ReturnField(false, name, constr, salt_pos));
rm->rfmeta.insert(pair);
}
static void
addSaltToReturn(ReturnMeta *const rm, int pos) {
const bool test = static_cast<unsigned int>(pos) == rm->rfmeta.size();
TEST_TextMessageError(test, "ReturnMeta has badly ordered"
" ReturnFields!");
std::pair<int, ReturnField>
pair(pos, ReturnField(true, "", OLK::invalidOLK(), -1));
rm->rfmeta.insert(pair);
}
//get returnMeta
//for each filed, we have a fieldmeta. we can chosse one onion under that field to construct a return meta.
//in fact, a returnmeta can contain many fields.
static
std::shared_ptr<ReturnMeta> getReturnMeta(std::vector<FieldMeta*> fms, std::vector<transField> &tfds){
assert(fms.size()==tfds.size());
std::shared_ptr<ReturnMeta> myReturnMeta = std::make_shared<ReturnMeta>();
int pos=0;
//construct OLK
for(auto i=0u;i<tfds.size();i++){
OLK curOLK(tfds[i].onions[tfds[i].onionIndex],
tfds[i].originalOm[tfds[i].onionIndex]->getSecLevel(),tfds[i].originalFm);
addToReturn(myReturnMeta.get(),pos++,curOLK,true,tfds[i].originalFm->getFieldName());
addSaltToReturn(myReturnMeta.get(),pos++);
}
return myReturnMeta;
}
/*
only support relative path
*/
/*static bool make_path(string directory){
struct stat st;
if(directory.size()==0||directory[0]=='/') return false;
if(directory.back()=='/') directory.pop_back();
int start = 0,next=0;
while(stat(directory.c_str(),&st)==-1&&next!=-1){
next = directory.find('/',start);
if(next!=-1){
string sub = directory.substr(0,next);
if(stat(sub.c_str(),&st)==-1)
mkdir(sub.c_str(),0700);
start = next + 1;
}else{
mkdir(directory.c_str(),0700);
}
}
return true;
}*/
/*for each field, convert the format to transField*/ /*for each field, convert the format to transField*/
static std::vector<transField> getTransField(std::vector<FieldMeta *> pfms){ static std::vector<transField> getTransField(std::vector<FieldMeta *> pfms){
std::vector<transField> res; std::vector<transField> res;
......
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