Skip to content

Commit a95f2c7

Browse files
andrewlawhhAndrew Laweric-feng-2011Eric Fengchester-leung
authored
JobVerificationEngine DAG construction (no driver assigned partition IDs) (#131)
* Support for multiple branched CaseWhen * Interval (#116) * add date_add, interval sql still running into issues * Add Interval SQL support * uncomment out the other tests * resolve comments * change interval equality Co-authored-by: Eric Feng <[email protected]> * Remove partition ID argument from enclaves * Fix comments * updates * Modifications to integrate crumb, log-mac, and all-outputs_mac, wip * Store log mac after each output buffer, add all-outputs-mac to each encryptedblocks wip * Add all_outputs_mac to all EncryptedBlocks once all log_macs have been generated * Almost builds * cpp builds * Use ubyte for all_outputs_mac * use Mac for all_outputs_mac * Hopefully this works for flatbuffers all_outputs_mac mutation, cpp builds * Scala builds now too, running into error with union * Stuff builds, error with all outputs mac serialization. this commit uses all_outputs_mac as Mac table * Fixed bug, basic encryption / show works * All single partition tests pass, multiple partiton passes until tpch-9 * All tests pass except tpch-9 and skew join * comment tpch back in * Check same number of ecalls per partition - exception for scanCollectLastPrimary(?) * First attempt at constructing executed DAG * Fix typos * Rework graph * Add log macs to graph nodes * Construct expected DAG and refactor JobNode. Refactor construction of executed DAG. * Implement 'paths to sink' for a DAG * add crumb for last ecall * Fix NULL handling for aggregation (#130) * Modify COUNT and SUM to correctly handle NULL values * Change average to support NULL values * Fix * Changing operator matching from logical to physical (#129) * WIP * Fix * Unapply change * Aggregation rewrite (#132) * Merge new aggregate * Uncomment log_mac_lst clear * Clean up comments * Clean up comments in other files * Remove print statements from unit tests Co-authored-by: Andrew Law <[email protected]> Co-authored-by: Eric Feng <[email protected]> Co-authored-by: Eric Feng <[email protected]> Co-authored-by: Chester Leung <[email protected]> Co-authored-by: Wenting Zheng <[email protected]>
1 parent 9c9dae1 commit a95f2c7

24 files changed

+1552
-1107
lines changed

build.sbt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ concurrentRestrictions in Global := Seq(
2424
fork in Test := true
2525
fork in run := true
2626

27+
testOptions in Test += Tests.Argument("-oF")
2728
javaOptions in Test ++= Seq("-Xmx2048m", "-XX:ReservedCodeCacheSize=384m")
2829
javaOptions in run ++= Seq(
2930
"-Xmx2048m", "-XX:ReservedCodeCacheSize=384m", "-Dspark.master=local[1]")
@@ -217,7 +218,7 @@ buildFlatbuffersTask := {
217218
if (gen.isEmpty || fbsLastMod > gen.map(_.lastModified).max) {
218219
for (fbs <- flatbuffers) {
219220
streams.value.log.info(s"Generating flatbuffers for ${fbs}")
220-
if (Seq(flatc.getPath, "--cpp", "-o", flatbuffersGenCppDir.value.getPath, fbs.getPath).! != 0
221+
if (Seq(flatc.getPath, "--cpp", "--gen-mutable", "-o", flatbuffersGenCppDir.value.getPath, fbs.getPath).! != 0
221222
|| Seq(flatc.getPath, "--java", "-o", javaOutDir.getPath, fbs.getPath).! != 0) {
222223
sys.error("Flatbuffers build failed.")
223224
}

src/enclave/App/App.cpp

Lines changed: 34 additions & 121 deletions
Large diffs are not rendered by default.

src/enclave/App/SGXEnclave.h

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ extern "C" {
1212
JNIEnv *, jobject, jlong);
1313

1414
JNIEXPORT jbyteArray JNICALL Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_Project(
15-
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jint);
15+
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray);
1616

1717
JNIEXPORT jbyteArray JNICALL Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_Filter(
18-
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jint);
18+
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray);
1919

2020
JNIEXPORT jbyteArray JNICALL Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_Encrypt(
2121
JNIEnv *, jobject, jlong, jbyteArray);
@@ -24,51 +24,47 @@ extern "C" {
2424
JNIEnv *, jobject, jlong, jbyteArray);
2525

2626
JNIEXPORT jbyteArray JNICALL Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_Sample(
27-
JNIEnv *, jobject, jlong, jbyteArray, jint);
27+
JNIEnv *, jobject, jlong, jbyteArray);
2828

2929
JNIEXPORT jbyteArray JNICALL
3030
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_FindRangeBounds(
31-
JNIEnv *, jobject, jlong, jbyteArray, jint, jbyteArray, jint);
31+
JNIEnv *, jobject, jlong, jbyteArray, jint, jbyteArray);
3232

3333
JNIEXPORT jobjectArray JNICALL
3434
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_PartitionForSort(
35-
JNIEnv *, jobject, jlong, jbyteArray, jint, jbyteArray, jbyteArray, jint);
35+
JNIEnv *, jobject, jlong, jbyteArray, jint, jbyteArray, jbyteArray);
3636

3737
JNIEXPORT jbyteArray JNICALL Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_ExternalSort(
38-
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jint);
38+
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray);
3939

4040
JNIEXPORT jbyteArray JNICALL
4141
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_ScanCollectLastPrimary(
42-
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jint);
42+
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray);
4343

4444
JNIEXPORT jbyteArray JNICALL
4545
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_NonObliviousSortMergeJoin(
46-
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jbyteArray, jint);
46+
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jbyteArray);
4747

4848
JNIEXPORT jobject JNICALL
49-
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_NonObliviousAggregateStep1(
50-
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jint);
51-
52-
JNIEXPORT jbyteArray JNICALL
53-
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_NonObliviousAggregateStep2(
54-
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jbyteArray, jbyteArray, jbyteArray, jint);
49+
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_NonObliviousAggregate(
50+
JNIEnv *, jobject, jlong, jbyteArray, jbyteArray, jboolean);
5551

5652
JNIEXPORT jbyteArray JNICALL
5753
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_CountRowsPerPartition(
58-
JNIEnv *, jobject, jlong, jbyteArray, jint);
54+
JNIEnv *, jobject, jlong, jbyteArray);
5955

6056

6157
JNIEXPORT jbyteArray JNICALL
6258
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_ComputeNumRowsPerPartition(
63-
JNIEnv *, jobject, jlong, jint, jbyteArray, jint);
59+
JNIEnv *, jobject, jlong, jint, jbyteArray);
6460

6561
JNIEXPORT jbyteArray JNICALL
6662
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_LocalLimit(
67-
JNIEnv *, jobject, jlong, jint, jbyteArray, jint);
63+
JNIEnv *, jobject, jlong, jint, jbyteArray);
6864

6965
JNIEXPORT jbyteArray JNICALL
7066
Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_LimitReturnRows(
71-
JNIEnv *, jobject, jlong, jlong, jbyteArray, jbyteArray, jint);
67+
JNIEnv *, jobject, jlong, jlong, jbyteArray, jbyteArray);
7268

7369
JNIEXPORT jbyteArray JNICALL Java_edu_berkeley_cs_rise_opaque_execution_SGXEnclave_GenerateReport(
7470
JNIEnv *, jobject, jlong);

src/enclave/Enclave/Aggregate.cpp

Lines changed: 16 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -5,127 +5,38 @@
55
#include "FlatbuffersWriters.h"
66
#include "common.h"
77

8-
void non_oblivious_aggregate_step1(
8+
void non_oblivious_aggregate(
99
uint8_t *agg_op, size_t agg_op_length,
1010
uint8_t *input_rows, size_t input_rows_length,
11-
uint8_t **first_row, size_t *first_row_length,
12-
uint8_t **last_group, size_t *last_group_length,
13-
uint8_t **last_row, size_t *last_row_length) {
11+
uint8_t **output_rows, size_t *output_rows_length,
12+
bool is_partial) {
1413

1514
FlatbuffersAggOpEvaluator agg_op_eval(agg_op, agg_op_length);
1615
RowReader r(BufferRefView<tuix::EncryptedBlocks>(input_rows, input_rows_length));
17-
RowWriter first_row_writer;
18-
RowWriter last_group_writer;
19-
RowWriter last_row_writer;
16+
RowWriter w;
2017

2118
FlatbuffersTemporaryRow prev, cur;
19+
size_t count = 0;
20+
2221
while (r.has_next()) {
2322
prev.set(cur.get());
2423
cur.set(r.next());
25-
26-
if (prev.get() == nullptr) {
27-
EnclaveContext::getInstance().set_curr_row_writer(std::string("first_row"));
28-
first_row_writer.append(cur.get());
29-
}
30-
31-
if (!r.has_next()) {
32-
EnclaveContext::getInstance().set_curr_row_writer(std::string("last_row"));
33-
last_row_writer.append(cur.get());
34-
}
35-
24+
3625
if (prev.get() != nullptr && !agg_op_eval.is_same_group(prev.get(), cur.get())) {
26+
w.append(agg_op_eval.evaluate());
3727
agg_op_eval.reset_group();
3828
}
3929
agg_op_eval.aggregate(cur.get());
30+
count += 1;
4031
}
4132

42-
EnclaveContext::getInstance().set_curr_row_writer(std::string("last_group"));
43-
last_group_writer.append(agg_op_eval.get_partial_agg());
44-
45-
std::string ecall = std::string("nonObliviousAggregateStep1");
46-
47-
EnclaveContext::getInstance().set_curr_row_writer(std::string("first_row"));
48-
first_row_writer.output_buffer(first_row, first_row_length, ecall);
49-
50-
EnclaveContext::getInstance().set_curr_row_writer(std::string("last_group"));
51-
last_group_writer.output_buffer(last_group, last_group_length, ecall);
52-
53-
EnclaveContext::getInstance().set_curr_row_writer(std::string("last_row"));
54-
last_row_writer.output_buffer(last_row, last_row_length, ecall);
55-
}
56-
57-
void non_oblivious_aggregate_step2(
58-
uint8_t *agg_op, size_t agg_op_length,
59-
uint8_t *input_rows, size_t input_rows_length,
60-
uint8_t *next_partition_first_row, size_t next_partition_first_row_length,
61-
uint8_t *prev_partition_last_group, size_t prev_partition_last_group_length,
62-
uint8_t *prev_partition_last_row, size_t prev_partition_last_row_length,
63-
uint8_t **output_rows, size_t *output_rows_length) {
64-
65-
FlatbuffersAggOpEvaluator agg_op_eval(agg_op, agg_op_length);
66-
RowReader r(BufferRefView<tuix::EncryptedBlocks>(input_rows, input_rows_length));
67-
RowReader next_partition_first_row_reader(
68-
BufferRefView<tuix::EncryptedBlocks>(
69-
next_partition_first_row, next_partition_first_row_length));
70-
RowReader prev_partition_last_group_reader(
71-
BufferRefView<tuix::EncryptedBlocks>(
72-
prev_partition_last_group, prev_partition_last_group_length));
73-
RowReader prev_partition_last_row_reader(
74-
BufferRefView<tuix::EncryptedBlocks>(
75-
prev_partition_last_row, prev_partition_last_row_length));
76-
RowWriter w;
77-
78-
if (next_partition_first_row_reader.num_rows() > 1) {
79-
throw std::runtime_error(
80-
std::string("Incorrect number of starting rows from next partition passed: expected 0 or 1, got ")
81-
+ std::to_string(next_partition_first_row_reader.num_rows()));
82-
}
83-
if (prev_partition_last_group_reader.num_rows() > 1) {
84-
throw std::runtime_error(
85-
std::string("Incorrect number of ending groups from prev partition passed: expected 0 or 1, got ")
86-
+ std::to_string(prev_partition_last_group_reader.num_rows()));
87-
}
88-
if (prev_partition_last_row_reader.num_rows() > 1) {
89-
throw std::runtime_error(
90-
std::string("Incorrect number of ending rows from prev partition passed: expected 0 or 1, got ")
91-
+ std::to_string(prev_partition_last_row_reader.num_rows()));
92-
}
93-
94-
const tuix::Row *next_partition_first_row_ptr =
95-
next_partition_first_row_reader.has_next() ? next_partition_first_row_reader.next() : nullptr;
96-
agg_op_eval.set(prev_partition_last_group_reader.has_next() ?
97-
prev_partition_last_group_reader.next() : nullptr);
98-
const tuix::Row *prev_partition_last_row_ptr =
99-
prev_partition_last_row_reader.has_next() ? prev_partition_last_row_reader.next() : nullptr;
100-
101-
FlatbuffersTemporaryRow prev, cur(prev_partition_last_row_ptr), next;
102-
bool stop = false;
103-
if (r.has_next()) {
104-
next.set(r.next());
105-
} else {
106-
stop = true;
33+
// Skip outputting the final row if the number of input rows is 0 AND
34+
// 1. It's a grouping aggregation, OR
35+
// 2. It's a global aggregation, the mode is final
36+
if (!(count == 0 && (agg_op_eval.get_num_grouping_keys() > 0 || (agg_op_eval.get_num_grouping_keys() == 0 && !is_partial)))) {
37+
w.append(agg_op_eval.evaluate());
10738
}
108-
while (!stop) {
109-
// Populate prev, cur, next to enable lookbehind and lookahead
110-
prev.set(cur.get());
111-
cur.set(next.get());
112-
if (r.has_next()) {
113-
next.set(r.next());
114-
} else {
115-
next.set(next_partition_first_row_ptr);
116-
stop = true;
117-
}
11839

119-
if (prev.get() != nullptr && !agg_op_eval.is_same_group(prev.get(), cur.get())) {
120-
agg_op_eval.reset_group();
121-
}
122-
agg_op_eval.aggregate(cur.get());
123-
124-
// Output the current aggregate if it is the last aggregate for its run
125-
if (next.get() == nullptr || !agg_op_eval.is_same_group(cur.get(), next.get())) {
126-
w.append(agg_op_eval.evaluate());
127-
}
128-
}
129-
130-
w.output_buffer(output_rows, output_rows_length, std::string("nonObliviousAggregateStep2"));
40+
w.output_buffer(output_rows, output_rows_length, std::string("nonObliviousAggregate"));
13141
}
42+

src/enclave/Enclave/Aggregate.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,10 @@
44
#ifndef AGGREGATE_H
55
#define AGGREGATE_H
66

7-
void non_oblivious_aggregate_step1(
7+
void non_oblivious_aggregate(
88
uint8_t *agg_op, size_t agg_op_length,
99
uint8_t *input_rows, size_t input_rows_length,
10-
uint8_t **first_row, size_t *first_row_length,
11-
uint8_t **last_group, size_t *last_group_length,
12-
uint8_t **last_row, size_t *last_row_length);
13-
14-
void non_oblivious_aggregate_step2(
15-
uint8_t *agg_op, size_t agg_op_length,
16-
uint8_t *input_rows, size_t input_rows_length,
17-
uint8_t *next_partition_first_row, size_t next_partition_first_row_length,
18-
uint8_t *prev_partition_last_group, size_t prev_partition_last_group_length,
19-
uint8_t *prev_partition_last_row, size_t prev_partition_last_row_length,
20-
uint8_t **output_rows, size_t *output_rows_length);
10+
uint8_t **output_rows, size_t *output_rows_length,
11+
bool is_partial);
2112

2213
#endif // AGGREGATE_H

0 commit comments

Comments
 (0)