Unified the function signatures across all process types (metadata server, chunk server, and simulation client) to accept an int *timeout parameter. This provides consistency in the simulation framework and allows all process types to control their wakeup times. **Changes:** **Headers (metadata_server.h, chunk_server.h):** - Updated metadata_server_init() to accept int *timeout parameter - Updated metadata_server_step() to accept int *timeout parameter - Updated chunk_server_init() to accept int *timeout parameter - Updated chunk_server_step() to accept int *timeout parameter **Implementations (metadata_server.c, chunk_server.c):** - Modified init functions to set *timeout = -1 (no timeout needed) - Modified step functions to set *timeout = -1 (no timeout needed) - Both server types currently don't require periodic wakeups, but the parameter allows for future timeout-based behavior **System Integration (system.c):** - Updated spawn_simulated_process() to declare timeout variable once and pass it to all process init functions uniformly - Updated update_simulation() to declare timeout variable once and pass it to all process step functions uniformly - Simplified control flow by removing special case for client timeout handling - now all process types use the same timeout logic - Consolidated timeout-to-wakeup_time conversion after switch statements **Benefits:** - Consistent API across all process types - Cleaner code with reduced duplication - Future-proof for server timeout requirements - All processes now managed uniformly by simulation framework The simulation continues to run correctly with all process types handling timeout parameter appropriately.
56 lines
1.2 KiB
C
56 lines
1.2 KiB
C
#ifndef METADATA_SERVER_INCLUDED
|
|
#define METADATA_SERVER_INCLUDED
|
|
|
|
#include "tcp.h"
|
|
#include "file_tree.h"
|
|
#include "config.h"
|
|
|
|
#define CONNECTION_TAG_CLIENT -1
|
|
#define CONNECTION_TAG_UNKNOWN -2
|
|
|
|
typedef struct {
|
|
int count;
|
|
int capacity;
|
|
SHA256 *items;
|
|
} HashList;
|
|
|
|
typedef struct {
|
|
|
|
bool auth;
|
|
|
|
int num_addrs;
|
|
Address addrs[MAX_SERVER_ADDRS];
|
|
|
|
// Chunks held by the chunk server during
|
|
// the last update
|
|
HashList old_list;
|
|
|
|
// Chunks added to the chunk server since
|
|
// the last update
|
|
HashList add_list;
|
|
|
|
// Chunks removed from the chunk server
|
|
// since the last update
|
|
HashList rem_list;
|
|
|
|
} ChunkServerPeer;
|
|
|
|
typedef struct {
|
|
|
|
TCP tcp;
|
|
|
|
FileTree file_tree;
|
|
|
|
int replication_factor;
|
|
|
|
int num_chunk_servers;
|
|
ChunkServerPeer chunk_servers[MAX_CHUNK_SERVERS];
|
|
|
|
} MetadataServer;
|
|
|
|
int metadata_server_init(MetadataServer *state, int argc, char **argv, void **contexts, struct pollfd *polled, int *timeout);
|
|
int metadata_server_free(MetadataServer *state);
|
|
int metadata_server_step(MetadataServer *state, void **contexts, struct pollfd *polled, int num_polled, int *timeout);
|
|
|
|
#endif // METADATA_SERVER_INCLUDED
|