-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobliv_foreigin_modify.c
99 lines (80 loc) · 2.83 KB
/
obliv_foreigin_modify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
static void
obliviousBeginForeignModify(ModifyTableState *mtstate,
ResultRelInfo *rinfo, List *fdw_private,
int subplan_index, int eflags)
{
elog(DEBUG1, "In obliviousBeginForeignModify");
Oid mappingOid;
Ostatus obliv_status;
MemoryContext mappingMemoryContext;
MemoryContext oldContext;
Relation oblivFDWTable;
Relation oblivMappingRel;
/* underlying heap files */
Relation heapTableRelation;
Relation indexRelation;
FdwOblivTableStatus oStatus;
char *relationName;
mappingMemoryContext = AllocSetContextCreate(CurrentMemoryContext, "Obliv Mapping Table", ALLOCSET_DEFAULT_SIZES);
oldContext = MemoryContextSwitchTo(mappingMemoryContext);
oblivFDWTable = rinfo->ri_RelationDesc;
relationName = RelationGetRelationName(oblivFDWTable);
mappingOid = get_relname_relid(OBLIV_MAPPING_TABLE_NAME, PG_PUBLIC_NAMESPACE);
if (mappingOid != InvalidOid)
{
oblivMappingRel = heap_open(mappingOid, RowShareLock);
oStatus = getOblivTableStatus(oblivFDWTable->rd_id, oblivMappingRel);
oStatus.tableRelFileNode = oblivFDWTable->rd_id;
obliv_status = validateIndexStatus(oStatus);
if (obliv_status == OBLIVIOUS_UNINTIALIZED)
{
elog(DEBUG1, "Index has not been created");
/* Create heap file for obliv index. */
indexRelation = obliv_index_create(oStatus);
/* Create heap file for obliv table */
heapTableRelation = obliv_table_create(oblivFDWTable);
/* ipdate ostates data */
oStatus.indexRelFileNode = indexRelation->rd_id;
oStatus.heapTableRelFileNode = heapTableRelation->rd_id;
/* update OBLIV_MAPPING_TABLE records */
setOblivStatusInitated(oStatus, oblivMappingRel);
heap_close(oblivMappingRel, RowShareLock);
setupOblivStatus(oStatus);
}
else if (obliv_status == OBLIVIOUS_INITIALIZED)
{
elog(DEBUG1, "Index has already been created");
/* Index has been created. */
/**
* Initiate secure operator evaluator (SOE).
* Current ORAM bucket capacity is hardcoded to 1.
* */
heap_close(oblivMappingRel, RowShareLock);
initSOE(relationName, (size_t) oStatus.tableNBlocks, 1);
}
/**
* If none of the above cases is valid, the record stored in
* OBLIV_MAPPING_TABLE_NAME is invalid and an error message
* has already been show to the user by the function
* validateIndexStatus.
* */
}
else
{
/*
* The database administrator should create a Mapping table which maps
* the oid of the foreign table to its mirror table counterpart. The
* mirror table is used by this extension to find a matching index and
* simulate it.
*
*/
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_OBJECT),
errmsg("Mapping table %s does not exist in the database!",
OBLIV_MAPPING_TABLE_NAME)));
}
pfree(relationName);
MemoryContextSwitchTo(oldContext);
MemoryContextDelete(mappingMemoryContext);
elog(DEBUG1, "closed begin foreing modify");
}