ray/src/common/common.c
Alexey Tumanov 46a887039e Global scheduler - per-task transfer-aware policy (#145)
* global scheduler with object transfer cost awareness -- upstream rebase

* debugging global scheduler: multiple subscriptions

* global scheduler: utarray push bug fix; tasks change state to SCHEDULED

* change global scheduler test to be an integraton test

* unit and integration tests are passing for global scheduler

* improve global scheduler test: break up into several

* global scheduler checkpoint: fix photon object id bug in test

* test with timesync between object and task notifications; TODO: handle OoO object+task notifications in GS

* fallback to base policy if no object dependencies are cached (may happen due to OoO object+task notification arrivals

* clean up printfs; handle a missing LS in LS cache

* Minor changes to Python test and factor out some common code.

* refactoring handle task waiting

* addressing comments

* log_info -> log_debug

* Change object ID printing.

* PRId64 merge

* Python 3 fix.

* PRId64.

* Python 3 fix.

* resurrect differentiation between no args and missing object info; spacing

* Valgrind fix.

* Run all global scheduler tests in valgrind.

* clang format

* Comments and documentation changes.

* Minor cleanups.

* fix whitespace

* Fix.

* Documentation fix.
2016-12-22 03:11:46 -08:00

57 lines
1.5 KiB
C

#include "common.h"
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "io.h"
/* This is used to define the array of object IDs. */
const UT_icd object_id_icd = {sizeof(object_id), NULL, NULL, NULL};
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}};
const unsigned char NIL_DIGEST[DIGEST_SIZE] = {0};
unique_id globally_unique_id(void) {
/* Use /dev/urandom for "real" randomness. */
int fd;
int const flags = 0 /* for Windows compatibility */;
if ((fd = open("/dev/urandom", O_RDONLY, flags)) == -1) {
LOG_ERROR("Could not generate random number");
}
unique_id result;
CHECK(read_bytes(fd, &result.id[0], UNIQUE_ID_SIZE) >= 0);
close(fd);
return result;
}
bool object_ids_equal(object_id first_id, object_id second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
bool object_id_is_nil(object_id id) {
return object_ids_equal(id, NIL_OBJECT_ID);
}
bool db_client_ids_equal(db_client_id first_id, db_client_id second_id) {
return UNIQUE_ID_EQ(first_id, second_id);
}
char *object_id_to_string(object_id obj_id, char *id_string, int id_length) {
CHECK(id_length >= ID_STRING_SIZE);
static const char hex[] = "0123456789abcdef";
char *buf = id_string;
for (int i = 0; i < UNIQUE_ID_SIZE; i++) {
unsigned int val = obj_id.id[i];
*buf++ = hex[val >> 4];
*buf++ = hex[val & 0xf];
}
*buf = '\0';
return id_string;
}