Bug fixes

This commit is contained in:
2025-11-13 23:02:25 +01:00
parent de3391c34a
commit 3048f3d66b
6 changed files with 115 additions and 79 deletions
+3 -3
View File
@@ -30,7 +30,7 @@ Time get_current_time(void)
ok = sys_QueryPerformanceFrequency((LARGE_INTEGER*) &freq);
if (!ok) return INVALID_TIME;
uint64_t res = 1000 * (double) count / freq;
uint64_t res = 1000000000 * (double) count / freq;
return res;
}
#else
@@ -45,12 +45,12 @@ Time get_current_time(void)
uint64_t sec = time.tv_sec;
if (sec > UINT64_MAX / 1000000000)
return INVALID_TIME;
res = sec * 1000;
res = sec * 1000000000;
uint64_t nsec = time.tv_nsec;
if (res > UINT64_MAX - nsec)
return INVALID_TIME;
res += nsec / 1000000;
res += nsec;
return res;
}
+10 -3
View File
@@ -812,6 +812,8 @@ int chunk_server_init(ChunkServer *state, int argc, char **argv, void **contexts
if (remote_port <= 0 || remote_port >= 1<<16)
return -1;
Time current_time = get_current_time();
state->trace = trace;
tcp_context_init(&state->tcp);
@@ -865,6 +867,7 @@ int chunk_server_init(ChunkServer *state, int argc, char **argv, void **contexts
}
state->remote_addr.port = remote_port;
state->disconnect_time = INVALID_TIME;
state->last_sync_time = current_time;
start_connecting_to_metadata_server(state);
@@ -988,12 +991,16 @@ int chunk_server_step(ChunkServer *state, void **contexts, struct pollfd *polled
}
}
// TODO: periodically send a SYNC message
bool should_sync = false;
if (should_sync) {
if (state->disconnect_time == INVALID_TIME) {
Time next_sync_time = state->last_sync_time + (Time) SYNC_INTERVAL * 1000000000;
if (current_time >= next_sync_time) {
if (send_sync_message(state) < 0) {
assert(0); // TODO
}
state->last_sync_time = current_time;
} else {
nearest_deadline(&deadline, next_sync_time);
}
}
// TODO: periodically look for chunks that have their hashes messed up and delete them
+1
View File
@@ -35,6 +35,7 @@ typedef struct {
Address remote_addr;
Time disconnect_time;
Time last_sync_time;
TCP tcp;
+22 -2
View File
@@ -72,12 +72,32 @@ bool hash_set_contains(HashSet *set, SHA256 hash)
int hash_set_merge(HashSet *dst, HashSet src)
{
assert(0); // TODO
HashSet ret;
hash_set_init(&ret);
for (int i = 0; i < dst->count; i++) {
if (hash_set_insert(&ret, dst->items[i]) < 0)
goto error;
}
for (int i = 0; i < src.count; i++) {
if (hash_set_insert(&ret, src.items[i]) < 0)
goto error;
}
hash_set_free(dst);
*dst = ret;
return 0;
error:
hash_set_free(&ret);
return -1;
}
void hash_set_remove_set(HashSet *dst, HashSet src)
{
assert(0); // TODO
for (int i = 0; i < src.count; i++)
hash_set_remove(dst, src.items[i]);
}
void timed_hash_set_init(TimedHashSet *set)
+1 -1
View File
@@ -1088,7 +1088,7 @@ int metadata_server_step(MetadataServer *state, void **contexts, struct pollfd *
Time response_timeout = chunk_server->last_response_time + (Time) RESPONSE_TIME_LIMIT * 1000000000;
if (current_time > response_timeout) {
// TODO: drop the chunk server
assert(0); // TODO: drop the chunk server
continue;
}
nearest_deadline(&next_wakeup, response_timeout);
+26 -18
View File
@@ -580,22 +580,8 @@ static int compare_processes(const void *p1, const void *p2)
return a->wakeup_time - b->wakeup_time;
}
void update_simulation(void)
static int setup_poll_array(void *contexts, struct pollfd *polled)
{
// Order processes by wakeup time. Those with no
// wakeup time go last.
Process *ordered_processes[MAX_PROCESSES];
for (int i = 0; i < num_processes; i++)
ordered_processes[i] = processes[i];
qsort(ordered_processes, num_processes, sizeof(*ordered_processes), compare_processes);
for (int i = 0; i < num_processes; i++) {
current_process = ordered_processes[i];
void *contexts[MAX_CONNS+1];
struct pollfd polled[MAX_CONNS+1];
int num_polled = 0;
for (int j = 0, k = 0; k < current_process->num_desc; j++) {
@@ -662,10 +648,32 @@ void update_simulation(void)
}
}
return num_polled;
}
void update_simulation(void)
{
// Order processes by wakeup time. Those with no
// wakeup time go last.
Process *ordered_processes[MAX_PROCESSES];
for (int i = 0; i < num_processes; i++)
ordered_processes[i] = processes[i];
qsort(ordered_processes, num_processes, sizeof(*ordered_processes), compare_processes);
for (int i = 0; i < num_processes; i++) {
current_process = ordered_processes[i];
void *contexts[MAX_CONNS+1];
struct pollfd polled[MAX_CONNS+1];
int num_polled = setup_poll_array(contexts, polled);
if (num_polled == 0) {
Time wakeup_time = current_process->wakeup_time;
if (wakeup_time == INVALID_TIME) continue;
if (wakeup_time == INVALID_TIME)
continue;
assert(current_time <= wakeup_time);
current_time = wakeup_time;
@@ -703,13 +711,13 @@ void update_simulation(void)
}
if (num_polled < 0) {
// TODO
assert(0); // TODO
}
if (timeout < 0) {
current_process->wakeup_time = INVALID_TIME;
} else {
current_process->wakeup_time = current_time + timeout * 1000000;
current_process->wakeup_time = current_time + (Time) timeout * 1000000;
}
process_poll_array(current_process, contexts, polled, num_polled);