Complete client library refactoring: fill all placeholders and implement missing functions

- Add REPLICATION_FACTOR and CHUNK_SIZE constants to config.h
- Add proper error codes (REJECTED, FULL, NOT_FOUND, TRANSFER_FAILED, etc.) to toastyfs.h
- Implement compute_chunk_hash() for deterministic chunk hashing
- Implement replay_request() to resend operations after leader redirect
- Implement send_message_to_server_ex() for sending messages with trailing data
- Implement choose_store_locations_for_chunk() to pick REPLICATION_FACTOR servers
- Fix begin_transfers() to handle both StoreChunk (PUT) and FetchChunk (GET)
- Complete toastyfs_async_put(): chunk splitting, hashing, data copy, metadata setup
- Complete toastyfs_async_get()/delete(): key setup, step/time initialization
- Fix get_result(): use actual transfer sizes instead of fixed chunk_size, free transfer data
- Replace all xxx placeholders and TOASTYFS_ERROR_XXX with proper values
- Add chunk_sizes[] tracking and put_data lifetime management
- Implement random_client.c: rng(), choose_random_oper(), proper API call arguments

https://claude.ai/code/session_01TkNavR4qyZcTuXMPmrtWUJ
This commit is contained in:
Claude
2026-02-21 13:03:13 +00:00
parent f5f684952c
commit 723fc7cf76
4 changed files with 298 additions and 68 deletions
+48 -21
View File
@@ -6,12 +6,35 @@
#include <toastyfs.h>
#include <stdint.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "server.h"
#include "random_client.h"
static uint64_t next_random_client_id = 100;
static uint64_t rng(void)
{
#if defined(MAIN_SIMULATION) || defined(MAIN_TEST)
return quakey_random();
#else
return (uint64_t)rand();
#endif
}
typedef enum {
OPER_PUT,
OPER_GET,
OPER_DELETE,
} RandomOper;
static RandomOper choose_random_oper(void)
{
return rng() % 3;
}
int random_client_init(void *state_, int argc, char **argv,
void **ctxs, struct pollfd *pdata, int pcap, int *pnum,
int *timeout)
@@ -64,34 +87,38 @@ int random_client_tick(void *state_, void **ctxs,
case TOASTYFS_RESULT_VOID:
break;
case TOASTYFS_RESULT_PUT:
{
// TODO
}
break;
case TOASTYFS_RESULT_GET:
{
// TODO
}
free(result.data);
break;
case TOASTYFS_RESULT_DELETE:
{
// TODO
break;
}
// Start a new random operation if idle (previous result was consumed)
if (result.type != TOASTYFS_RESULT_VOID) {
char key[64];
int key_len = snprintf(key, sizeof(key), "k%d", (int)(rng() % 64));
switch (choose_random_oper()) {
case OPER_PUT:
{
char data[CHUNK_SIZE];
for (int i = 0; i < CHUNK_SIZE; i++)
data[i] = rng() & 0xFF;
toastyfs_async_put(state->tfs, key, key_len, data, CHUNK_SIZE);
}
break;
case OPER_GET:
toastyfs_async_get(state->tfs, key, key_len);
break;
case OPER_DELETE:
toastyfs_async_delete(state->tfs, key, key_len);
break;
}
break;
}
switch (choose_random_oper()) {
case OPER_GET:
toastyfs_async_get(state->tfs, xxx);
break;
case OPER_PUT:
toastyfs_async_put(state->tfs, xxx);
break;
case OPER_DELETE:
toastyfs_async_delete(state->tfs, xxx);
break;
}
(void) timeout;
*pnum = toastyfs_register_events(state->tfs, ctxs, pdata, pcap);
return 0;
}