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

Move plasma, common, and photon into the Ray repository. #1

Merged
merged 111 commits into from
Oct 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
68056da
Initial commit
pcmoritz Aug 13, 2016
81bfd8c
add readme
robertnishihara Aug 13, 2016
97087b0
initial version of object store
pcmoritz Aug 14, 2016
ff13386
Merge pull request #3 from pcmoritz/initial
robertnishihara Aug 14, 2016
e5ecd49
minimal travis file
robertnishihara Aug 14, 2016
504044c
Merge pull request #2 from pcmoritz/travis
pcmoritz Aug 14, 2016
c01e992
Merge pull request #1 from pcmoritz/readme
pcmoritz Aug 16, 2016
7a18347
cleanup
pcmoritz Aug 15, 2016
88a1487
Merge pull request #5 from pcmoritz/cleanup
robertnishihara Aug 16, 2016
29f0489
Remove directories as well with make clean.
robertnishihara Aug 16, 2016
535f440
add python client
pcmoritz Aug 16, 2016
1b22b54
Merge pull request #4 from pcmoritz/python
robertnishihara Aug 16, 2016
6db8d1c
fix error handling
pcmoritz Aug 16, 2016
6511ea8
Merge pull request #8 from pcmoritz/fix
robertnishihara Aug 16, 2016
1b66ac5
Basic Python unit tests.
robertnishihara Aug 16, 2016
b6b17f3
Retry if plasma client fails to connect to plasma store.
robertnishihara Aug 17, 2016
36af794
Merge pull request #9 from pcmoritz/test
pcmoritz Aug 17, 2016
32fadd5
Merge pull request #6 from pcmoritz/make
pcmoritz Aug 17, 2016
23327a1
add plasma manager
pcmoritz Aug 17, 2016
3d6d1e8
Test plasma manager.
robertnishihara Aug 18, 2016
8744725
Test Python 3 in Travis.
robertnishihara Aug 19, 2016
98b80ea
Merge pull request #11 from pcmoritz/python
pcmoritz Aug 19, 2016
e162731
clean up tests
pcmoritz Aug 22, 2016
a049084
Merge pull request #7 from pcmoritz/manager
robertnishihara Aug 22, 2016
ad1a845
remove C struct duplication and python plasma manager
pcmoritz Sep 5, 2016
dd23a68
Merge pull request #12 from pcmoritz/refactor
robertnishihara Sep 6, 2016
a62c0f8
Allow arbitrary number of connections (#13)
pcmoritz Sep 8, 2016
04737f3
Run clang-format and check in Travis CI (#14)
rshin Sep 8, 2016
d52bf7d
Use dlmalloc to manage shared memory (#15)
rshin Sep 10, 2016
494903c
fix compiler warnings (#17)
pcmoritz Sep 11, 2016
a35de3b
Initial commit
pcmoritz Sep 11, 2016
96a5920
Fix some bugs (#22)
robertnishihara Sep 13, 2016
7d629d4
Adding object table (#1)
pcmoritz Sep 14, 2016
72361c9
Add metadata handling (#23)
robertnishihara Sep 14, 2016
28c19a3
Catch incorrect arguments to PlasmaClient constructor. (#18)
robertnishihara Sep 14, 2016
13560bd
Fix offset in get_malloc_mapinfo. (#24)
robertnishihara Sep 15, 2016
0198a0d
make plasma robust wrt to number of open file descriptors (#25)
pcmoritz Sep 15, 2016
73f4b96
Sockets (#3)
Sep 15, 2016
4521e5f
Initial commit
pcmoritz Sep 17, 2016
0b7d81c
API for creating task specifications (#5)
pcmoritz Sep 17, 2016
9e4203c
Update README.md
robertnishihara Sep 17, 2016
77d5365
Merge pull request #1 from ray-project/name
pcmoritz Sep 17, 2016
ff11ee2
Convert to streaming sockets (#7)
Sep 17, 2016
b18f214
Make it possible to read and write data that is not null-terminated (#9)
pcmoritz Sep 18, 2016
c238ae4
do not re-download and rebuild redis if it already exists (#10)
pcmoritz Sep 18, 2016
37f035d
implementing reading and writing tasks (#11)
pcmoritz Sep 19, 2016
d11161b
make static libraries (#13)
pcmoritz Sep 19, 2016
6c6f2d0
Implement object table API (#16)
pcmoritz Sep 21, 2016
313241e
Asynchronous Redis IPC (#14)
Sep 21, 2016
7a07954
task queue tests and extensions (#18)
pcmoritz Sep 23, 2016
d41566a
Implement delete and contains for plasma client and store. (#28)
robertnishihara Sep 23, 2016
e1b8711
Redis logging (#17)
pcmoritz Sep 24, 2016
7907992
[WIP] Event loop refactoring (#19)
pcmoritz Sep 24, 2016
1e08629
fix submit_task for task queue (#21)
pcmoritz Sep 25, 2016
db8c0ac
Refactor state database (#22)
pcmoritz Sep 26, 2016
675ea40
Update README.md
pcmoritz Sep 26, 2016
9f26c2d
Merge pull request #3 from ray-project/rename
robertnishihara Sep 26, 2016
631de92
Build redis before libcommon. (#20)
robertnishihara Sep 26, 2016
184242a
Add basic travis file and lint check.
robertnishihara Sep 27, 2016
57214b3
Fixes.
robertnishihara Sep 27, 2016
2776d6a
Fix permissions.
robertnishihara Sep 27, 2016
21d6ceb
Merge pull request #4 from ray-project/trav
pcmoritz Sep 27, 2016
084220b
Allow reading/writing generic message types, not just tasks. (#24)
robertnishihara Sep 28, 2016
ff8018d
First pass at local scheduler (#2)
pcmoritz Sep 28, 2016
227eab3
Use doxygen for generating documentation (#29)
robertnishihara Sep 29, 2016
e21e9f6
API for task log and scheduled task (#25)
pcmoritz Sep 30, 2016
9c223a1
Increase dlmalloc's granularity to 1 << 25 (#30)
rshin Sep 30, 2016
eb71c2e
Increase allocation granularity dynamically with each MMAP call (#32)
ujvl Oct 1, 2016
f4037ad
Plasma fixes (#29)
Oct 4, 2016
eabfa9a
Stephanie's plasma refactor (#31)
pcmoritz Oct 4, 2016
5a0725c
Increase dlmalloc threshold along with granularity (#33)
ujvl Oct 4, 2016
da5ec3b
add documentation for tasks (#30)
pcmoritz Oct 4, 2016
64c5e08
Let workers get tasks from local scheduler. (#5)
robertnishihara Oct 4, 2016
8e04453
Python API for constructing tasks (#28)
pcmoritz Oct 4, 2016
872e68b
submit task to redis
pcmoritz Oct 4, 2016
4329afb
rename TASK_* -> TASK_STATUS_* (#31)
pcmoritz Oct 4, 2016
67677c3
update documentation and common
pcmoritz Oct 5, 2016
4204500
Fix formatting. (#32)
robertnishihara Oct 5, 2016
a7a9634
fixes
pcmoritz Oct 5, 2016
0f97855
More fixes.
robertnishihara Oct 5, 2016
a3e01c8
Merge pull request #6 from ray-project/submit-redis
robertnishihara Oct 5, 2016
75441a1
add valgrind tests (#33)
pcmoritz Oct 5, 2016
e8e4aa6
add valgrind check
pcmoritz Oct 6, 2016
a048ad9
Merge pull request #7 from ray-project/valgrind
robertnishihara Oct 6, 2016
90a6a99
Clean up task interface and add testing. (#34)
robertnishihara Oct 6, 2016
7be1a93
Move common C extension module into a different C file. (#35)
robertnishihara Oct 7, 2016
18934c3
Make photon client into a C extension. (#8)
robertnishihara Oct 7, 2016
e9a336a
Fix incorrect free. (#9)
robertnishihara Oct 7, 2016
7f51511
Generate return object IDs in the task constructor. (#36)
robertnishihara Oct 7, 2016
94ad12f
Get valgrind in place for plasma (#35)
pcmoritz Oct 12, 2016
6290cab
fix compiler warning for linux
pcmoritz Oct 12, 2016
50fb53f
fix compiler warnings on macOS
pcmoritz Oct 12, 2016
832888d
fix formating
pcmoritz Oct 12, 2016
1adafee
Fix signature of create_object. (#39)
robertnishihara Oct 12, 2016
1829850
Make warnings errors
pcmoritz Oct 12, 2016
7e23b87
Merge pull request #38 from ray-project/fixwarnings
Oct 12, 2016
5ad8e14
Allow clients to subscribe to notifications about sealed objects. (#40)
robertnishihara Oct 15, 2016
f189ca7
Send a one byte message in send_fd because otherwise it sometimes han…
robertnishihara Oct 15, 2016
e57b879
Fixes for implementing Plasma fetch (#39)
Oct 18, 2016
da3a312
Move get_client_id to db.h (#40)
Oct 18, 2016
ddfbd70
Plasma fetch (#36)
Oct 19, 2016
63ec244
Connect local scheduler to Plasma. (#11)
robertnishihara Oct 19, 2016
d19f7ad
Implement plasma_release. (#42)
robertnishihara Oct 21, 2016
db63757
Prevent ObjectIDs from being pickled. (#42)
robertnishihara Oct 21, 2016
7c1b2f7
Remove git submodules and C++ files.
robertnishihara Oct 25, 2016
1915539
Rearrange files to prepare to merge into Ray.
robertnishihara Oct 25, 2016
5165b41
Merge remote-tracking branch 'r1remote/moveout' into switch
robertnishihara Oct 25, 2016
ad55166
Rearrange local scheduler files to prepare to merge into Ray.
robertnishihara Oct 25, 2016
6a5ddae
Merge remote-tracking branch 'r1remote/moveout' into switch
robertnishihara Oct 25, 2016
02d4050
Rearrange plasma files to prepare for merging into Ray.
robertnishihara Oct 25, 2016
8c48410
Merge remote-tracking branch 'r1remote/moveout' into switch
robertnishihara Oct 25, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,17 +1,3 @@
[submodule "thirdparty/grpc"]
path = thirdparty/grpc
url = https://github.com/grpc/grpc
ignore = dirty
[submodule "thirdparty/numbuf"]
path = thirdparty/numbuf
url = https://github.com/ray-project/numbuf.git
[submodule "thirdparty/arrow"]
path = thirdparty/arrow
url = https://github.com/ray-project/arrow.git
[submodule "thirdparty/python"]
path = thirdparty/python
url = https://github.com/austinsc/python.git
ignore = dirty
[submodule "thirdparty/hiredis"]
path = thirdparty/hiredis
url = https://github.com/redis/hiredis.git
46 changes: 46 additions & 0 deletions src/common/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
CC = gcc
CFLAGS = -g -Wall --std=c99 -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=200809L -fPIC -I. -Ithirdparty -Ithirdparty/ae -Wno-typedef-redefinition -Werror
BUILD = build

all: hiredis $(BUILD)/libcommon.a

$(BUILD)/libcommon.a: event_loop.o common.o task.o io.o state/redis.o thirdparty/ae/ae.o
ar rcs $@ $^

$(BUILD)/common_tests: test/common_tests.c $(BUILD)/libcommon.a
$(CC) -o $@ test/common_tests.c $(BUILD)/libcommon.a $(CFLAGS)

$(BUILD)/db_tests: hiredis test/db_tests.c $(BUILD)/libcommon.a
$(CC) -o $@ test/db_tests.c $(BUILD)/libcommon.a thirdparty/hiredis/libhiredis.a $(CFLAGS)

$(BUILD)/io_tests: test/io_tests.c $(BUILD)/libcommon.a
$(CC) -o $@ $^ $(CFLAGS)

$(BUILD)/task_tests: test/task_tests.c $(BUILD)/libcommon.a
$(CC) -o $@ $^ $(CFLAGS)

$(BUILD)/redis_tests: hiredis test/redis_tests.c $(BUILD)/libcommon.a logging.h
$(CC) -o $@ test/redis_tests.c logging.c $(BUILD)/libcommon.a thirdparty/hiredis/libhiredis.a $(CFLAGS)

clean:
rm -f *.o state/*.o test/*.o thirdparty/ae/*.o
rm -rf $(BUILD)/*

redis:
cd thirdparty ; bash ./build-redis.sh

hiredis:
git submodule update --init --recursive -- "thirdparty/hiredis" ; cd thirdparty/hiredis ; make

test: hiredis redis $(BUILD)/common_tests $(BUILD)/db_tests $(BUILD)/io_tests $(BUILD)/task_tests $(BUILD)/redis_tests FORCE
./thirdparty/redis-3.2.3/src/redis-server &
sleep 1s ; ./build/common_tests ; ./build/db_tests ; ./build/io_tests ; ./build/task_tests ; ./build/redis_tests

valgrind: test
valgrind --leak-check=full --error-exitcode=1 ./build/common_tests
valgrind --leak-check=full --error-exitcode=1 ./build/db_tests
valgrind --leak-check=full --error-exitcode=1 ./build/io_tests
valgrind --leak-check=full --error-exitcode=1 ./build/task_tests
valgrind --leak-check=full --error-exitcode=1 ./build/redis_tests

FORCE:
Empty file added src/common/build/.gitkeep
Empty file.
36 changes: 36 additions & 0 deletions src/common/common.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "common.h"

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

const unique_id NIL_ID = {{255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
255, 255, 255, 255, 255, 255, 255, 255, 255, 255}};

unique_id globally_unique_id(void) {
/* Use /dev/urandom for "real" randomness. */
int fd;
if ((fd = open("/dev/urandom", O_RDONLY)) == -1) {
LOG_ERR("Could not generate random number");
}
unique_id result;
read(fd, &result.id[0], UNIQUE_ID_SIZE);
close(fd);
return result;
}

char *sha1_to_hex(const unsigned char *sha1, char *buffer) {
static const char hex[] = "0123456789abcdef";
char *buf = buffer;

for (int i = 0; i < UNIQUE_ID_SIZE; i++) {
unsigned int val = *sha1++;
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];
}
*buf = '\0';

return buffer;
}
61 changes: 61 additions & 0 deletions src/common/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#ifndef COMMON_H
#define COMMON_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#ifndef RAY_COMMON_DEBUG
#define LOG_DEBUG(M, ...)
#else
#define LOG_DEBUG(M, ...) \
fprintf(stderr, "[DEBUG] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)
#endif

#define LOG_ERR(M, ...) \
fprintf(stderr, "[ERROR] (%s:%d: errno: %s) " M "\n", __FILE__, __LINE__, \
errno == 0 ? "None" : strerror(errno), ##__VA_ARGS__)

#define LOG_INFO(M, ...) \
fprintf(stderr, "[INFO] (%s:%d) " M "\n", __FILE__, __LINE__, ##__VA_ARGS__)

#define CHECK(COND) \
do { \
if (!(COND)) { \
LOG_ERR("Check failure: %s", #COND); \
exit(-1); \
} \
} while (0);

#define CHECKM(COND, M, ...) \
do { \
if (!(COND)) { \
LOG_ERR("Check failure: %s \n" M, #COND, ##__VA_ARGS__); \
exit(-1); \
} \
} while (0);

#define UNIQUE_ID_SIZE 20

/* Cleanup method for running tests with the greatest library.
* Runs the test, then clears the Redis database. */
#define RUN_REDIS_TEST(context, test) \
RUN_TEST(test); \
freeReplyObject(redisCommand(context, "FLUSHALL"));

typedef struct { unsigned char id[UNIQUE_ID_SIZE]; } unique_id;

extern const unique_id NIL_ID;

/* Generate a globally unique ID. */
unique_id globally_unique_id(void);

/* Convert a 20 byte sha1 hash to a hexdecimal string. This function assumes
* that buffer points to an already allocated char array of size 2 *
* UNIQUE_ID_SIZE + 1 */
char *sha1_to_hex(const unsigned char *sha1, char *buffer);

typedef unique_id object_id;

#endif
33 changes: 33 additions & 0 deletions src/common/doc/tasks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Task specifications, task instances and task logs

A *task specification* contains all information that is needed for computing
the results of a task:

- The function ID of the function that executes the task
- The arguments (either object IDs for pass by reference
or values for pass by value)
- The IDs of the result objects

From these, a task ID can be computed which is also stored in the task
specification.

A *task instance* represents one execution of a task specification.
It consists of:

- A scheduling state (WAITING, SCHEDULED, RUNNING, DONE)
- The target node where the task is scheduled or executed
- A unique task instance ID that identifies the particular execution
of the task.

The task data structures are defined in `common/task.h`.

The *task log* is a mapping from the task instance ID to a sequence of
updates to the status of the task instance. It is updated by various parts
of the system:

1. The local scheduler writes it with status WAITING when submits a task to the global scheduler
2. The global scheduler appends an update WAITING -> SCHEDULED together with the node ID when assigning the task to a local scheduler
3. The local scheduler appends an update SCHEDULED -> RUNNING when it assigns a task to a worker
4. The local scheduler appends an update RUNNING -> DONE when the task finishes execution

The task log is defined in `common/state/task_log.h`.
62 changes: 62 additions & 0 deletions src/common/event_loop.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include "event_loop.h"

#include "common.h"
#include <errno.h>

#define INITIAL_EVENT_LOOP_SIZE 1024

event_loop *event_loop_create() {
return aeCreateEventLoop(INITIAL_EVENT_LOOP_SIZE);
}

void event_loop_destroy(event_loop *loop) {
/* Clean up timer events. This is to make valgrind happy. */
aeTimeEvent *te = loop->timeEventHead;
while (te) {
aeTimeEvent *next = te->next;
free(te);
te = next;
}
aeDeleteEventLoop(loop);
}

void event_loop_add_file(event_loop *loop,
int fd,
int events,
event_loop_file_handler handler,
void *context) {
/* Try to add the file descriptor. */
int err = aeCreateFileEvent(loop, fd, events, handler, context);
/* If it cannot be added, increase the size of the event loop. */
if (err == AE_ERR && errno == ERANGE) {
err = aeResizeSetSize(loop, 3 * aeGetSetSize(loop) / 2);
CHECK(err == AE_OK);
err = aeCreateFileEvent(loop, fd, events, handler, context);
}
/* In any case, test if there were errors. */
CHECK(err == AE_OK);
}

void event_loop_remove_file(event_loop *loop, int fd) {
aeDeleteFileEvent(loop, fd, EVENT_LOOP_READ | EVENT_LOOP_WRITE);
}

int64_t event_loop_add_timer(event_loop *loop,
int64_t milliseconds,
event_loop_timer_handler handler,
void *context) {
return aeCreateTimeEvent(loop, milliseconds, handler, context, NULL);
}

void event_loop_remove_timer(event_loop *loop, timer_id timer_id) {
int err = aeDeleteTimeEvent(loop, timer_id);
CHECK(err == AE_OK); /* timer id found? */
}

void event_loop_run(event_loop *loop) {
aeMain(loop);
}

void event_loop_stop(event_loop *loop) {
aeStop(loop);
}
77 changes: 77 additions & 0 deletions src/common/event_loop.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#ifndef EVENT_LOOP_H
#define EVENT_LOOP_H

#include <stdint.h>
#include "ae/ae.h"

typedef long long timer_id;

typedef aeEventLoop event_loop;

/* File descriptor is readable. */
#define EVENT_LOOP_READ AE_READABLE

/* File descriptor is writable. */
#define EVENT_LOOP_WRITE AE_WRITABLE

/* Constant specifying that the timer is done and it will be removed. */
#define EVENT_LOOP_TIMER_DONE AE_NOMORE

/* Signature of the handler that will be called when there is a new event
* on the file descriptor that this handler has been registered for. The
* context is the one that was passed into add_file by the user. The
* events parameter indicates which event is available on the file,
* it can be EVENT_LOOP_READ or EVENT_LOOP_WRITE. */
typedef void (*event_loop_file_handler)(event_loop *loop,
int fd,
void *context,
int events);

/* This handler will be called when a timer times out. The id of the timer
* as well as the context that was specified when registering this handler
* are passed as arguments. The return is the number of milliseconds the
* timer shall be reset to or EVENT_LOOP_TIMER_DONE if the timer shall
* not be triggered again. */
typedef int (*event_loop_timer_handler)(event_loop *loop,
timer_id timer_id,
void *context);

/* Create and return a new event loop. */
event_loop *event_loop_create();

/* Deallocate space associated with the event loop that was created
* with the "create" function. */
void event_loop_destroy(event_loop *loop);

/* Register a handler that will be called any time a new event happens on
* a file descriptor. Can specify a context that will be passed as an
* argument to the handler. Currently there can only be one handler per file.
* The events parameter specifies which events we listen to: EVENT_LOOP_READ
* or EVENT_LOOP_WRITE. */
void event_loop_add_file(event_loop *loop,
int fd,
int events,
event_loop_file_handler handler,
void *context);

/* Remove a registered file event handler from the event loop. */
void event_loop_remove_file(event_loop *loop, int fd);

/* Register a handler that will be called after a time slice of
* "milliseconds" milliseconds. Can specify a context that will be passed
* as an argument to the handler. Return the id of the time event. */
int64_t event_loop_add_timer(event_loop *loop,
int64_t milliseconds,
event_loop_timer_handler handler,
void *context);

/* Remove a registered time event handler from the event loop. */
void event_loop_remove_timer(event_loop *loop, timer_id timer_id);

/* Run the event loop. */
void event_loop_run(event_loop *loop);

/* Stop the event loop. */
void event_loop_stop(event_loop *loop);

#endif
Loading