Skip to content

Commit

Permalink
Use Redis auto memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanie-wang committed Feb 14, 2019
1 parent 71724c9 commit f508521
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
34 changes: 17 additions & 17 deletions src/ray/gcs/redis_module/ray_redis_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ extern RedisChainModule module;
}

// Wrap a Redis command with automatic memory management.
#define AUTO_MEMORY(FUNC) \
#define AUTO_MEMORY(FUNC) \
int FUNC(RedisModuleCtx *ctx, RedisModuleString **argv, int argc) { \
RedisModule_AutoMemory(ctx); \
return redis_commands::FUNC(ctx, argv, argc); \
RedisModule_AutoMemory(ctx); \
return redis_commands::FUNC(ctx, argv, argc); \
}

/// Commands in this namespace can be wrapped with AUTO_MEMORY in the
Expand Down Expand Up @@ -682,28 +682,28 @@ int DebugString_RedisCommand(RedisModuleCtx *ctx, RedisModuleString **argv, int
std::string debug_string = DebugString();
return RedisModule_ReplyWithStringBuffer(ctx, debug_string.data(), debug_string.size());
}

};


namespace auto_memory_redis_commands {
// Wrap all Redis commands with Redis' auto memory management.
AUTO_MEMORY(TableAdd_RedisCommand);
AUTO_MEMORY(TableAppend_RedisCommand);
AUTO_MEMORY(TableLookup_RedisCommand);
AUTO_MEMORY(TableRequestNotifications_RedisCommand);
AUTO_MEMORY(TableCancelNotifications_RedisCommand);
AUTO_MEMORY(TableTestAndUpdate_RedisCommand);
AUTO_MEMORY(DebugString_RedisCommand);
// Wrap all Redis commands with Redis' auto memory management.
AUTO_MEMORY(TableAdd_RedisCommand);
AUTO_MEMORY(TableAppend_RedisCommand);
AUTO_MEMORY(TableLookup_RedisCommand);
AUTO_MEMORY(TableRequestNotifications_RedisCommand);
AUTO_MEMORY(TableCancelNotifications_RedisCommand);
AUTO_MEMORY(TableTestAndUpdate_RedisCommand);
AUTO_MEMORY(DebugString_RedisCommand);
#if RAY_USE_NEW_GCS
AUTO_MEMORY(ChainTableAdd_RedisCommand);
AUTO_MEMORY(ChainTableAppend_RedisCommand);
AUTO_MEMORY(ChainTableAdd_RedisCommand);
AUTO_MEMORY(ChainTableAppend_RedisCommand);
#endif
};

extern "C" {
// Only use commands that have auto memory management.
using namespace auto_memory_redis_commands;
// Only use commands that have auto memory management.
// TODO(swang): Ideally, we would make the commands that don't have auto memory
// management inaccessible instead of just using separate namespaces.
using namespace auto_memory_redis_commands;

/* This function must be present on each Redis module. It is used in order to
* register the commands into the Redis server. */
Expand Down
2 changes: 2 additions & 0 deletions src/ray/gcs/tables.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ Status Log<ID, Data>::Append(const JobID &job_id, const ID &id,
std::shared_ptr<DataT> &dataT, const WriteCallback &done) {
num_appends_++;
auto callback = [this, id, dataT, done](const std::string &data) {
// If data is not empty, then Redis failed to append the entry.
RAY_CHECK(data.empty()) << "TABLE_APPEND command failed: " << data;

if (done != nullptr) {
(done)(client_, id, *dataT);
}
Expand Down

0 comments on commit f508521

Please sign in to comment.