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