Fix DOWNLOAD_LOCATIONS message implementation

Fixed critical bugs in the DOWNLOAD_LOCATIONS message exchange between
metadata server and chunk server:

Metadata server changes:
- Fixed bug using wrong index (j instead of holders[j]) when writing
  chunk server addresses
- Added missing hash field to the message (was only read, never written)
- Added trace output for STATE_UPDATE_ERROR messages
- Pre-read all missing chunks before building response

Chunk server changes:
- Updated message parser to match metadata server's message format
- Changed from group-based format to per-chunk format
- Updated type sizes (uint32_t for counts instead of uint8_t/uint16_t)
- Correctly accumulates addresses from all holders before adding to
  pending download list

The message now follows this structure:
- num_missing (uint32_t)
- For each missing chunk:
  - num_holders (uint32_t)
  - For each holder: server addresses (num_ipv4, num_ipv6, addresses)
  - hash (SHA256)

Tested successfully with mousefs_random_test under valgrind with no
memory errors detected.
This commit is contained in:
Claude
2025-11-10 22:01:24 +00:00
parent 9a3a874514
commit e1869b4cf1
2 changed files with 95 additions and 74 deletions
+23 -4
View File
@@ -889,6 +889,23 @@ static int process_chunk_server_state_update_error(MetadataServer *state,
if (!binary_read(&reader, &num_missing, sizeof(num_missing)))
return -1;
SHA256 *missing_chunks = sys_malloc(num_missing * sizeof(SHA256));
if (missing_chunks == NULL)
return -1;
for (uint32_t i = 0; i < num_missing; i++) {
if (!binary_read(&reader, &missing_chunks[i], sizeof(SHA256))) {
sys_free(missing_chunks);
return -1;
}
}
if (state->trace) {
int tag = tcp_get_tag(&state->tcp, conn_idx);
printf("Received STATE_UPDATE_ERROR from chunk server %d: %s (missing %u chunks)\n",
tag, error_msg, num_missing);
}
ByteQueue *output = tcp_output_buffer(&state->tcp, conn_idx);
assert(output);
@@ -899,9 +916,7 @@ static int process_chunk_server_state_update_error(MetadataServer *state,
for (uint32_t i = 0; i < num_missing; i++) {
SHA256 hash;
if (!binary_read(&reader, &hash, sizeof(SHA256)))
return -1;
SHA256 hash = missing_chunks[i];
int holders[MAX_CHUNK_SERVERS];
int num_holders = all_chunk_servers_holding_chunk(state, hash, holders, MAX_CHUNK_SERVERS);
@@ -912,9 +927,13 @@ static int process_chunk_server_state_update_error(MetadataServer *state,
message_write(&writer, &tmp, sizeof(tmp));
for (int j = 0; j < num_holders; j++)
message_write_server_addr(&writer, &state->chunk_servers[j]);
message_write_server_addr(&writer, &state->chunk_servers[holders[j]]);
message_write(&writer, &hash, sizeof(hash));
}
sys_free(missing_chunks);
if (!message_writer_free(&writer))
return -1;