Skip to content
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

Merged
merged 25 commits into from
Dec 14, 2017

Conversation

pcmoritz
Copy link
Contributor

@pcmoritz pcmoritz commented Oct 31, 2017

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test FAILed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Build finished. Test FAILed.

@AmplabJenkins
Copy link

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

Merged build finished. Test FAILed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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.

Copy link
Contributor

@concretevitamin concretevitamin left a 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,
Copy link
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
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
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
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
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

Copy link
Contributor Author

@pcmoritz pcmoritz Dec 14, 2017

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
Contributor

Choose a reason for hiding this comment

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

"readonly"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

constexpr int64_t kUniqueIDSize = 20;

/// Prefix for the object table keys in redis.
constexpr char ObjectTablePrefix[] = "ObjectTable";
Copy link
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
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'

std::shared_ptr<RedisContext> context_;
};

class SyncGSCClient {
Copy link
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
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.

#define RAY_UTIL_MACROS_H

// From Google gutil
#ifndef RAY_DISALLOW_COPY_AND_ASSIGN
Copy link
Contributor

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
Copy link
Contributor

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) \
Copy link
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
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 :)

// non-const method, all threads accessing the same Status must use
// external synchronization.

// Adapted from Apache Arrow, Apache Kudu, TensorFlow
Copy link
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
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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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

Merged build finished. Test FAILed.

@AmplabJenkins
Copy link

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

Merged build finished. Test PASSed.

@AmplabJenkins
Copy link

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.

/// 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
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
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
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.

#include "ray/id.h"
#include "ray/status.h"
#include "ray/gcs/tables.h"
#include "ray/util/logging.h"
Copy link
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
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
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
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

Copy link
Contributor

@concretevitamin concretevitamin left a 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";
Copy link
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.


namespace gcs {

AsyncGcsClient::AsyncGcsClient() {}
Copy link
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.


class AsyncGcsClient {
public:
AsyncGcsClient();
Copy link
Contributor

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