Skip to content

Commit c774e9e

Browse files
Rodrigo Kumperafacebook-github-bot
authored andcommitted
Introduce optional append method. (#357)
Summary: Append is an optional operation for stores. The semantics is to create or append the value to a given key. Pull Request resolved: #357 Test Plan: It builds. This change was tested from PyTorch. Reviewed By: fduwjj Differential Revision: D45369865 Pulled By: kumpera fbshipit-source-id: 33ad6bac3fa87952b8ef3d060b73fd274bf3d65e
1 parent 583545a commit c774e9e

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ Ubuntu, this version ships with version 17.10 and up. If you run an
5454
older version, you'll have to install Google Test yourself, and set
5555
the `GTEST_ROOT` CMake variable.
5656

57+
You can install Google Test using conda with:
58+
``` shell
59+
conda install -c anaconda gmock gtest
60+
```
61+
Be carefull that you might need to fish for a package that works with your glibc
62+
63+
5764
To build the tests, run:
5865

5966
``` shell

gloo/rendezvous/prefix_store.cc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,45 @@ void PrefixStore::wait(
4343
store_.wait(joinedKeys, timeout);
4444
}
4545

46+
bool PrefixStore::has_v2_support() {
47+
return store_.has_v2_support();
48+
}
49+
50+
std::vector<std::vector<char>> PrefixStore::multi_get(const std::vector<std::string>& keys) {
51+
if (!store_.has_v2_support()) {
52+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("underlying store doesn't support multi_get");
53+
}
54+
std::vector<std::string> prefixed_keys;
55+
for(auto& key : keys) {
56+
prefixed_keys.push_back(joinKey(key));
57+
}
58+
return store_.multi_get(prefixed_keys);
59+
}
60+
61+
void PrefixStore::multi_set(const std::vector<std::string>& keys, const std::vector<std::vector<char>>& values) {
62+
if (!store_.has_v2_support()) {
63+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("underlying store doesn't support multi_set");
64+
}
65+
std::vector<std::string> prefixed_keys;
66+
for(auto& key : keys) {
67+
prefixed_keys.push_back(joinKey(key));
68+
}
69+
return store_.multi_set(prefixed_keys, values);
70+
}
71+
72+
void PrefixStore::append(const std::string& key, const std::vector<char>& data) {
73+
if (!store_.has_v2_support()) {
74+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("underlying store doesn't support append");
75+
}
76+
store_.append(joinKey(key), data);
77+
}
78+
79+
int64_t PrefixStore::add(const std::string& key, int64_t value) {
80+
if (!store_.has_v2_support()) {
81+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("underlying store doesn't support append");
82+
}
83+
return store_.add(joinKey(key), value);
84+
}
85+
4686
} // namespace rendezvous
4787
} // namespace gloo

gloo/rendezvous/prefix_store.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ class PrefixStore : public Store {
3434
const std::vector<std::string>& keys,
3535
const std::chrono::milliseconds& timeout) override;
3636

37+
virtual bool has_v2_support() override;
38+
virtual std::vector<std::vector<char>> multi_get(const std::vector<std::string>& keys) override;
39+
virtual void multi_set(const std::vector<std::string>& keys, const std::vector<std::vector<char>>& values) override;
40+
virtual void append(const std::string& key, const std::vector<char>& data) override;
41+
virtual int64_t add(const std::string& key, int64_t value) override;
42+
3743
protected:
3844
const std::string prefix_;
3945
Store& store_;

gloo/rendezvous/store.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#include <vector>
1414

1515
#include "gloo/common/logging.h"
16+
#include "gloo/common/error.h"
17+
18+
//can be used by upstream users to know whether this is available or not.
19+
#define GLOO_STORE_HAS_STORE_V2 1
1620

1721
namespace gloo {
1822
namespace rendezvous {
@@ -39,6 +43,27 @@ class Store {
3943
wait(keys);
4044
}
4145

46+
virtual bool has_v2_support() {
47+
// If True, the following operations are guaranteed to be efficiently and correclty implemented.
48+
return false;
49+
}
50+
51+
virtual std::vector<std::vector<char>> multi_get(const std::vector<std::string>& /*keys*/) {
52+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("this store doesn't support multi_get");
53+
}
54+
55+
virtual void multi_set(const std::vector<std::string>& /*keys*/, const std::vector<std::vector<char>>& /*values*/) {
56+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("this store doesn't support multi_set");
57+
}
58+
59+
virtual void append(const std::string& key, const std::vector<char>& /*data*/) {
60+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("this store doesn't support append");
61+
}
62+
63+
virtual int64_t add(const std::string& key, int64_t value) {
64+
GLOO_THROW_INVALID_OPERATION_EXCEPTION("this store doesn't support add");
65+
}
66+
4267
};
4368

4469
} // namespace rendezvous

0 commit comments

Comments
 (0)