Skip to content

Commit dbf1234

Browse files
committed
Remove key_prefix from keys() call
Signed-off-by: James Mulcahy <[email protected]>
1 parent 799254e commit dbf1234

File tree

6 files changed

+13
-27
lines changed

6 files changed

+13
-27
lines changed

include/proxy-wasm/context.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,8 +353,7 @@ 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,
357-
std::vector<std::string> *result) override;
356+
WasmResult getSharedDataKeys(std::vector<std::string> *result) override;
358357
WasmResult removeSharedDataKey(std::string_view key, uint32_t cas,
359358
std::pair<std::string, uint32_t> *result) override;
360359

include/proxy-wasm/context_interface.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ struct GeneralInterface {
596596
};
597597

598598
/**
599-
* SharedDataInterface is for shaing data between VMs. In general the VMs may be on different
599+
* SharedDataInterface is for sharing data between VMs. In general the VMs may be on different
600600
* threads. Keys can have any format, but good practice would use reverse DNS and namespacing
601601
* prefixes to avoid conflicts.
602602
*/
@@ -623,12 +623,10 @@ struct SharedDataInterface {
623623
virtual WasmResult setSharedData(std::string_view key, std::string_view value, uint32_t cas) = 0;
624624

625625
/**
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
626+
* Return all the keys from the data shraed between VMs
628627
* @param data is a location to store the returned value.
629628
*/
630-
virtual WasmResult getSharedDataKeys(std::string_view key_prefix,
631-
std::vector<std::string> *result) = 0;
629+
virtual WasmResult getSharedDataKeys(std::vector<std::string> *result) = 0;
632630

633631
/**
634632
* Removes the given key from the data shared between VMs.

src/context.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,8 @@ 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);
195+
WasmResult ContextBase::getSharedDataKeys(std::vector<std::string> *result) {
196+
return getGlobalSharedData().keys(wasm_->vm_id(), result);
198197
}
199198

200199
WasmResult ContextBase::removeSharedDataKey(std::string_view key, uint32_t cas,

src/shared_data.cc

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ WasmResult SharedData::get(std::string_view vm_id, const std::string_view key,
5656
return WasmResult::NotFound;
5757
}
5858

59-
WasmResult SharedData::keys(std::string_view vm_id, const std::string_view key_prefix,
60-
std::vector<std::string> *result) {
59+
WasmResult SharedData::keys(std::string_view vm_id, std::vector<std::string> *result) {
6160
result->clear();
6261

6362
std::lock_guard<std::mutex> lock(mutex_);
@@ -67,9 +66,7 @@ WasmResult SharedData::keys(std::string_view vm_id, const std::string_view key_p
6766
}
6867

6968
for (auto kv : map->second) {
70-
if (kv.first.rfind(key_prefix, 0) == 0) {
71-
result->push_back(kv.first);
72-
}
69+
result->push_back(kv.first);
7370
}
7471

7572
return WasmResult::Ok;

src/shared_data.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ class SharedData {
2525
SharedData(bool register_vm_id_callback = true);
2626
WasmResult get(std::string_view vm_id, const std::string_view key,
2727
std::pair<std::string, uint32_t> *result);
28-
WasmResult keys(std::string_view vm_id, const std::string_view key_prefix,
29-
std::vector<std::string> *result);
28+
WasmResult keys(std::string_view vm_id, std::vector<std::string> *result);
3029
WasmResult set(std::string_view vm_id, std::string_view key, std::string_view value,
3130
uint32_t cas);
3231
WasmResult remove(std::string_view vm_id, const std::string_view key, uint32_t cas,

test/shared_data_test.cc

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,14 @@ TEST(SharedData, SingleThread) {
2929
// Validate we get an 'Ok' response when fetching keys before anything
3030
// is initialized.
3131
std::vector<std::string> keys;
32-
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, "", &keys));
32+
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, &keys));
3333
EXPECT_EQ(0, keys.size());
3434

3535
// Validate that we clear the result set
3636
std::vector<std::string> nonEmptyKeys(2);
3737
nonEmptyKeys[0] = "valueA";
3838
nonEmptyKeys[1] = "valueB";
39-
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, "", &nonEmptyKeys));
39+
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, &nonEmptyKeys));
4040
EXPECT_EQ(0, nonEmptyKeys.size());
4141

4242
std::pair<std::string, uint32_t> result;
@@ -59,19 +59,13 @@ TEST(SharedData, SingleThread) {
5959
EXPECT_EQ(value, result.first);
6060
EXPECT_EQ(result.second, 3);
6161

62-
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, "unmatched-prefix", &keys));
63-
EXPECT_EQ(0, keys.size());
64-
65-
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, "keyyyyy", &keys));
66-
EXPECT_EQ(0, keys.size());
67-
68-
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, "ke", &keys));
62+
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, &keys));
6963
EXPECT_EQ(1, keys.size());
7064
EXPECT_EQ(key, keys[0]);
7165

7266
keys.clear();
7367
EXPECT_EQ(WasmResult::CasMismatch, shared_data.remove(vm_id, key, 911, nullptr));
74-
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, "ke", &keys));
68+
EXPECT_EQ(WasmResult::Ok, shared_data.keys(vm_id, &keys));
7569
EXPECT_EQ(1, keys.size());
7670

7771
EXPECT_EQ(WasmResult::Ok, shared_data.remove(vm_id, key, 0, nullptr));

0 commit comments

Comments
 (0)