diff --git a/src/enclave/persistence/Persistence.cpp b/src/enclave/persistence/Persistence.cpp index 7568303b..dabc3c89 100644 --- a/src/enclave/persistence/Persistence.cpp +++ b/src/enclave/persistence/Persistence.cpp @@ -5,6 +5,8 @@ using namespace std; +void inner_ocall_persist_get(crust_status_t* crust_status, const char *key, uint8_t **value, size_t *value_len); + /** * @description: Add value by key * @param key -> Pointer to key @@ -129,6 +131,24 @@ crust_status_t persist_set(std::string key, const uint8_t *value, size_t value_l } else { + // Delete old data + std::string sum_key = key + "_sum"; + uint8_t *p_sum_key = NULL; + size_t sum_key_len = 0; + inner_ocall_persist_get(&crust_status, sum_key.c_str(), &p_sum_key, &sum_key_len); + if (CRUST_SUCCESS == crust_status) + { + json::JSON sum_json = json::JSON::Load(std::string(reinterpret_cast(p_sum_key), sum_key_len)); + free(p_sum_key); + uint32_t piece_num = sum_json[PERSIST_SUM].ToInt(); + for (uint32_t i = 0; i < piece_num; i++) + { + std::string del_key = key + "_" + std::to_string(i); + persist_del(del_key); + } + persist_del(sum_key); + } + // Set new data ocall_persist_set(&crust_status, key.c_str(), (uint8_t *)p_sealed_data, sealed_data_size); } @@ -178,6 +198,24 @@ crust_status_t persist_set_unsafe(std::string key, const uint8_t *value, size_t } else { + // Delete old data + std::string sum_key = key + "_sum"; + uint8_t *p_sum_key = NULL; + size_t sum_key_len = 0; + inner_ocall_persist_get(&crust_status, sum_key.c_str(), &p_sum_key, &sum_key_len); + if (CRUST_SUCCESS == crust_status) + { + json::JSON sum_json = json::JSON::Load(std::string(reinterpret_cast(p_sum_key), sum_key_len)); + free(p_sum_key); + uint32_t piece_num = sum_json[PERSIST_SUM].ToInt(); + for (uint32_t i = 0; i < piece_num; i++) + { + std::string del_key = key + "_" + std::to_string(i); + persist_del(del_key); + } + persist_del(sum_key); + } + // Set new data ocall_persist_set(&crust_status, key.c_str(), value, value_len); } diff --git a/src/enclave/storage/Storage.cpp b/src/enclave/storage/Storage.cpp index 982b6a57..9d45a3cc 100644 --- a/src/enclave/storage/Storage.cpp +++ b/src/enclave/storage/Storage.cpp @@ -87,6 +87,8 @@ crust_status_t storage_seal_file(const char *p_tree, size_t tree_len, const char file_entry_json[FILE_BLOCK_NUM] = block_num; // Status indicates current new file's status, which must be one of valid, lost and unconfirmed file_entry_json[FILE_STATUS] = FILE_STATUS_UNCONFIRMED; + free(new_root_hash_u); + free(org_root_hash_u); // Store new tree structure crust_status = persist_set_unsafe(new_root_hash_str, (const uint8_t*)new_tree.c_str(), new_tree.size()); diff --git a/src/enclave/workload/Workload.cpp b/src/enclave/workload/Workload.cpp index e52e132e..dd71225e 100644 --- a/src/enclave/workload/Workload.cpp +++ b/src/enclave/workload/Workload.cpp @@ -354,5 +354,9 @@ void Workload::set_srd_info(std::string path, long change) */ json::JSON Workload::get_srd_info() { - return this->srd_info_json; + sgx_thread_mutex_lock(&this->srd_info_mutex); + json::JSON srd_info = this->srd_info_json; + sgx_thread_mutex_unlock(&this->srd_info_mutex); + + return srd_info; } diff --git a/test/integration/performance/run_test.sh b/test/integration/performance/run_test.sh index cc23f8af..a209be8e 100755 --- a/test/integration/performance/run_test.sh +++ b/test/integration/performance/run_test.sh @@ -1,14 +1,23 @@ #!/bin/bash function _seal() { + echo 0 > $sealsyncfile file_num_g=0 local total_num=$(get_config ".performance|.file_num") while true; do sleep 3 if [ $file_num_g -lt $total_num ]; then local num=1000 - while [ $num -ge 0 ]; do - _seal_r + while [ $num -ge 0 ] && [ $(cat $sealsyncfile) -lt 10 ]; do + ( + flock -w 30 202 + if [ $(cat $sealsyncfile) -lt 10 ]; then + _seal_r & + local cur_num=$(cat $sealsyncfile) + ((cur_num++)) + echo $cur_num > $sealsyncfile + fi + ) 202>$seallockfile ((num--)) done fi @@ -295,6 +304,8 @@ srdresfile=$ptmpdir/srd_info deletefilethres=3 deletetime=100 deletelockfile=$ptmpdir/deletelockfile +seallockfile=$ptmpdir/seallockfile +sealsyncfile=$ptmpdir/sealsyncfile # Control sig num sigShowInfo=28 diff --git a/test/integration/scripts/start_test.sh b/test/integration/scripts/start_test.sh index bd9c9234..5a4f203c 100755 --- a/test/integration/scripts/start_test.sh +++ b/test/integration/scripts/start_test.sh @@ -114,7 +114,7 @@ fi ### Start crust-sworker cd $testdir rm -rf tee_base_path -rm -rf files/* +rm -rf files verbose INFO "starting crust-sworker..." h ./bin/crust-sworker -c etc/Config.json --offline --debug &>$sworkerlog & pid=$! diff --git a/test/integration/scripts/utils.sh b/test/integration/scripts/utils.sh index 7e5a6733..ce31ceee 100755 --- a/test/integration/scripts/utils.sh +++ b/test/integration/scripts/utils.sh @@ -81,6 +81,7 @@ function seal_file() { local data_path=$1 local store_path=$2 + store_path=${store_path}.$RANDOM local tmp_file=tmp_file.$RANDOM ### Split file