-
Notifications
You must be signed in to change notification settings - Fork 6.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First Part of Internal Ray API Refactor #1173
Conversation
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test FAILed. |
Test FAILed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Build finished. Test FAILed. |
Test FAILed. |
Merged build finished. Test FAILed. |
Test FAILed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test PASSed. |
Test PASSed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick look, hope it helps!
@@ -388,6 +388,46 @@ bool PublishObjectNotification(RedisModuleCtx *ctx, | |||
return true; | |||
} | |||
|
|||
int TableAdd_RedisCommand(RedisModuleCtx *ctx, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment? E.g. // Experimental usage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doing that now
|
||
RedisModuleKey *key; | ||
key = OpenPrefixedKey(ctx, "T:", id, REDISMODULE_READ); | ||
size_t len; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In local scope I think it's a good practice to always initialize: size_t len = 0;
. I could be misremembering, but such a statement was an undefined behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, you are right, it is undefined behavior in the sense that if it is accessed the value is undefined (in many cases it will just be whatever was in the corresponding memory location on the stack). In this case it would be fine because RedisModule_StringDMA
will initialize the memory location and not read before it, but I'm initializing it nonetheless :)
RedisModuleKey *key; | ||
key = OpenPrefixedKey(ctx, "T:", id, REDISMODULE_READ); | ||
size_t len; | ||
char *buf = RedisModule_StringDMA(key, &len, REDISMODULE_READ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add const, and put asterisk right after the type? const char* buf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added the const; the asterisk is currently encoded that way in the clang-format file and enforced (we started as a C project, remember), we will change everywhere consistently with a future PR...
} | ||
|
||
if (RedisModule_CreateCommand(ctx, "ray.table_lookup", | ||
TableLookup_RedisCommand, "write", 0, 0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"readonly"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
src/ray/constants.h
Outdated
constexpr int64_t kUniqueIDSize = 20; | ||
|
||
/// Prefix for the object table keys in redis. | ||
constexpr char ObjectTablePrefix[] = "ObjectTable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be consistent with naming?: kObjectTablePrefix
?
Less importantly, here's another way of initializing string constants:
constexpr char* const kObjectTablePrefix = "ObjectTable";
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did the first, for the second, the compiler complains with
error: ISO C++11 does not allow conversion from string literal to 'char *const'
src/ray/gcs/client.h
Outdated
std::shared_ptr<RedisContext> context_; | ||
}; | ||
|
||
class SyncGSCClient { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S and C reordered
Also, why not Gcs? https://google.github.io/styleguide/cppguide.html#Function_Names says Prefer to capitalize acronyms as single words (i.e. StartRpc(), not StartRPC()).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, including the capitalization. I agree it is more readable if there is a followup word.
#define RAY_UTIL_MACROS_H | ||
|
||
// From Google gutil | ||
#ifndef RAY_DISALLOW_COPY_AND_ASSIGN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
|
||
namespace ray { | ||
|
||
// Stubbed versions of macros defined in glog/logging.h, intended for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love these macros.
#include "ray/util/visibility.h" | ||
|
||
// Return the given status if it is not OK. | ||
#define RAY_RETURN_NOT_OK(s) \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's be consistent with a bunch of codebase out there and use RAY_RETURN_IF_ERROR
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer this one since it it the one used by arrow and we already use it in a bunch of places in plasma (which was merged with arrow). But no big deal, if you strongly prefer the other way we can also rename it :)
// non-const method, all threads accessing the same Status must use | ||
// external synchronization. | ||
|
||
// Adapted from Apache Arrow, Apache Kudu, TensorFlow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Let's return Status everywhere when it makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Merged build finished. Test PASSed. |
Test PASSed. |
Merged build finished. Test FAILed. |
Test FAILed. |
Merged build finished. Test PASSed. |
Test PASSed. |
/// Prefix for the object table keys in redis. | ||
constexpr char kObjectTablePrefix[] = "ObjectTable"; | ||
/// Prefix for the task table keys in redis. | ||
constexpr char kTaskTablePrefix[] = "TaskTable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These prefixes aren't used yet, right? We're still hardcoding TT
and OI
and OL
and things like that in various places in the code so at some point we'll have to replace those with these constants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's right!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a more "correct" way (at least how I was educated at my previous employer :p) of defining constants are,
- In header:
extern const int64_t kUniqueIDSize; ...; extern const char* const kObjectTablePrefix;
- In
.cc
:const int64_t kUniqueIDSize = 20; ...; const char* const kObjectTablePrefix = "ObjectTable"
Just an FYI, no need to do it this way in this PR.
#include "ray/id.h" | ||
#include "ray/status.h" | ||
#include "ray/gcs/tables.h" | ||
#include "ray/util/logging.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be more alphabetical to move ray/gcs
before ray/id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
things are ordered in such a way that includes that are in more nested directories are further down
extern "C" { | ||
#include "hiredis/async.h" | ||
#include "hiredis/hiredis.h" | ||
#include "hiredis/adapters/ae.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe move adapters
above async
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heroic PR, @pcmoritz! Just a few nits.
/// Prefix for the object table keys in redis. | ||
constexpr char kObjectTablePrefix[] = "ObjectTable"; | ||
/// Prefix for the task table keys in redis. | ||
constexpr char kTaskTablePrefix[] = "TaskTable"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a more "correct" way (at least how I was educated at my previous employer :p) of defining constants are,
- In header:
extern const int64_t kUniqueIDSize; ...; extern const char* const kObjectTablePrefix;
- In
.cc
:const int64_t kUniqueIDSize = 20; ...; const char* const kObjectTablePrefix = "ObjectTable"
Just an FYI, no need to do it this way in this PR.
|
||
namespace gcs { | ||
|
||
AsyncGcsClient::AsyncGcsClient() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since these are empty, might be cleaner to just remove ctor & dtor declarations and definitions.
|
||
class AsyncGcsClient { | ||
public: | ||
AsyncGcsClient(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove?
std::string *name, | ||
std::string *data); | ||
|
||
Status AddExport(const std::string &driver_id, std::string &export_data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const for 2nd arg
} | ||
int64_t callback_index = reinterpret_cast<int64_t>(privdata); | ||
redisReply *reply = reinterpret_cast<redisReply *>(r); | ||
std::string data = ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just std::string data;
suffices, I think.
RedisCallback &get(int64_t callback_index); | ||
|
||
private: | ||
RedisCallbackManager() : num_callbacks(0){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should keep it simple if possible: remove num_callbacks
and its maintenance, since it's just callbacks_.size()
.
|
||
int64_t add(const RedisCallback &function); | ||
|
||
RedisCallback &get(int64_t callback_index); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not keep it more consistent to name as Add(..) and Get(..)?
|
||
class RedisContext { | ||
public: | ||
RedisContext() {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove empty ctor, dtor.
Thanks @concretevitamin, we'll fix the nits in a follow up PR. |
This PR imports the new C++ APIs for the GCS into the repo, sets up the build environment for them, implements the task classes and as an example how to use those implements object table and task table lookups, as well as tests for the above.
It does NOT change any of the existing calls to the new calls.