Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
Practical-Cryptdb
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Zhaozhen
Practical-Cryptdb
Commits
6a00e3a4
Commit
6a00e3a4
authored
May 17, 2017
by
casualet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove obselete
parent
0ad6659c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
532 deletions
+5
-532
mbk.cc
main/mbk.cc
+5
-532
No files found.
main/mbk.cc
View file @
6a00e3a4
...
...
@@ -99,19 +99,6 @@ struct rawReturnValue{
};
struct
backupOnionSelection
{
int
numOfFields
;
std
::
vector
<
int
>
fieldSize
;
std
::
vector
<
int
>
saltIndex
;
std
::
vector
<
int
>
onionIndex
;
backupOnionSelection
(
int
n
)
:
numOfFields
(
n
),
fieldSize
(
n
,
-
1
),
saltIndex
(
n
,
-
1
),
onionIndex
(
n
,
-
1
){}
void
print
();
};
//must be static, or we get "no previous declaration"
//execute the query and getthe rawReturnVale, this struct can be copied.
static
...
...
@@ -154,6 +141,7 @@ rawReturnValue executeAndGetResultRemote(Connect * curConn,std::string query){
return
myRaw
;
}
/*
//print RawReturnValue for testing purposes.
static
void printrawReturnValue(rawReturnValue & cur) {
...
...
@@ -180,42 +168,8 @@ void printrawReturnValue(rawReturnValue & cur) {
std::cout<<std::endl;
}
}
//The rewrite phase of cryptdb.
/*
1. getSchemaInfo
2. rewrite => gather/write
3. fetch the executor and put it in wrapperState(std::unique_ptr<QueryRewrite> qr)
*/
static
bool
myRewrite
(
std
::
string
curQuery
,
unsigned
long
long
_thread_id
,
std
::
string
client
)
{
assert
(
0
==
mysql_thread_init
());
WrapperState
*
const
c_wrapper
=
clients
[
client
];
ProxyState
*
const
ps
=
c_wrapper
->
ps
.
get
();
assert
(
ps
);
c_wrapper
->
last_query
=
curQuery
;
std
::
cout
<<
RED_BEGIN
<<
"start my rewrite"
<<
COLOR_END
<<
std
::
endl
;
try
{
TEST_Text
(
retrieveDefaultDatabase
(
_thread_id
,
ps
->
getConn
(),
&
c_wrapper
->
default_db
),
"proxy failed to retrieve default database!"
);
const
std
::
shared_ptr
<
const
SchemaInfo
>
&
schema
=
ps
->
getSchemaInfo
();
c_wrapper
->
schema_info_refs
.
push_back
(
schema
);
std
::
unique_ptr
<
QueryRewrite
>
qr
=
std
::
unique_ptr
<
QueryRewrite
>
(
new
QueryRewrite
(
Rewriter
::
rewrite
(
curQuery
,
*
schema
.
get
(),
c_wrapper
->
default_db
,
*
ps
)));
assert
(
qr
);
c_wrapper
->
setQueryRewrite
(
std
::
move
(
qr
));
}
catch
(...){
std
::
cout
<<
"rewrite exception!!!"
<<
std
::
endl
;
return
false
;
}
return
true
;
}
//helper function for transforming the rawReturnValue
static
Item_null
*
make_null
(
const
std
::
string
&
name
=
""
){
...
...
@@ -285,157 +239,6 @@ void parseResType(const ResType &rd) {
}
//the "next" phase of cryptdb
/*
1. call function "next" in the executor
2. process three different return types.
*/
static
void
myNext
(
std
::
string
client
,
bool
isFirst
,
ResType
inRes
)
{
WrapperState
*
const
c_wrapper
=
clients
[
client
];
ProxyState
*
const
ps
=
c_wrapper
->
ps
.
get
();
assert
(
ps
);
ps
->
safeCreateEmbeddedTHD
();
const
ResType
&
res
=
inRes
;
const
std
::
unique_ptr
<
QueryRewrite
>
&
qr
=
c_wrapper
->
getQueryRewrite
();
try
{
NextParams
nparams
(
*
ps
,
c_wrapper
->
default_db
,
c_wrapper
->
last_query
);
const
auto
&
new_results
=
qr
->
executor
->
next
(
res
,
nparams
);
const
auto
&
result_type
=
new_results
.
first
;
switch
(
result_type
){
//execute the query, fetch the results, and call next again
case
AbstractQueryExecutor
:
:
ResultType
::
QUERY_COME_AGAIN
:
{
std
::
cout
<<
RED_BEGIN
<<
"case one"
<<
COLOR_END
<<
std
::
endl
;
const
auto
&
output
=
std
::
get
<
1
>
(
new_results
)
->
extract
<
std
::
pair
<
bool
,
std
::
string
>
>
();
const
auto
&
next_query
=
output
.
second
;
//here we execute the query against the remote database, and get rawReturnValue
rawReturnValue
resRemote
=
executeAndGetResultRemote
(
globalConn
,
next_query
);
//transform rawReturnValue first
const
auto
&
againGet
=
MygetResTypeFromLuaTable
(
false
,
&
resRemote
);
myNext
(
client
,
false
,
againGet
);
break
;
}
//only execute the query, without processing the retults
case
AbstractQueryExecutor
:
:
ResultType
::
QUERY_USE_RESULTS
:
{
std
::
cout
<<
RED_BEGIN
<<
"case two"
<<
COLOR_END
<<
std
::
endl
;
const
auto
&
new_query
=
std
::
get
<
1
>
(
new_results
)
->
extract
<
std
::
string
>
();
auto
resRemote
=
executeAndGetResultRemote
(
globalConn
,
new_query
);
printrawReturnValue
(
resRemote
);
break
;
}
//return the results to the client directly
case
AbstractQueryExecutor
:
:
ResultType
::
RESULTS
:
{
std
::
cout
<<
RED_BEGIN
<<
"case three"
<<
COLOR_END
<<
std
::
endl
;
const
auto
&
res
=
new_results
.
second
->
extract
<
ResType
>
();
parseResType
(
res
);
break
;
}
default
:
{
std
::
cout
<<
"case default"
<<
std
::
endl
;
}
}
}
catch
(...){
std
::
cout
<<
"next error"
<<
std
::
endl
;
}
}
static
void
batchTogether
(
std
::
string
client
,
std
::
string
curQuery
,
unsigned
long
long
_thread_id
)
{
//the first step is to Rewrite, we abort this session if we fail here.
bool
resMyRewrite
=
myRewrite
(
curQuery
,
_thread_id
,
client
);
if
(
!
resMyRewrite
){
std
::
cout
<<
"my rewrite error in batch"
<<
std
::
endl
;
return
;
}
myNext
(
client
,
true
,
MygetResTypeFromLuaTable
(
true
));
}
static
void
processLayers
(
const
EncLayer
&
enc
){
//std::cout<<enc.serialize(enc)<<std::endl;
std
::
cout
<<
enc
.
name
()
<<
std
::
endl
;
}
static
void
processOnionMeta
(
const
OnionMeta
&
onion
){
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT OnionMeta"
<<
COLOR_END
<<
std
::
endl
;
std
::
cout
<<
"onionmeta->getAnonOnionName(): "
<<
onion
.
getAnonOnionName
()
<<
std
::
endl
;
auto
&
layers
=
onion
.
getLayers
();
for
(
auto
&
slayer
:
layers
){
processLayers
(
*
(
slayer
.
get
()));
}
}
static
void
processFieldMeta
(
const
FieldMeta
&
field
){
//Process general info
if
(
field
.
getHasSalt
()){
std
::
cout
<<
"this field has salt"
<<
std
::
endl
;
}
std
::
cout
<<
"field.getFieldName(): "
<<
field
.
getFieldName
()
<<
std
::
endl
;
std
::
cout
<<
"field.getSaltName(): "
<<
field
.
getSaltName
()
<<
std
::
endl
;
std
::
cout
<<
"field.serialize(): "
<<
field
.
serialize
(
field
)
<<
std
::
endl
;
for
(
std
::
pair
<
const
OnionMetaKey
*
,
OnionMeta
*>
&
ompair
:
field
.
orderedOnionMetas
()){
processOnionMeta
(
*
ompair
.
second
);
}
//Process Onions
if
(
field
.
hasOnion
(
oDET
)){
field
.
getOnionMeta
(
oDET
);
}
if
(
field
.
hasOnion
(
oOPE
)){
field
.
getOnionMeta
(
oOPE
);
}
if
(
field
.
hasOnion
(
oAGG
)){
field
.
getOnionMeta
(
oAGG
);
}
return
;
//iterate over onions
for
(
const
std
::
pair
<
const
OnionMetaKey
,
std
::
unique_ptr
<
OnionMeta
>
>
&
onion
:
field
.
getChildren
()){
std
::
cout
<<
onion
.
second
->
getDatabaseID
()
<<
":"
<<
onion
.
first
.
getValue
()
<<
std
::
endl
;
}
}
static
void
processTableMeta
(
const
TableMeta
&
table
){
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT TableMeta"
<<
COLOR_END
<<
std
::
endl
;
for
(
FieldMeta
*
cfm
:
table
.
orderedFieldMetas
()){
processFieldMeta
(
*
cfm
);
}
}
static
void
processDatabaseMeta
(
const
DatabaseMeta
&
dbm
,
std
::
string
table
=
"student1"
)
{
TableMeta
&
tbm
=
*
dbm
.
getChild
(
IdentityMetaKey
(
table
));
processTableMeta
(
tbm
);
return
;
}
static
void
processSchemaInfo
(
SchemaInfo
&
schema
,
std
::
string
db
=
"tdb"
){
const
std
::
unique_ptr
<
AES_KEY
>
&
TK
=
std
::
unique_ptr
<
AES_KEY
>
(
getKey
(
std
::
string
(
"113341234"
)));
Analysis
analysis
(
db
,
schema
,
TK
,
SECURITY_RATING
::
SENSITIVE
);
if
(
analysis
.
databaseMetaExists
(
db
)){
processDatabaseMeta
(
analysis
.
getDatabaseMeta
(
db
));
}
else
{
std
::
cout
<<
"data base not exists"
<<
std
::
endl
;
}
}
//first step of back
static
std
::
vector
<
FieldMeta
*>
getFieldMeta
(
SchemaInfo
&
schema
,
std
::
string
db
=
"tdb"
,
std
::
string
table
=
"student1"
){
const
std
::
unique_ptr
<
AES_KEY
>
&
TK
=
std
::
unique_ptr
<
AES_KEY
>
(
getKey
(
std
::
string
(
"113341234"
)));
...
...
@@ -631,158 +434,7 @@ ResType decryptResults(const ResType &dbres, const ReturnMeta &rmeta) {
std
::
move
(
dec_rows
));
}
//can not use unique_ptr here in argument 3?
static
std
::
shared_ptr
<
ReturnMeta
>
myGetReturnMeta
(
std
::
string
database
,
std
::
string
table
,
\
SchemaInfo
&
schema
,
backupOnionSelection
&
bonion
)
{
std
::
cout
<<
"start my decrypt!!"
<<
std
::
endl
;
std
::
shared_ptr
<
ReturnMeta
>
myReturnMeta
=
std
::
make_shared
<
ReturnMeta
>
();
myReturnMeta
->
rfmeta
.
size
();
//construct OLKs for each field!!
//do not use factory to construct IdentityMetaKey, it's used only upon serial data.
const
std
::
unique_ptr
<
IdentityMetaKey
>
dbmeta_key
(
new
IdentityMetaKey
(
database
));
//get databaseMeta
std
::
cout
<<
dbmeta_key
->
getValue
()
<<
std
::
endl
;
DatabaseMeta
*
db
=
schema
.
getChild
(
*
dbmeta_key
);
if
(
db
==
NULL
)
{
std
::
cout
<<
"db == NULL"
<<
std
::
endl
;
exit
(
0
);
}
else
{
std
::
cout
<<
db
->
getDatabaseID
()
<<
std
::
endl
;
}
//get tableMeta
const
std
::
unique_ptr
<
IdentityMetaKey
>
tbMeta_key
(
new
IdentityMetaKey
(
table
));
TableMeta
*
tbMeta
=
(
*
db
).
getChild
(
*
tbMeta_key
);
if
(
tbMeta
==
NULL
){
std
::
cout
<<
"tb == NULL"
<<
std
::
endl
;
exit
(
0
);
}
else
{
std
::
cout
<<
tbMeta
->
getDatabaseID
()
<<
std
::
endl
;
}
std
::
cout
<<
"table anon name: "
<<
tbMeta
->
getAnonTableName
()
<<
std
::
endl
;
//get fieldMeta
const
auto
&
fields
=
tbMeta
->
getChildren
();
//num of fields
std
::
cout
<<
fields
.
size
()
<<
std
::
endl
;
//one Olk for each field
std
::
cout
<<
"fields print: "
<<
std
::
endl
;
int
pos
=
0
;
std
::
vector
<
std
::
string
>
selectFields
;
//according to uniqueCounter
for
(
FieldMeta
*
field
:
tbMeta
->
orderedFieldMetas
())
{
std
::
cout
<<
field
->
getFieldName
()
<<
field
->
getSaltName
()
<<
std
::
endl
;
//getOlks!!
for
(
std
::
pair
<
const
OnionMetaKey
*
,
OnionMeta
*>
oneOnion
:
field
->
orderedOnionMetas
()){
std
::
cout
<<
oneOnion
.
first
->
getValue
()
<<
":"
<<
oneOnion
.
second
->
getAnonOnionName
()
<<
std
::
endl
;
OLK
curOLK
(
oneOnion
.
first
->
getValue
(),
oneOnion
.
second
->
getSecLevel
(),
field
);
std
::
cout
<<
curOLK
.
o
<<
std
::
endl
;
addToReturn
(
myReturnMeta
.
get
(),
pos
++
,
curOLK
,
true
,
field
->
getFieldName
());
addSaltToReturn
(
myReturnMeta
.
get
(),
pos
++
);
selectFields
.
push_back
(
oneOnion
.
second
->
getAnonOnionName
());
break
;
}
selectFields
.
push_back
(
field
->
getSaltName
());
}
auto
allFieldMetas
=
tbMeta
->
orderedFieldMetas
();
int
numOfFields
=
allFieldMetas
.
size
();
for
(
int
i
=
0
;
i
<
numOfFields
;
i
++
){
FieldMeta
*
field
=
allFieldMetas
[
i
];
auto
allOnionMetas
=
field
->
orderedOnionMetas
();
//choose onion and then construct returnmeta,
//current we choose the first onion
std
::
pair
<
const
OnionMetaKey
*
,
OnionMeta
*>
oneOnion
=
allOnionMetas
[
0
];
OLK
curOLK
(
oneOnion
.
first
->
getValue
(),
oneOnion
.
second
->
getSecLevel
(),
field
);
addToReturn
(
myReturnMeta
.
get
(),
pos
++
,
curOLK
,
true
,
field
->
getFieldName
());
addSaltToReturn
(
myReturnMeta
.
get
(),
pos
++
);
}
//we have constructed OLK in myReturnMeta, let's decrypt
// ResType deResType = decryptResults(backResType,*myReturnMeta);
// std::cout<<"start parsing deresType!!!!!"<<std::endl;
// parseResType(deResType);
return
myReturnMeta
;
}
//select query generate, select and retrive the onion selected
static
std
::
string
generateSelectQuery
(
std
::
string
database
,
std
::
string
table
,
SchemaInfo
&
schema
,
backupOnionSelection
&
bonion
)
{
//construct OLKs for each field!!
//do not use factory to construct IdentityMetaKey, it's used only upon serial data.
const
std
::
unique_ptr
<
IdentityMetaKey
>
dbmeta_key
(
new
IdentityMetaKey
(
database
));
//get databaseMeta
DatabaseMeta
*
db
=
schema
.
getChild
(
*
dbmeta_key
);
if
(
db
==
NULL
)
{
std
::
cout
<<
"db == NULL"
<<
std
::
endl
;
return
"select NULL"
;
}
//get tableMeta
const
std
::
unique_ptr
<
IdentityMetaKey
>
tbMeta_key
(
new
IdentityMetaKey
(
table
));
TableMeta
*
tbMeta
=
(
*
db
).
getChild
(
*
tbMeta_key
);
if
(
tbMeta
==
NULL
){
std
::
cout
<<
"tb == NULL"
<<
std
::
endl
;
return
"select NULL"
;
}
//get fieldMeta
const
auto
&
fields
=
tbMeta
->
getChildren
();
//num of fields
int
numOfFields
=
fields
.
size
();
assert
(
numOfFields
==
bonion
.
numOfFields
);
//one Olk for each field
std
::
vector
<
std
::
string
>
selectFields
;
/*
//according to uniqueCounter
for(FieldMeta * field : tbMeta->orderedFieldMetas()) {
std::cout<<field->getFieldName()<<field->getSaltName()<<std::endl;
//getOlks!!
for(std::pair<const OnionMetaKey *, OnionMeta *> oneOnion:field->orderedOnionMetas()){
selectFields.push_back(oneOnion.second->getAnonOnionName());
break;
}
selectFields.push_back(field->getSaltName());
}
*/
std
::
cout
<<
"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
<<
std
::
endl
;
auto
allFieldMetas
=
tbMeta
->
orderedFieldMetas
();
for
(
int
i
=
0
;
i
<
numOfFields
;
i
++
){
FieldMeta
*
field
=
allFieldMetas
[
i
];
auto
allOnionMetas
=
field
->
orderedOnionMetas
();
//for this field, choose an onion
std
::
pair
<
const
OnionMetaKey
*
,
OnionMeta
*>
oneOnion
=
allOnionMetas
[
0
];
selectFields
.
push_back
(
oneOnion
.
second
->
getAnonOnionName
());
selectFields
.
push_back
(
field
->
getSaltName
());
}
std
::
string
firstFields
;
for
(
int
i
=
0
;
i
<
(
int
)
selectFields
.
size
()
-
1
;
i
++
)
{
firstFields
=
firstFields
+
selectFields
[
i
]
+
","
;
}
firstFields
+=
selectFields
[
selectFields
.
size
()
-
1
];
//backup(select) only some of the onions
std
::
string
backQuery
=
std
::
string
(
"select "
+
firstFields
+
" from "
+
database
+
"."
)
\
+
std
::
string
(
tbMeta
->
getAnonTableName
());
return
backQuery
;
}
static
void
split
(
const
std
::
string
&
s
,
char
delim
,
std
::
vector
<
std
::
string
>
&
elems
)
{
/*static void split(const std::string &s, char delim, std::vector<std::string> &elems) {
std::stringstream ss;
ss.str(s);
std::string item;
...
...
@@ -795,177 +447,7 @@ static std::vector<std::string> split(const std::string &s, char delim) {
std::vector<std::string> elems;
split(s, delim, elems);
return elems;
}
void
backupOnionSelection
::
print
()
{
std
::
cout
<<
GREEN_BEGIN
<<
"numOfFields: "
<<
numOfFields
<<
COLOR_END
<<
std
::
endl
;
std
::
cout
<<
"field size: "
<<
std
::
endl
;
for
(
auto
item
:
fieldSize
){
std
::
cout
<<
item
<<
"
\t
"
<<
std
::
endl
;
}
std
::
cout
<<
"saltIndex: "
<<
std
::
endl
;
for
(
auto
item
:
saltIndex
){
std
::
cout
<<
item
<<
"
\t
"
<<
std
::
endl
;
}
std
::
cout
<<
"onionIndex: "
<<
std
::
endl
;
for
(
auto
item
:
onionIndex
){
std
::
cout
<<
item
<<
"
\t
"
<<
std
::
endl
;
}
}
//based on the Metadata, we mordify the original create tabe query and generate the new query.
//static void std::string getCreateTable) {
static
std
::
string
getCreateTable
(
std
::
string
orignalQuery
,
backupOnionSelection
back
)
{
std
::
cout
<<
"orignalQuery: "
<<
orignalQuery
<<
std
::
endl
;
back
.
print
();
auto
res
=
split
(
orignalQuery
,
','
);
for
(
auto
item
:
res
)
{
std
::
cout
<<
item
<<
std
::
endl
;
}
std
::
string
result
;
//choose the salt and onion base on backupOnionSelection.
for
(
int
i
=
0
;
i
<
back
.
numOfFields
-
1
;
i
++
){
int
indexOne
=
back
.
onionIndex
[
i
];
int
indexTwo
=
back
.
saltIndex
[
i
];
result
=
result
+
res
[
indexOne
]
+
","
+
res
[
indexTwo
]
+
","
;
}
int
indexOne
=
back
.
onionIndex
[
back
.
numOfFields
-
1
];
int
indexTwo
=
back
.
saltIndex
[
back
.
numOfFields
-
1
];
result
=
result
+
res
[
indexOne
]
+
","
+
res
[
indexTwo
];
return
result
;
}
//generate simple INSERT query for testing purposes.
static
void
generateInsertQuery
(
rawReturnValue
&
raw
,
std
::
string
annoTable
)
{
std
::
cout
<<
raw
.
rowValues
.
size
()
<<
std
::
endl
;
std
::
cout
<<
annoTable
<<
std
::
endl
;
int
len
=
raw
.
fieldNames
.
size
();
for
(
auto
oneRow
:
raw
.
rowValues
){
std
::
string
res
=
std
::
string
(
"INSERT INTO "
)
+
annoTable
+
" VALUES("
;
for
(
int
i
=
0
;
i
<
len
-
1
;
i
++
){
res
=
res
+
oneRow
[
i
]
+
" , "
;
}
res
=
res
+
oneRow
[
len
-
1
]
+
")"
;
std
::
cout
<<
GREEN_BEGIN
<<
res
<<
COLOR_END
<<
std
::
endl
;
}
}
static
backupOnionSelection
generateBackupStrategy
(
std
::
string
database
,
std
::
string
table
,
SchemaInfo
&
schema
){
//do not use factory to construct IdentityMetaKey, it's used only upon serial data.
const
std
::
unique_ptr
<
IdentityMetaKey
>
dbmeta_key
(
new
IdentityMetaKey
(
database
));
//get databaseMeta, search in the map
DatabaseMeta
*
db
=
schema
.
getChild
(
*
dbmeta_key
);
if
(
db
==
NULL
)
{
std
::
cout
<<
"db == NULL"
<<
std
::
endl
;
return
backupOnionSelection
(
0
);
}
//get tableMeta
const
std
::
unique_ptr
<
IdentityMetaKey
>
tbMeta_key
(
new
IdentityMetaKey
(
table
));
TableMeta
*
tbMeta
=
(
*
db
).
getChild
(
*
tbMeta_key
);
if
(
tbMeta
==
NULL
){
std
::
cout
<<
"tb == NULL"
<<
std
::
endl
;
return
backupOnionSelection
(
0
);
}
//get fieldMeta(we only need size here)
const
auto
&
fields
=
tbMeta
->
getChildren
();
//one Olk for each field
backupOnionSelection
curBack
(
fields
.
size
());
int
fieldIndex
=
0
;
//according to uniqueCounter
for
(
FieldMeta
*
field
:
tbMeta
->
orderedFieldMetas
()){
curBack
.
fieldSize
[
fieldIndex
]
=
field
->
getChildren
().
size
()
+
1
;
curBack
.
onionIndex
[
fieldIndex
]
=
0
;
fieldIndex
+=
1
;
}
//complete curBack
int
num
=
curBack
.
numOfFields
;
int
add
=
0
;
for
(
int
i
=
0
;
i
<
num
;
i
++
){
int
cur
=
curBack
.
fieldSize
[
i
];
curBack
.
onionIndex
[
i
]
=
add
;
add
+=
cur
;
curBack
.
saltIndex
[
i
]
=
add
-
1
;
}
assert
(
num
=
curBack
.
saltIndex
.
size
());
assert
(
num
=
curBack
.
onionIndex
.
size
());
return
curBack
;
}
static
std
::
string
logicBackUp
(
std
::
string
database
,
std
::
string
table
,
SchemaInfo
&
schema
)
{
//do not use factory to construct IdentityMetaKey, it's used only upon serial data.
const
std
::
unique_ptr
<
IdentityMetaKey
>
dbmeta_key
(
new
IdentityMetaKey
(
database
));
//get databaseMeta, search in the map
DatabaseMeta
*
db
=
schema
.
getChild
(
*
dbmeta_key
);
if
(
db
==
NULL
)
{
std
::
cout
<<
"db == NULL"
<<
std
::
endl
;
return
""
;
}
//get tableMeta
const
std
::
unique_ptr
<
IdentityMetaKey
>
tbMeta_key
(
new
IdentityMetaKey
(
table
));
TableMeta
*
tbMeta
=
(
*
db
).
getChild
(
*
tbMeta_key
);
if
(
tbMeta
==
NULL
){
std
::
cout
<<
"tb == NULL"
<<
std
::
endl
;
return
""
;
}
//construct OLKs for each field!!
backupOnionSelection
curBack
=
generateBackupStrategy
(
database
,
table
,
schema
);
std
::
string
logicTableQuery
=
std
::
string
(
"SHOW create table "
+
database
+
"."
)
+
\
std
::
string
(
tbMeta
->
getAnonTableName
());
auto
res2
=
executeAndGetResultRemote
(
globalConn
,
logicTableQuery
);
assert
(
res2
.
rowValues
.
size
()
==
1
);
std
::
vector
<
std
::
string
>
oneRow
=
res2
.
rowValues
[
0
];
//modify and get the create table command.
getCreateTable
(
oneRow
[
1
],
curBack
);
//then create SELECT command,based on the curBack
std
::
string
selectQuery
=
generateSelectQuery
(
database
,
table
,
schema
,
curBack
);
auto
res3
=
executeAndGetResultRemote
(
globalConn
,
selectQuery
);
generateInsertQuery
(
res3
,
tbMeta
->
getAnonTableName
());
return
selectQuery
;
}
static
void
startBack
(){
return
;
//only for testing backup module
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
();
processSchemaInfo
(
*
schema
);
std
::
cout
<<
"please input dbname:####"
<<
std
::
endl
;
std
::
string
dbname
;
std
::
cin
>>
dbname
;
std
::
cout
<<
"please input tableame:####"
<<
std
::
endl
;
std
::
string
tablename
;
std
::
cin
>>
tablename
;
backupOnionSelection
curBack
=
generateBackupStrategy
(
dbname
,
tablename
,
*
schema
);
std
::
shared_ptr
<
ReturnMeta
>
rmeta
=
myGetReturnMeta
(
dbname
,
tablename
,
*
schema
,
curBack
);
std
::
string
selectQuery
=
logicBackUp
(
dbname
,
tablename
,
*
schema
);
auto
res3
=
executeAndGetResultRemote
(
globalConn
,
selectQuery
);
const
auto
dres
=
MygetResTypeFromLuaTable
(
false
,
&
res3
);
if
(
rmeta
.
get
()
!=
NULL
){
std
::
cout
<<
"decrypted results !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
<<
std
::
endl
;
ResType
deResType
=
decryptResults
(
dres
,
*
rmeta
);
parseResType
(
deResType
);
std
::
cout
<<
"decrypted results !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
<<
std
::
endl
;
}
}
}*/
static
std
::
shared_ptr
<
ReturnMeta
>
getReturnMeta
(
std
::
vector
<
FieldMeta
*>
fms
,
std
::
vector
<
transField
>
&
tfds
){
...
...
@@ -999,8 +481,6 @@ std::string getBackupQuery(SchemaInfo &schema, std::vector<transField> &tfds,std
}
}
res
=
res
.
substr
(
0
,
res
.
size
()
-
2
);
res
=
res
+
"FROM `"
+
db
+
std
::
string
(
"`.`"
)
+
annotablename
+
"`"
;
return
res
;
}
...
...
@@ -1051,18 +531,14 @@ main() {
std
::
string
curQuery
=
"SHOW DATABASES;"
;
std
::
cout
<<
"please input a new query:######################################################"
<<
std
::
endl
;
std
::
getline
(
std
::
cin
,
curQuery
);
unsigned
long
long
_thread_id
=
globalConn
->
get_thread_id
();
//
unsigned long long _thread_id = globalConn->get_thread_id();
while
(
curQuery
!=
"quit"
){
if
(
curQuery
.
size
()
==
0
){
std
::
cout
<<
std
::
endl
;
std
::
getline
(
std
::
cin
,
curQuery
);
continue
;
}
if
(
curQuery
==
"back1"
){
startBack
();
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
();
processSchemaInfo
(
*
schema
);
}
else
if
(
curQuery
==
"back"
){
if
(
curQuery
==
"back"
){
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
();
std
::
vector
<
FieldMeta
*>
fms
=
getFieldMeta
(
*
schema
);
auto
res
=
getTransField
(
fms
);
...
...
@@ -1076,9 +552,6 @@ main() {
ResType
rawtorestype
=
MygetResTypeFromLuaTable
(
false
,
&
resraw
);
auto
finalresults
=
decryptResults
(
rawtorestype
,
*
rm
);
parseResType
(
finalresults
);
}
else
{
std
::
cout
<<
GREEN_BEGIN
<<
"curQuery: "
<<
curQuery
<<
"
\n
"
<<
COLOR_END
<<
std
::
endl
;
batchTogether
(
client
,
curQuery
,
_thread_id
);
}
std
::
cout
<<
GREEN_BEGIN
<<
"
\n
please input a new query:#######"
<<
COLOR_END
<<
std
::
endl
;
std
::
getline
(
std
::
cin
,
curQuery
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment