Skip to content

First Part of Internal Ray API Refactor - #1173

Merged
robertnishihara merged 25 commits into
ray-project:masterfrom
pcmoritz:c++-api
Dec 14, 2017
Merged

robertnishihara merged 25 commits into
ray-project:masterfrom
pcmoritz:c++-api

Conversation

@pcmoritz

@pcmoritz pcmoritz commented Oct 31, 2017 •

Copy link
Copy Markdown
Contributor

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.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2237/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2238/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2239/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2240/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2241/
Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2281/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2420/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2425/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Build finished. Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2435/
Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2752/
Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2751/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2754/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2755/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2756/
Test PASSed.

@concretevitamin concretevitamin left a comment

Copy link
Copy Markdown
Contributor

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!

return true;
}

int TableAdd_RedisCommand(RedisModuleCtx *ctx,

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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;

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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);

Copy link
Copy Markdown
Contributor

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

@pcmoritz pcmoritz Dec 14, 2017 •

Copy link
Copy Markdown
Contributor Author

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"readonly"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

Comment thread src/ray/constants.h Outdated
constexpr int64_t kUniqueIDSize = 20;

/// Prefix for the object table keys in redis.
constexpr char ObjectTablePrefix[] = "ObjectTable";

Copy link
Copy Markdown
Contributor

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";

Copy link
Copy Markdown
Contributor Author

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'

Comment thread src/ray/gcs/client.h Outdated
std::shared_ptr<RedisContext> context_;
};

class SyncGSCClient {

Copy link
Copy Markdown
Contributor

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()).

Copy link
Copy Markdown
Contributor Author

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.

Comment thread src/ray/util/macros.h
#define RAY_UTIL_MACROS_H

// From Google gutil
#ifndef RAY_DISALLOW_COPY_AND_ASSIGN

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread src/ray/util/logging.h

namespace ray {

// Stubbed versions of macros defined in glog/logging.h, intended for

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love these macros.

Comment thread src/ray/status.h
#include "ray/util/visibility.h"

// Return the given status if it is not OK.
#define RAY_RETURN_NOT_OK(s) \

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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 :)

Comment thread src/ray/status.h
// non-const method, all threads accessing the same Status must use
// external synchronization.

// Adapted from Apache Arrow, Apache Kudu, TensorFlow

Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2791/
Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Test FAILed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2795/
Test FAILed.

@AmplabJenkins

Copy link
Copy Markdown

Merged build finished. Test PASSed.

@AmplabJenkins

Copy link
Copy Markdown

Test PASSed.
Refer to this link for build results (access rights to CI server needed):
https://amplab.cs.berkeley.edu/jenkins//job/Ray-PRB/2794/
Test PASSed.

Comment thread src/ray/constants.h
/// Prefix for the object table keys in redis.
constexpr char kObjectTablePrefix[] = "ObjectTable";
/// Prefix for the task table keys in redis.
constexpr char kTaskTablePrefix[] = "TaskTable";

Copy link
Copy Markdown
Collaborator

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's right!

Copy link
Copy Markdown
Contributor

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.

Comment thread src/ray/gcs/client.h
#include "ray/id.h"
#include "ray/status.h"
#include "ray/gcs/tables.h"
#include "ray/util/logging.h"

Copy link
Copy Markdown
Collaborator

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

Copy link
Copy Markdown
Contributor Author

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"

Copy link
Copy Markdown
Collaborator

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as the above

@concretevitamin concretevitamin left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread src/ray/constants.h
/// Prefix for the object table keys in redis.
constexpr char kObjectTablePrefix[] = "ObjectTable";
/// Prefix for the task table keys in redis.
constexpr char kTaskTablePrefix[] = "TaskTable";

Copy link
Copy Markdown
Contributor

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.

Comment thread src/ray/gcs/client.cc

namespace gcs {

AsyncGcsClient::AsyncGcsClient() {}

Copy link
Copy Markdown
Contributor

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.

Comment thread src/ray/gcs/client.h

class AsyncGcsClient {
public:
AsyncGcsClient();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

Comment thread src/ray/gcs/client.h
std::string *name,
std::string *data);

Status AddExport(const std::string &driver_id, std::string &export_data);

Copy link
Copy Markdown
Contributor

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 = "";

Copy link
Copy Markdown
Contributor

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){};

Copy link
Copy Markdown
Contributor

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);

Copy link
Copy Markdown
Contributor

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() {}

Copy link
Copy Markdown
Contributor

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.

@robertnishihara
robertnishihara merged commit cac5f47 into ray-project:master Dec 14, 2017
@robertnishihara
robertnishihara deleted the c++-api branch December 14, 2017 22:54
@robertnishihara

Copy link
Copy Markdown
Collaborator

Thanks @concretevitamin, we'll fix the nits in a follow up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants