Commit d6fe6757 authored by yiwenshao's avatar yiwenshao

add comments

parent a7eb58f6
......@@ -4,9 +4,9 @@
#oASHE: ASHE
[onions for num]
oDET: DETJOIN DET RND
oOPE: OPE
#oOPE: OPE
#oAGG: HOM
oASHE: ASHE
#oASHE: ASHE
[end]
......
......@@ -386,9 +386,9 @@ SharedProxyState::SharedProxyState(ConnectionInfo ci,
const std::string prefix =
getenv("CRYPTDB_NAME") ? getenv("CRYPTDB_NAME")
: "generic_prefix_";
//初始化embedded的表
//init embedded mysql tables
assert(MetaData::initialize(conn, init_e_conn, prefix));
//两头的defaultdb是一样的
//sychronize the default embedded db and remote db
TEST_TextMessageError(synchronizeDatabases(conn, init_e_conn),
"Failed to synchronize embedded and remote"
" databases!");
......
......@@ -114,7 +114,7 @@ public:
void safeCreateEmbeddedTHD();
void dumpTHDs();
const SchemaCache &getSchemaCache() const {return shared.cache;}
//conn 是大家共享, shared里面的, embedded是每个代理自己保持的,初始化的时候, 就存在了.
//conn is shared by all the clients and is stored in variable shared. embedded is stored in each proxy.
std::shared_ptr<const SchemaInfo> getSchemaInfo() const
{return shared.cache.getSchema(this->getConn(), this->getEConn());}
......@@ -130,17 +130,14 @@ extern __thread ProxyState *thread_ps;
class Delta {
public:
enum TableType {REGULAR_TABLE, BLEEDING_TABLE};
Delta(const DBMeta &parent_meta) : parent_meta(parent_meta) {}
virtual ~Delta() {}
/*
* Take the update action against the database. Contains high level
* serialization semantics.
*/
virtual bool apply(const std::unique_ptr<Connect> &e_conn,
TableType table_type) = 0;
protected:
const DBMeta &parent_meta;
......@@ -211,7 +208,7 @@ class Rewriter;
enum class CompletionType {DDL, Onion};
//用于调用apply函数,写数据库
//call the function apply and write data to embedded MySQL.
bool
writeDeltas(const std::unique_ptr<Connect> &e_conn,
const std::vector<std::unique_ptr<Delta> > &deltas,
......@@ -260,7 +257,6 @@ class RewritePlan;
/*
*1.A set of functions for manipulating metadata at high level.
*/
class Analysis {
Analysis() = delete;
Analysis(Analysis &&a) = delete;
......@@ -287,39 +283,30 @@ public:
std::map<const Item *, std::unique_ptr<RewritePlan> > rewritePlans;
std::map<std::string, std::map<const std::string, const std::string>> table_aliases;
std::map<const Item_field *, std::pair<Item_field *, OLK>> item_cache;
// information for decrypting results
ReturnMeta rmeta;
bool inject_alias;
bool summation_hack;
KillZone kill_zone;
// These functions are prefered to their lower level counterparts.
bool addAlias(const std::string &alias, const std::string &db,
const std::string &table);
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,
......@@ -340,15 +327,11 @@ 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;}
......@@ -357,7 +340,6 @@ public:
{return default_sec_rating;}
// access to isAlias(...)
friend class MultiDeleteHandler;
private:
//name for the default db
const std::string db_name;
......@@ -383,4 +365,3 @@ getAllUDFs();
std::string
lexToQuery(const LEX &lex);
......@@ -70,14 +70,14 @@ AbstractQueryExecutor *
// layout we use
const auto &key_data = collectKeyData(*lex);
//这里给出了create的获取. alter_info代码被摘出来了. 代表了要创建的一系列column以及index
// create_list is a set of columns and indecies to be created.
auto it =
List_iterator<Create_field>(lex->alter_info.create_list);
//对现有的每个field, 如id,name, 都在内部通过createAndRewriteField函数扩展成多个洋葱+salt.
//其中洋葱有多个层, 其通过newCreateField函数, 决定了类型, 而新的field的名字, 就是洋葱的名字传过去的.
//扩展以后, 就是新的Create_field类型了, 这了返回的list是被继续传到引用参数里面的, 很奇怪的用法.
//key data在这里的作用是, 决定是不是unique, 从而选择和是的洋葱层次.
//1. we need key_data to determine whether the field is unique.
//2. each field, like id or name, is processed in the function createAndRewriteField to be expanded to
// multiple onions together with an optional salt column. Each onion has multiple layers. The function
//newCreateField determines the new datatype, and the new filed name is passed only once.
new_lex->alter_info.create_list =
accumList<Create_field>(it,
[&a, &tm, &key_data] (List<Create_field> out_list,
......@@ -93,7 +93,8 @@ AbstractQueryExecutor *
// -----------------------------
// Update TABLE
// -----------------------------
//建立了db=>table的关系, 作为delta实现. 然后delta会apply. 这里使用了createDelta
//add the db=>table relation through delta.
a.deltas.push_back(std::unique_ptr<Delta>(
new CreateDelta(std::move(tm),
a.getDatabaseMeta(pre.dbname),
......@@ -106,15 +107,10 @@ AbstractQueryExecutor *
"Table " + pre.table + " already exists!");
//why still rewrite here???
}
//在handler的第一阶段, 通过analysis搜集delta以及执行计划等内容, 然后在第二阶段, 实行delta以及
//执行计划, 新的lex里面包含了改写以后的语句, 直接转化成string就可以用了.
//first use analysis to collect delta, and then apply the delta to the embedded database.
return new DDLQueryExecutor(*new_lex, std::move(a.deltas));
}
//################################################################Alter table handler#########################################################################################
// mysql does not support indiscriminate add-drops
// ie,
......@@ -226,12 +222,11 @@ class CreateDBHandler : public DDLHandler {
convert_lex_str(lex->name);
if (false == a.databaseMetaExists(dbname)) {
std::unique_ptr<DatabaseMeta> dm(new DatabaseMeta());
//可以看到, 建立数据库的时候,和建立表的时候类型, 使用了createdelta, 添加了从db到schema的映射过程.
//createdelta is used both for CREATE DB and CREATE TABLE.
a.deltas.push_back(std::unique_ptr<Delta>(
new CreateDelta(std::move(dm), a.getSchema(),
IdentityMetaKey(dbname))));
} else {
const bool test =
lex->create_info.options & HA_LEX_CREATE_IF_NOT_EXISTS;
TEST_TextMessageError(test,
......@@ -241,7 +236,6 @@ class CreateDBHandler : public DDLHandler {
}
};
//################################################################change db handler#########################################################################################
class ChangeDBHandler : public DDLHandler {
......@@ -294,8 +288,7 @@ class LockTablesHandler : public DDLHandler {
class CreateIndexHandler : public DDLHandler {
virtual AbstractQueryExecutor *
rewriteAndUpdate(Analysis &a, LEX *const lex, const Preamble &pre)
const
{
const {
assert(a.deltas.size() == 0);
LEX *const new_lex = copyWithTHD(lex);
......
......@@ -19,7 +19,11 @@
*to fetch its children, the databasemeta. Then it adds those databasemeta as KV in the map, and return those
*databasemeta as a vector for recursive processing.
for this function, it only extract the dbmeta and
for this function, it only extract the dbmeta and.
This function is called by fetchChildren in MappedDBMeta,LeafMeta, and OnionMeta. the parameter deserialHandler has
three parameters: serial key, serial, and id, with those three parameters, the function is able to recover DBMeta from
one line of record in the embedded mysql
*/
std::vector<DBMeta *>
DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn,
......@@ -32,7 +36,8 @@ DBMeta::doFetchChildren(const std::unique_ptr<Connect> &e_conn,
// Now that we know the table exists, SELECT the data we want.
std::vector<DBMeta *> out_vec;
std::unique_ptr<DBResult> db_res;
//this is the id of the current class.
//this is the id of the current class.For SchemaInfo, the parentid is that of the schemainfo, and using this id,
//we are able to recover the underlying DatabaseMeta.
const std::string parent_id = std::to_string(this->getDatabaseID());
const std::string serials_query =
" SELECT " + table_name + ".serial_object,"
......@@ -608,17 +613,18 @@ SchemaCache::getSchema(const std::unique_ptr<Connect> &conn,
const std::unique_ptr<Connect> &e_conn) const
{
if (true == this->no_loads) {
//设置当前id对应的stale的值为true.
//set staleness of current id to true.
TEST_SchemaFailure(initialStaleness(e_conn));
this->no_loads = false;
}else{
;
}
//查询当前ID对应的Stale的值
//check the staleness of the current id
if (true == lowLevelGetCurrentStaleness(e_conn, this->id)) {
this->schema =
std::shared_ptr<SchemaInfo>(loadSchemaInfo(conn, e_conn));
}else{
;
}
assert(this->schema);
......
......@@ -73,7 +73,9 @@ public:
virtual std::pair<ResultType, AbstractAnything *>
nextImpl(const ResType &res, const NextParams &nparams) = 0;
//true will set the staleness of the current cache id to true, which results in a reloading of schemaInfo
virtual bool stales() const {return false;}
//if usesEmbedded is true, then the current db of the embedded MySQL is set to embedded_db
virtual bool usesEmbedded() const {return false;}
private:
......
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