Skip to content

Commit 004edbb

Browse files
committed
Expose SharedData keys & remove methods in Context
1 parent cb1b36a commit 004edbb

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

include/proxy-wasm/context.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,9 @@ class ContextBase : public RootInterface,
353353
WasmResult getSharedData(std::string_view key,
354354
std::pair<std::string, uint32_t /* cas */> *data) override;
355355
WasmResult setSharedData(std::string_view key, std::string_view value, uint32_t cas) override;
356+
WasmResult getSharedDataKeys(std::string_view key_prefix, std::vector<std::string> *result) override;
357+
WasmResult removeSharedDataKey(std::string_view key, uint32_t cas) override;
358+
356359

357360
// Shared Queue
358361
WasmResult registerSharedQueue(std::string_view queue_name,

include/proxy-wasm/context_interface.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,21 @@ struct SharedDataInterface {
621621
* @param data is a location to store the returned value.
622622
*/
623623
virtual WasmResult setSharedData(std::string_view key, std::string_view value, uint32_t cas) = 0;
624+
625+
/**
626+
* Return all the keys which match the given key_prefix
627+
* @param key_prefix is used to restrict the results to keys matching the given prefix
628+
* @param data is a location to store the returned value.
629+
*/
630+
virtual WasmResult getSharedDataKeys(std::string_view key_prefix, std::vector<std::string> *result) = 0;
631+
632+
/**
633+
* Removes the given key from the data shared between VMs.
634+
* @param key is a proxy-wide key mapping to the shared data value.
635+
* @param cas is a compare-and-swap value. If it is zero it is ignored, otherwise it must match
636+
* the cas associated with the value.
637+
*/
638+
virtual WasmResult removeSharedDataKey(std::string_view key, uint32_t cas) = 0;
624639
}; // namespace proxy_wasm
625640

626641
struct SharedQueueInterface {

src/context.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,16 @@ WasmResult ContextBase::setSharedData(std::string_view key, std::string_view val
192192
return getGlobalSharedData().set(wasm_->vm_id(), key, value, cas);
193193
}
194194

195+
WasmResult ContextBase::getSharedDataKeys(std::string_view key_prefix,
196+
std::vector<std::string> *result) {
197+
return getGlobalSharedData().keys(wasm_->vm_id(), key_prefix, result);
198+
}
199+
200+
WasmResult ContextBase::removeSharedDataKey(std::string_view key, uint32_t cas) {
201+
return getGlobalSharedData().remove(wasm_->vm_id(), key, cas);
202+
}
203+
204+
195205
// Shared Queue
196206

197207
WasmResult ContextBase::registerSharedQueue(std::string_view queue_name,

0 commit comments

Comments
 (0)