-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_balancer.h
More file actions
77 lines (66 loc) · 2.57 KB
/
load_balancer.h
File metadata and controls
77 lines (66 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* Copyright (c) 2024, Manolache Maria-Catalina 313CA
*/
#ifndef LOAD_BALANCER_H
#define LOAD_BALANCER_H
#include "server.h"
#define MAX_SERVERS 99999
typedef struct load_balancer {
unsigned int (*hash_function_servers)(void *);
unsigned int (*hash_function_docs)(void *);
// vectorul de servere si dimensiunea acestuia
server **servers;
int nr_servers;
bool enable_vnodes;
// vectorul de etichete pentru servere, pt hash ring
int *s_tags;
// vectorul care face legatura intre o eticheta si indexul ei in
// vectorul de servere
int *tag_to_index;
} load_balancer;
load_balancer *init_load_balancer(bool enable_vnodes);
void free_load_balancer(load_balancer **main);
/**
* loader_add_server() - Adds a new server to the system.
*
* @param main: Load balancer which distributes the work.
* @param server_id: ID of the new server.
* @param cache_size: Capacity of the new server's cache.
*
* @brief The load balancer will generate 1 or 3 replica labels and will place
* them inside the hash ring. The neighbor servers will distribute SOME of the
* documents to the added server. Before distributing the documents, these
* servers should execute all the tasks in their queues.
*/
void loader_add_server(load_balancer *main, int server_id, int cache_size);
/**
* loader_remove_server() Removes a server from the system.
*
* @param main: Load balancer which distributes the work.
* @param server_id: ID of the server to be removed.
*
* @brief The load balancer will remove the server (and its replicas) from
* the hash ring and will distribute ALL documents stored on the removed
* server to the "neighboring" servers.
*
* Additionally, all the tasks stored in the removed server's queue
* should be executed before moving the documents.
*/
void loader_remove_server(load_balancer *main, int server_id);
/**
* loader_forward_request() - Forwards a request to the appropriate server.
*
* @param main: Load balancer which distributes the work.
* @param req: Request to be forwarded (relevant fields from the request are
* dynamically allocated, but the caller have to free them).
*
* @return response* - Contains the response received from the server
*
* @brief The load balancer will find the server which should handle the
* request and will send the request to that server. The request will contain
* the document name and/or content, which are dynamically allocated in main
* and should be freed either here, either in server_handle_request, after
* using them.
*/
response *loader_forward_request(load_balancer *main, request *req);
#endif /* LOAD_BALANCER_H */