Add client trace lines and fix random client first-operation bug
Add logging infrastructure to client.c mirroring the server's node_log pattern, with trace lines for: init, async put/get/delete, begin transfers, replay requests, all received message types (store ack, fetch chunk response, redirect, reply, get blob response), disconnects, and unexpected messages. Add result/operation trace lines to random_client.c and fix a bug where the random client never started its first operation (the condition `result.type != TOASTYFS_RESULT_VOID` was always false on the first tick since no operation was pending). https://claude.ai/code/session_0184gHjra7fsmSPZ4kppaGhC
This commit is contained in:
+27
-3
@@ -15,6 +15,20 @@
|
||||
|
||||
static uint64_t next_random_client_id = 100;
|
||||
|
||||
static const char *error_name(ToastyFS_Error err)
|
||||
{
|
||||
switch (err) {
|
||||
case TOASTYFS_ERROR_VOID: return "OK";
|
||||
case TOASTYFS_ERROR_OUT_OF_MEMORY: return "OUT_OF_MEMORY";
|
||||
case TOASTYFS_ERROR_UNEXPECTED_MESSAGE: return "UNEXPECTED_MSG";
|
||||
case TOASTYFS_ERROR_REJECTED: return "REJECTED";
|
||||
case TOASTYFS_ERROR_FULL: return "FULL";
|
||||
case TOASTYFS_ERROR_NOT_FOUND: return "NOT_FOUND";
|
||||
case TOASTYFS_ERROR_TRANSFER_FAILED: return "TRANSFER_FAILED";
|
||||
}
|
||||
return "??";
|
||||
}
|
||||
|
||||
static uint64_t rng(void)
|
||||
{
|
||||
#if defined(MAIN_SIMULATION) || defined(MAIN_TEST)
|
||||
@@ -66,6 +80,7 @@ int random_client_init(void *state_, int argc, char **argv,
|
||||
state->tfs = toastyfs_init(client_id, addrs, num_addrs);
|
||||
if (state->tfs == NULL)
|
||||
return -1;
|
||||
state->started = false;
|
||||
|
||||
*timeout = 0;
|
||||
if (pcap < TCP_POLL_CAPACITY) {
|
||||
@@ -87,32 +102,41 @@ int random_client_tick(void *state_, void **ctxs,
|
||||
case TOASTYFS_RESULT_VOID:
|
||||
break;
|
||||
case TOASTYFS_RESULT_PUT:
|
||||
printf(" RANDOM_CLIENT :: PUT result=%s\n", error_name(result.error));
|
||||
break;
|
||||
case TOASTYFS_RESULT_GET:
|
||||
printf(" RANDOM_CLIENT :: GET result=%s size=%d\n", error_name(result.error), result.size);
|
||||
free(result.data);
|
||||
break;
|
||||
case TOASTYFS_RESULT_DELETE:
|
||||
printf(" RANDOM_CLIENT :: DELETE result=%s\n", error_name(result.error));
|
||||
break;
|
||||
}
|
||||
|
||||
// Start a new random operation if idle (previous result was consumed)
|
||||
if (result.type != TOASTYFS_RESULT_VOID) {
|
||||
// Start a new random operation if idle (previous result was consumed,
|
||||
// or this is the first tick and no operation has been started yet)
|
||||
if (result.type != TOASTYFS_RESULT_VOID || !state->started) {
|
||||
state->started = true;
|
||||
char key[64];
|
||||
int key_len = snprintf(key, sizeof(key), "k%d", (int)(rng() % 64));
|
||||
|
||||
switch (choose_random_oper()) {
|
||||
RandomOper oper = choose_random_oper();
|
||||
switch (oper) {
|
||||
case OPER_PUT:
|
||||
{
|
||||
char data[CHUNK_SIZE];
|
||||
for (int i = 0; i < CHUNK_SIZE; i++)
|
||||
data[i] = rng() & 0xFF;
|
||||
printf(" RANDOM_CLIENT :: starting PUT key=%s size=%d\n", key, CHUNK_SIZE);
|
||||
toastyfs_async_put(state->tfs, key, key_len, data, CHUNK_SIZE);
|
||||
}
|
||||
break;
|
||||
case OPER_GET:
|
||||
printf(" RANDOM_CLIENT :: starting GET key=%s\n", key);
|
||||
toastyfs_async_get(state->tfs, key, key_len);
|
||||
break;
|
||||
case OPER_DELETE:
|
||||
printf(" RANDOM_CLIENT :: starting DELETE key=%s\n", key);
|
||||
toastyfs_async_delete(state->tfs, key, key_len);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user