fix: Correct upsert bug

master
Sean McBride 3 years ago
parent e5b222d83d
commit 32248f11be

@ -22,7 +22,11 @@ all: \
gocr.install \ gocr.install \
gps_ekf.install \ gps_ekf.install \
license_plate_detection.install \ license_plate_detection.install \
resize_image.install resize_image.install \
scratch_storage_get.install \
scratch_storage_set.install \
scratch_storage_delete.install \
scratch_storage_upsert.install \
.PHONY: clean .PHONY: clean
clean: clean:
@ -94,3 +98,9 @@ scratch_storage_get.install: ../runtime/bin/scratch_storage_get.wasm.so
.PHONY: scratch_storage_set.install .PHONY: scratch_storage_set.install
scratch_storage_set.install: ../runtime/bin/scratch_storage_set.wasm.so scratch_storage_set.install: ../runtime/bin/scratch_storage_set.wasm.so
.PHONY: scratch_storage_delete.install
scratch_storage_delete.install: ../runtime/bin/scratch_storage_delete.wasm.so
.PHONY: scratch_storage_upsert.install
scratch_storage_upsert.install: ../runtime/bin/scratch_storage_upsert.wasm.so

@ -1 +1 @@
Subproject commit 54de4d27f9a6e1f20b65b7110612a658479e6133 Subproject commit cf8a8bafb10c37f207ccba1405cac07cd70bae8f

@ -153,9 +153,9 @@ map_upsert(struct map *map, uint8_t *key, uint32_t key_len, uint8_t *value, uint
for (struct map_node *node = map->buckets[hash % MAP_BUCKET_COUNT]; node != NULL; node = node->next) { for (struct map_node *node = map->buckets[hash % MAP_BUCKET_COUNT]; node != NULL; node = node->next) {
if (node->hash == hash) { if (node->hash == hash) {
node->value_len = value_len; node->value_len = value_len;
node->value = realloc(&node->value, value_len); node->value = realloc(node->value, value_len);
assert(node->value); assert(node->value);
memcpy(&node->value, value, value_len); memcpy(node->value, value, value_len);
} }
goto DONE; goto DONE;
} }
@ -173,8 +173,8 @@ map_upsert(struct map *map, uint8_t *key, uint32_t key_len, uint8_t *value, uint
assert(new_node->value); assert(new_node->value);
// Copy Key and Value // Copy Key and Value
memcpy(&new_node->key, key, key_len); memcpy(new_node->key, key, key_len);
memcpy(&new_node->value, value, value_len); memcpy(new_node->value, value, value_len);
map->buckets[hash % MAP_BUCKET_COUNT] = new_node; map->buckets[hash % MAP_BUCKET_COUNT] = new_node;

@ -1148,7 +1148,6 @@ DONE:
* @param key_len * @param key_len
* @param value_offset * @param value_offset
* @param value_len * @param value_len
* @returns 0 on success, 1 if already present,
*/ */
EXPORT void EXPORT void
sledge_abi__scratch_storage_upsert(uint32_t key_offset, uint32_t key_len, uint32_t value_offset, uint32_t value_len) sledge_abi__scratch_storage_upsert(uint32_t key_offset, uint32_t key_len, uint32_t value_offset, uint32_t value_len)

@ -20,6 +20,24 @@
"relative-deadline-us": 20000000, "relative-deadline-us": 20000000,
"http-resp-content-type": "text/plain", "http-resp-content-type": "text/plain",
"http-resp-size": 1024 "http-resp-size": 1024
},
{
"route": "/delete",
"path": "scratch_storage_delete.wasm.so",
"expected-execution-us": 10000000,
"admissions-percentile": 70,
"relative-deadline-us": 20000000,
"http-resp-content-type": "text/plain",
"http-resp-size": 1024
},
{
"route": "/upsert",
"path": "scratch_storage_upsert.wasm.so",
"expected-execution-us": 10000000,
"admissions-percentile": 70,
"relative-deadline-us": 20000000,
"http-resp-content-type": "text/plain",
"http-resp-size": 1024
} }
] ]
} }

Loading…
Cancel
Save