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
23c57509
Commit
23c57509
authored
Apr 14, 2017
by
casualet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add foreign key support in create tabel hadner
parent
89dafe74
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
141 additions
and
81 deletions
+141
-81
Analysis.cc
main/Analysis.cc
+19
-15
Analysis.hh
main/Analysis.hh
+15
-0
Makefrag
main/Makefrag
+2
-2
cdb_test.cc
main/cdb_test.cc
+17
-8
ddl_handler.cc
main/ddl_handler.cc
+4
-25
ddl_handler.hh
main/ddl_handler.hh
+14
-3
rewrite_main.cc
main/rewrite_main.cc
+17
-2
rewrite_util.cc
main/rewrite_util.cc
+49
-22
rewrite_util.hh
main/rewrite_util.hh
+1
-1
schema.cc
main/schema.cc
+3
-3
No files found.
main/Analysis.cc
View file @
23c57509
...
...
@@ -388,12 +388,10 @@ SharedProxyState::SharedProxyState(ConnectionInfo ci,
cache
(
std
::
move
(
SchemaCache
()))
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
// make sure the server was not started in SQL_SAFE_UPDATES mode
// > it might not even be possible to start the server in this mode;
// better to be safe
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
std
::
unique_ptr
<
DBResult
>
dbres
;
assert
(
conn
->
execute
(
"SELECT @@sql_safe_updates"
,
&
dbres
));
assert
(
1
==
mysql_num_rows
(
dbres
->
n
));
...
...
@@ -799,36 +797,48 @@ OnionMeta &Analysis::getOnionMeta(const std::string &db,
const
std
::
string
&
field
,
onion
o
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
return
this
->
getOnionMeta
(
this
->
getFieldMeta
(
db
,
table
,
field
),
o
);
}
OnionMeta
&
Analysis
::
getOnionMeta
(
const
FieldMeta
&
fm
,
onion
o
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
OnionMeta
*
const
om
=
fm
.
getOnionMeta
(
o
);
TEST_IdentifierNotFound
(
om
,
TypeText
<
onion
>::
toText
(
o
));
//TEST_IdentifierNotFound(om, TypeText<onion>::toText(o));
return
*
om
;
}
OnionMeta
*
Analysis
::
getOnionMeta2
(
const
FieldMeta
&
fm
,
onion
o
)
const
{
OnionMeta
*
const
om
=
fm
.
getOnionMeta
(
o
);
//TEST_IdentifierNotFound(om, TypeText<onion>::toText(o));
return
om
;
}
OnionMeta
*
Analysis
::
getOnionMeta2
(
const
std
::
string
&
db
,
const
std
::
string
&
table
,
const
std
::
string
&
field
,
onion
o
)
const
{
return
this
->
getOnionMeta2
(
this
->
getFieldMeta
(
db
,
table
,
field
),
o
);
}
FieldMeta
&
Analysis
::
getFieldMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
table
,
const
std
::
string
&
field
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
FieldMeta
*
const
fm
=
this
->
getTableMeta
(
db
,
table
).
getChild
(
IdentityMetaKey
(
field
));
TEST_IdentifierNotFound
(
fm
,
field
);
return
*
fm
;
}
FieldMeta
&
Analysis
::
getFieldMeta
(
const
TableMeta
&
tm
,
const
std
::
string
&
field
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
FieldMeta
*
const
fm
=
tm
.
getChild
(
IdentityMetaKey
(
field
));
TEST_IdentifierNotFound
(
fm
,
field
);
...
...
@@ -838,7 +848,6 @@ FieldMeta &Analysis::getFieldMeta(const TableMeta &tm,
TableMeta
&
Analysis
::
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
table
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
const
DatabaseMeta
&
dm
=
this
->
getDatabaseMeta
(
db
);
TableMeta
*
const
tm
=
...
...
@@ -851,7 +860,6 @@ TableMeta &Analysis::getTableMeta(const std::string &db,
DatabaseMeta
&
Analysis
::
getDatabaseMeta
(
const
std
::
string
&
db
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
DatabaseMeta
*
const
dm
=
this
->
schema
.
getChild
(
IdentityMetaKey
(
db
));
TEST_DatabaseNotFound
(
dm
,
db
);
...
...
@@ -867,7 +875,6 @@ bool Analysis::tableMetaExists(const std::string &db,
bool
Analysis
::
nonAliasTableMetaExists
(
const
std
::
string
&
db
,
const
std
::
string
&
table
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
const
DatabaseMeta
&
dm
=
this
->
getDatabaseMeta
(
db
);
return
dm
.
childExists
(
IdentityMetaKey
(
table
));
}
...
...
@@ -876,7 +883,6 @@ bool Analysis::nonAliasTableMetaExists(const std::string &db,
bool
Analysis
::
databaseMetaExists
(
const
std
::
string
&
db
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
return
this
->
schema
.
childExists
(
IdentityMetaKey
(
db
));
}
...
...
@@ -901,7 +907,6 @@ Analysis::translateNonAliasPlainToAnonTableName(const std::string &db,
const
std
::
string
&
table
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
TableMeta
*
const
tm
=
this
->
getDatabaseMeta
(
db
).
getChild
(
IdentityMetaKey
(
table
));
TEST_IdentifierNotFound
(
tm
,
table
);
...
...
@@ -940,7 +945,6 @@ bool Analysis::isAlias(const std::string &db,
std
::
string
Analysis
::
unAliasTable
(
const
std
::
string
&
db
,
const
std
::
string
&
table
)
const
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
auto
db_alias_pair
=
table_aliases
.
find
(
db
);
if
(
table_aliases
.
end
()
==
db_alias_pair
)
{
return
table
;
...
...
main/Analysis.hh
View file @
23c57509
...
...
@@ -300,15 +300,24 @@ public:
OnionMeta
&
getOnionMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
table
,
const
std
::
string
&
field
,
onion
o
)
const
;
OnionMeta
*
getOnionMeta2
(
const
std
::
string
&
db
,
const
std
::
string
&
table
,
const
std
::
string
&
field
,
onion
o
)
const
;
OnionMeta
&
getOnionMeta
(
const
FieldMeta
&
fm
,
onion
o
)
const
;
OnionMeta
*
getOnionMeta2
(
const
FieldMeta
&
fm
,
onion
o
)
const
;
FieldMeta
&
getFieldMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
table
,
const
std
::
string
&
field
)
const
;
FieldMeta
&
getFieldMeta
(
const
TableMeta
&
tm
,
const
std
::
string
&
field
)
const
;
TableMeta
&
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
table
)
const
;
DatabaseMeta
&
getDatabaseMeta
(
const
std
::
string
&
db
)
const
;
bool
tableMetaExists
(
const
std
::
string
&
db
,
const
std
::
string
&
table
)
const
;
bool
nonAliasTableMetaExists
(
const
std
::
string
&
db
,
...
...
@@ -317,10 +326,12 @@ public:
std
::
string
getAnonTableName
(
const
std
::
string
&
db
,
const
std
::
string
&
table
,
bool
*
const
is_alias
=
NULL
)
const
;
std
::
string
translateNonAliasPlainToAnonTableName
(
const
std
::
string
&
db
,
const
std
::
string
&
table
)
const
;
std
::
string
getAnonIndexName
(
const
std
::
string
&
db
,
const
std
::
string
&
table
,
const
std
::
string
&
index_name
,
...
...
@@ -328,16 +339,20 @@ public:
std
::
string
getAnonIndexName
(
const
TableMeta
&
tm
,
const
std
::
string
&
index_name
,
onion
o
)
const
;
static
const
EncLayer
&
getBackEncLayer
(
const
OnionMeta
&
om
);
static
SECLEVEL
getOnionLevel
(
const
OnionMeta
&
om
);
SECLEVEL
getOnionLevel
(
const
FieldMeta
&
fm
,
onion
o
);
static
const
std
::
vector
<
std
::
unique_ptr
<
EncLayer
>
>
&
getEncLayers
(
const
OnionMeta
&
om
);
const
SchemaInfo
&
getSchema
()
const
{
return
schema
;}
std
::
vector
<
std
::
unique_ptr
<
Delta
>
>
deltas
;
std
::
string
getDatabaseName
()
const
{
return
db_name
;}
const
std
::
unique_ptr
<
AES_KEY
>
&
getMasterKey
()
const
{
return
master_key
;}
SECURITY_RATING
getDefaultSecurityRating
()
const
{
return
default_sec_rating
;}
...
...
main/Makefrag
View file @
23c57509
...
...
@@ -7,7 +7,7 @@ CRYPTDB_SRCS := schema.cc Translator.cc Connect.cc \
rewrite_func.cc rewrite_sum.cc metadata_tables.cc \
error.cc stored_procedures.cc rewrite_ds.cc rewrite_main.cc
CRYPTDB_PROGS:=
cdb_test MyBack
CRYPTDB_PROGS:=
CRYPTDBPROGOBJS := $(patsubst %,$(OBJDIR)/main/%,$(CRYPTDB_PROGS))
...
...
@@ -27,7 +27,7 @@ $(OBJDIR)/libcryptdb.so: $(CRYPTDB_OBJS) \
$(OBJDIR)/libedbcrypto.so \
$(OBJDIR)/libedbutil.so \
$(OBJDIR)/libedbparser.so
$(CXX) -shared -o $@ $(CRYPTDB_OBJS) $(LDFLAGS) $(LDRPATH) \
$(CXX) -shared -
g -
o $@ $(CRYPTDB_OBJS) $(LDFLAGS) $(LDRPATH) \
-ledbcrypto -ledbutil -ledbparser -lntl -lcrypto
install: install_main
...
...
main/cdb_test.cc
View file @
23c57509
...
...
@@ -46,6 +46,8 @@
FILE
*
fr
,
*
fw
;
static
std
::
string
embeddedDir
=
"/t/cryt/shadow"
;
//My WrapperState.
...
...
@@ -94,6 +96,7 @@ struct rawReturnValue{
};
struct
backupOnionSelection
{
int
numOfFields
;
std
::
vector
<
int
>
fieldSize
;
...
...
@@ -375,7 +378,6 @@ static void processTableMeta(const TableMeta &table){
static
void
processDatabaseMeta
(
const
DatabaseMeta
&
db
)
{
std
::
cout
<<
GREEN_BEGIN
<<
"PRINT DatabaseMeta"
<<
COLOR_END
<<
std
::
endl
;
for
(
const
auto
&
table
:
db
.
getChildren
()){
// std::cout<<table.second->getDatabaseID()<<":"<<table.first.getValue()<<std::endl;
processTableMeta
(
*
(
table
.
second
));
}
}
...
...
@@ -889,17 +891,24 @@ main() {
std
::
getline
(
std
::
cin
,
curQuery
);
continue
;
}
if
(
curQuery
==
"back"
){
startBack
();
}
else
{
std
::
cout
<<
GREEN_BEGIN
<<
"curQuery: "
<<
curQuery
<<
"
\n
"
<<
COLOR_END
<<
std
::
endl
;
batchTogether
(
client
,
curQuery
,
_thread_id
);
}
/*
if(curQuery=="back"){
startBack();
}else{
std::cout<<GREEN_BEGIN<<"curQuery: "<<curQuery<<"\n"<<COLOR_END<<std::endl;
batchTogether(client,curQuery,_thread_id);
}*/
std
::
unique_ptr
<
SchemaInfo
>
schema
=
myLoadSchemaInfo
();
processSchemaInfo
(
*
schema
);
std
::
cout
<<
GREEN_BEGIN
<<
"
\n
please input a new query:#######"
<<
COLOR_END
<<
std
::
endl
;
std
::
getline
(
std
::
cin
,
curQuery
);
}
fclose
(
fr
);
fclose
(
fw
);
return
0
;
...
...
main/ddl_handler.cc
View file @
23c57509
...
...
@@ -15,9 +15,8 @@
//a list of ddl handlers, buildddlhandler, and ddlexecutor
//################################################################Create table handler#########################################################################################
class
CreateTableHandler
:
public
DDLHandler
{
virtual
AbstractQueryExecutor
*
rewriteAndUpdate
(
Analysis
&
a
,
LEX
*
lex
,
const
Preamble
&
pre
)
const
AbstractQueryExecutor
*
CreateTableHandler
::
rewriteAndUpdate
(
Analysis
&
a
,
LEX
*
lex
,
const
Preamble
&
pre
)
const
{
assert
(
a
.
deltas
.
size
()
==
0
);
...
...
@@ -87,13 +86,11 @@ class CreateTableHandler : public DDLHandler {
return
createAndRewriteField
(
a
,
cf
,
tm
.
get
(),
true
,
key_data
,
out_list
);
});
// -----------------------------
// Rewrite INDEX
// -----------------------------
highLevelRewriteKey
(
*
tm
.
get
(),
*
lex
,
new_lex
,
a
);
highLevelRewriteForeignKey
(
*
tm
.
get
(),
*
lex
,
new_lex
,
a
);
highLevelRewriteForeignKey
(
*
tm
.
get
(),
*
lex
,
new_lex
,
a
,
pre
.
table
);
// -----------------------------
// Update TABLE
// -----------------------------
...
...
@@ -103,36 +100,18 @@ class CreateTableHandler : public DDLHandler {
a
.
getDatabaseMeta
(
pre
.
dbname
),
IdentityMetaKey
(
pre
.
table
))));
}
else
{
// Table already exists.
// Make sure we aren't trying to create a table that
// already exists.
const
bool
test
=
lex
->
create_info
.
options
&
HA_LEX_CREATE_IF_NOT_EXISTS
;
TEST_TextMessageError
(
test
,
"Table "
+
pre
.
table
+
" already exists!"
);
//why still rewrite here???
// -----------------------------
// Rewrite TABLE
// -----------------------------
//这部分在exists的时候, 没有被执行!!!,但是如何抛出一场返回给客户端信息呢?
new_lex
->
select_lex
.
table_list
=
rewrite_table_list
(
lex
->
select_lex
.
table_list
,
a
);
// > We do not rewrite the fields because presumably the caller
// can do a CREATE TABLE IF NOT EXISTS for a table that already
// exists, but with fields that do not actually exist.
// > This would cause problems when trying to look up FieldMeta
// for these non-existant fields.
// > We may want to do some additional non-deterministic
// anonymization of the fieldnames to prevent information leaks.
// (ie, server gets compromised, server logged all sql queries,
// attacker can see that the admin creates the account table
// with the credit card field every time the server boots)
}
//在handler的第一阶段, 通过analysis搜集delta以及执行计划等内容, 然后在第二阶段, 实行delta以及
//执行计划, 新的lex里面包含了改写以后的语句, 直接转化成string就可以用了.
return
new
DDLQueryExecutor
(
*
new_lex
,
std
::
move
(
a
.
deltas
));
}
};
...
...
main/ddl_handler.hh
View file @
23c57509
...
...
@@ -9,13 +9,14 @@
#include <sql_lex.h>
class
DDLQueryExecutor
:
public
AbstractQueryExecutor
{
const
std
::
string
new_query
;
const
std
::
vector
<
std
::
unique_ptr
<
Delta
>
>
deltas
;
AssignOnce
<
ResType
>
ddl_res
;
AssignOnce
<
uint64_t
>
embedded_completion_id
;
public
:
const
std
::
string
new_query
;
DDLQueryExecutor
(
const
LEX
&
new_lex
,
std
::
vector
<
std
::
unique_ptr
<
Delta
>
>
&&
deltas
)
:
new_query
(
lexToQuery
(
new_lex
)),
deltas
(
std
::
move
(
deltas
))
{}
...
...
@@ -24,6 +25,7 @@ public:
nextImpl
(
const
ResType
&
res
,
const
NextParams
&
nparams
);
private
:
const
std
::
vector
<
std
::
unique_ptr
<
Delta
>
>
deltas
;
bool
stales
()
const
{
return
true
;}
bool
usesEmbedded
()
const
{
return
true
;}
};
...
...
@@ -37,11 +39,20 @@ public:
private
:
virtual
AbstractQueryExecutor
*
rewriteAndUpdate
(
Analysis
&
a
,
LEX
*
lex
,
const
Preamble
&
pre
)
const
=
0
;
protected
:
DDLHandler
()
{;}
virtual
~
DDLHandler
()
{;}
};
class
CreateTableHandler
:
public
DDLHandler
{
//must rewrite the header here or we get pure virtual function
virtual
AbstractQueryExecutor
*
rewriteAndUpdate
(
Analysis
&
a
,
LEX
*
lex
,
const
Preamble
&
pre
)
const
;
};
SQLDispatcher
*
buildDDLDispatcher
();
main/rewrite_main.cc
View file @
23c57509
...
...
@@ -58,6 +58,7 @@ std::string global_crash_point = "";
void
crashTest
(
const
std
::
string
&
current_point
)
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
if
(
current_point
==
global_crash_point
)
{
throw
CrashTestException
();
}
...
...
@@ -66,6 +67,7 @@ crashTest(const std::string ¤t_point) {
static
inline
std
::
string
extract_fieldname
(
Item_field
*
const
i
)
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
std
::
stringstream
fieldtemp
;
fieldtemp
<<
*
i
;
return
fieldtemp
.
str
();
...
...
@@ -74,6 +76,7 @@ extract_fieldname(Item_field *const i)
static
bool
sanityCheck
(
FieldMeta
&
fm
)
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
for
(
const
auto
&
it
:
fm
.
getChildren
())
{
OnionMeta
*
const
om
=
it
.
second
.
get
();
const
onion
o
=
it
.
first
.
getValue
();
...
...
@@ -90,7 +93,9 @@ sanityCheck(FieldMeta &fm)
static
bool
sanityCheck
(
TableMeta
&
tm
)
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
for
(
const
auto
&
it
:
tm
.
getChildren
())
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
const
auto
&
fm
=
it
.
second
;
assert
(
sanityCheck
(
*
fm
.
get
()));
}
...
...
@@ -100,7 +105,9 @@ sanityCheck(TableMeta &tm)
static
bool
sanityCheck
(
DatabaseMeta
&
dm
)
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
for
(
const
auto
&
it
:
dm
.
getChildren
())
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const
auto
&
tm
=
it
.
second
;
assert
(
sanityCheck
(
*
tm
.
get
()));
}
...
...
@@ -110,7 +117,9 @@ sanityCheck(DatabaseMeta &dm)
static
bool
sanityCheck
(
SchemaInfo
&
schema
)
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
for
(
const
auto
&
it
:
schema
.
getChildren
())
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
const
auto
&
dm
=
it
.
second
;
assert
(
sanityCheck
(
*
dm
.
get
()));
}
...
...
@@ -121,6 +130,7 @@ static std::map<std::string, int>
collectTableNames
(
const
std
::
string
&
db_name
,
const
std
::
unique_ptr
<
Connect
>
&
c
)
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
std
::
map
<
std
::
string
,
int
>
name_map
;
assert
(
c
->
execute
(
"USE "
+
quoteText
(
db_name
)));
...
...
@@ -148,6 +158,7 @@ tablesSanityCheck(SchemaInfo &schema,
const
std
::
unique_ptr
<
Connect
>
&
e_conn
,
const
std
::
unique_ptr
<
Connect
>
&
conn
)
{
// std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std::endl<<std::endl;
for
(
const
auto
&
dm_it
:
schema
.
getChildren
())
{
const
auto
&
db_name
=
dm_it
.
first
.
getValue
();
std
::
cout
<<
"db_name: "
<<
db_name
<<
std
::
endl
;
...
...
@@ -204,6 +215,7 @@ collectRecoveryDetails(const std::unique_ptr<Connect> &conn,
unsigned
long
unfinished_id
,
std
::
unique_ptr
<
RecoveryDetails
>
*
details
)
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
// collect completion data
std
::
unique_ptr
<
DBResult
>
dbres
;
const
std
::
string
&
embedded_completion_q
=
...
...
@@ -1343,17 +1355,20 @@ Rewriter::dispatchOnLex(Analysis &a, const std::string &query)
QueryRewrite
Rewriter
::
rewrite
(
const
std
::
string
&
q
,
const
SchemaInfo
&
schema
,
const
std
::
string
&
default_db
,
const
ProxyState
&
ps
){
const
std
::
string
&
default_db
,
const
ProxyState
&
ps
)
{
LOG
(
cdb_v
)
<<
"q "
<<
q
;
assert
(
0
==
mysql_thread_init
());
Analysis
analysis
(
default_db
,
schema
,
ps
.
getMasterKey
(),
ps
.
defaultSecurityRating
());
// NOTE: Care what data you try to read from Analysis
// at this height.
AbstractQueryExecutor
*
const
executor
=
Rewriter
::
dispatchOnLex
(
analysis
,
q
);
if
(
!
executor
)
{
std
::
cout
<<
"we return noopexecutor here"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
;
return
QueryRewrite
(
true
,
analysis
.
rmeta
,
analysis
.
kill_zone
,
new
NoOpExecutor
());
}
...
...
main/rewrite_util.cc
View file @
23c57509
...
...
@@ -352,7 +352,15 @@ rewrite_key(const TableMeta &tm, const Key &key, const Analysis &a)
static
std
::
vector
<
Key
*>
rewrite_key1
(
const
TableMeta
&
tm
,
const
Key
&
key
,
const
Analysis
&
a
)
{
//leave foreign key unchanged
std
::
vector
<
Key
*>
output_keys
;
if
(
key
.
type
==
Key
::
FOREIGN_KEY
){
THD
*
cthd
=
current_thd
;
Key
*
const
new_key
=
key
.
clone
(
cthd
->
mem_root
);
output_keys
.
push_back
(
new_key
);
return
output_keys
;
}
//从左到右分别是三种类型: oOPE, oDET, oPLAIN, 对于每个语句的index都是这样
//比如自己要alter table add 的index, 其对应index的名字, 以及相关的column信息
...
...
@@ -361,6 +369,7 @@ rewrite_key1(const TableMeta &tm, const Key &key, const Analysis &a)
for
(
auto
onion_it
:
key_onions
)
{
const
onion
o
=
onion_it
;
THD
*
cthd
=
current_thd
;
//原始key的拷贝
Key
*
const
new_key
=
key
.
clone
(
cthd
->
mem_root
);
//通过key的原始名字+onion+tm哈希获得新的key名字,用的是std::hash<string>算法.
...
...
@@ -444,24 +453,27 @@ highLevelRewriteKey(const TableMeta &tm, const LEX &seed_lex,
}
void
highLevelRewriteForeignKey
(
const
TableMeta
&
tm
,
const
LEX
&
seed_lex
,
LEX
*
const
out_lex
,
const
Analysis
&
a
){
highLevelRewriteForeignKey
(
const
TableMeta
&
tm
,
const
LEX
&
seed_lex
,
LEX
*
const
out_lex
,
const
Analysis
&
a
,
std
::
string
tbname
){
std
::
string
dbname
=
a
.
getDatabaseName
();
auto
it
=
List_iterator
<
Key
>
(
out_lex
->
alter_info
.
key_list
);
std
::
vector
<
Key
*>
output_keys
;
while
(
auto
cur
=
it
++
){
if
(
cur
->
type
==
Key
::
FOREIGN_KEY
){
THD
*
cthd
=
current_thd
;
THD
*
cthd
=
current_thd
;
//process current names
Key
*
const
new_key
=
cur
->
clone
(
cthd
->
mem_root
);
std
::
string
new_name
=
"newfk"
;
std
::
string
new_name
=
"newfk
name
"
;
new_key
->
name
=
string_to_lex_str
(
new_name
);
//process current columns
auto
col_it_cur
=
List_iterator
<
Key_part_spec
>
((
cur
->
columns
));
auto
col_it_cur
=
List_iterator
<
Key_part_spec
>
((
cur
->
columns
));
new_key
->
columns
.
empty
();
/* while(1){
while
(
1
){
const
Key_part_spec
*
const
key_part
=
col_it_cur
++
;
if
(
NULL
==
key_part
){
break
;
...
...
@@ -469,10 +481,25 @@ highLevelRewriteForeignKey( const TableMeta &tm, const LEX &seed_lex,
Key_part_spec
*
const
new_key_part
=
copyWithTHD
(
key_part
);
std
::
string
field_name
=
convert_lex_str
(
new_key_part
->
field_name
);
field_name=std::string("curadd+")+field_name;
//get current field name, and then replace it with one onionname here
//currently we choose det onion, without caring about the layers
//OnionMeta *om = a.getOnionMeta2(dbname,tbname,field_name,oDET);
OnionMeta
*
om
=
tm
.
getChild
(
IdentityMetaKey
(
field_name
))
->
getOnionMeta
(
oOPE
);
assert
(
om
!=
NULL
);
field_name
=
om
->
getAnonOnionName
();
new_key_part
->
field_name
=
string_to_lex_str
(
field_name
);
new_key
->
columns
.
push_back
(
new_key_part
);
}
//process ref tables
Table_ident
*
ref_table
=
((
Foreign_key
*
)
cur
)
->
ref_table
;
std
::
string
ref_table_name
=
std
::
string
(
ref_table
->
table
.
str
,
ref_table
->
table
.
length
);
TableMeta
&
rtm
=
a
.
getTableMeta
(
a
.
getDatabaseName
(),
ref_table_name
);
std
::
string
ref_table_annoname
=
rtm
.
getAnonTableName
();
ref_table
->
table
=
string_to_lex_str
(
ref_table_annoname
);
//process ref columns
auto
col_it
=
List_iterator
<
Key_part_spec
>
(((
Foreign_key
*
)
cur
)
->
ref_columns
);
...
...
@@ -485,23 +512,27 @@ highLevelRewriteForeignKey( const TableMeta &tm, const LEX &seed_lex,
Key_part_spec
*
const
new_key_part
=
copyWithTHD
(
key_part
);
std
::
string
field_name
=
convert_lex_str
(
new_key_part
->
field_name
);
field_name=std::string("refadd")+field_name;
//update field name here
OnionMeta
*
om
=
a
.
getOnionMeta2
(
dbname
,
ref_table_name
,
field_name
,
oOPE
);
assert
(
om
!=
NULL
);
field_name
=
om
->
getAnonOnionName
();
new_key_part
->
field_name
=
string_to_lex_str
(
field_name
);
((
Foreign_key
*
)
new_key
)
->
ref_columns
.
push_back
(
new_key_part
);
}
//process ref tables
Table_ident* ref_table = ((Foreign_key*)cur)->ref_table;
//Table_ident* new_ref_table = ref_table->clone(cthd->mem_root);
ref_table->table = string_to_lex_str(std::string("hehe_ref"));
//((Foreign_key*)new_key)->ref_table = new_ref_table;
output_keys
.
push_back
(
new_key
);
}
else
{
THD
*
cthd
=
current_thd
;
Key
*
const
new_key
=
cur
->
clone
(
cthd
->
mem_root
);
output_keys
.
push_back
(
new_key
);
*/
}
}
lex
->
alter_info
.
key_list
=
*
vectorToListWithTHD
(
output_keys
);
return
lex
;
out_
lex
->
alter_info
.
key_list
=
*
vectorToListWithTHD
(
output_keys
);
}
...
...
@@ -565,14 +596,12 @@ createAndRewriteField(Analysis &a, Create_field * const cf,
fm
(
new
FieldMeta
(
*
cf
,
a
.
getMasterKey
().
get
(),
a
.
getDefaultSecurityRating
(),
tm
->
leaseCount
(),
isUnique
(
name
,
key_data
)));
// -----------------------------
// Rewrite FIELD
// -----------------------------
//for each onion, we have new fields and salts, salts have long long type
const
auto
new_fields
=
rewrite_create_field
(
fm
.
get
(),
cf
,
a
);
rewritten_cfield_list
.
concat
(
vectorToListWithTHD
(
new_fields
));
// -----------------------------
// Update FIELD
// -----------------------------
...
...
@@ -596,7 +625,6 @@ createAndRewriteField(Analysis &a, Create_field * const cf,
Item
*
encrypt_item_layers
(
const
Item
&
i
,
onion
o
,
const
OnionMeta
&
om
,
const
Analysis
&
a
,
uint64_t
IV
)
{
std
::
cout
<<
__PRETTY_FUNCTION__
<<
":"
<<
__LINE__
<<
":"
<<
__FILE__
<<
":"
<<
__LINE__
<<
std
::
endl
<<
std
::
endl
;
assert
(
!
RiboldMYSQL
::
is_null
(
i
));
//这里是onionMeta中的vector, enclayers.也就是洋葱不同层次的加解密通过Onionmeta以及
//encLary中的加解密算法来完成.
...
...
@@ -613,7 +641,6 @@ std::cout<<__PRETTY_FUNCTION__<<":"<<__LINE__<<":"<<__FILE__<<":"<<__LINE__<<std
assert
(
new_enc
);
enc
=
new_enc
;
}
// @i is const, do we don't want the caller to modify it accidentally.
assert
(
new_enc
&&
new_enc
!=
&
i
);
return
new_enc
;
...
...
main/rewrite_util.hh
View file @
23c57509
...
...
@@ -56,7 +56,7 @@ highLevelRewriteKey(const TableMeta &tm, const LEX &seed_lex,
//added
void
highLevelRewriteForeignKey
(
const
TableMeta
&
tm
,
const
LEX
&
seed_lex
,
LEX
*
const
out_lex
,
const
Analysis
&
a
);
LEX
*
const
out_lex
,
const
Analysis
&
a
,
std
::
string
tbname
);
std
::
string
...
...
main/schema.cc
View file @
23c57509
...
...
@@ -286,10 +286,12 @@ init_onions_layout(const AES_KEY *const m_key, FieldMeta *const fm,
const
onionlayout
onion_layout
=
fm
->
getOnionLayout
();
if
(
fm
->
getHasSalt
()
!=
(
static_cast
<
bool
>
(
m_key
)
&&
PLAIN_ONION_LAYOUT
!=
onion_layout
))
{
std
::
cout
<<
"unable to get salt?"
<<
std
::
endl
;
return
false
;
}
if
(
0
!=
fm
->
getChildren
().
size
())
{
std
::
cout
<<
"already has children"
<<
std
::
endl
;
return
false
;
}
...
...
@@ -331,6 +333,7 @@ FieldMeta::FieldMeta(const Create_field &field,
sec_rating
(
sec_rating
),
uniq_count
(
uniq_count
),
counter
(
0
),
has_default
(
determineHasDefault
(
field
)),
default_value
(
determineDefaultValue
(
has_default
,
field
))
{
TEST_TextMessageError
(
init_onions_layout
(
m_key
,
this
,
field
,
unique
),
"Failed to build onions for new FieldMeta!"
);
}
...
...
@@ -409,10 +412,8 @@ onionlayout FieldMeta::determineOnionLayout(const AES_KEY *const m_key,
// assert(!m_key);
return
PLAIN_ONION_LAYOUT
;
}
TEST_TextMessageError
(
m_key
,
"Should be using SECURITY_RATING::PLAIN!"
);
if
(
false
==
encryptionSupported
(
f
))
{
std
::
cout
<<
"encryption not supported for this field, remain plain"
<<
std
::
endl
;
//TEST_TextMessageError(SECURITY_RATING::SENSITIVE != sec_rating,
...
...
@@ -425,7 +426,6 @@ onionlayout FieldMeta::determineOnionLayout(const AES_KEY *const m_key,
if
(
Field
::
NEXT_NUMBER
==
f
.
unireg_check
)
{
return
PLAIN_ONION_LAYOUT
;
}
if
(
SECURITY_RATING
::
SENSITIVE
==
sec_rating
)
{
if
(
true
==
isMySQLTypeNumeric
(
f
))
{
return
NUM_ONION_LAYOUT
;
...
...
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