-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathload_balancer.h
76 lines (66 loc) · 2.42 KB
/
load_balancer.h
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
/* Copyright 2021 <Madalina-Valentina Zanficu 313CA> */
#ifndef LOAD_BALANCER_H_
#define LOAD_BALANCER_H_
#include "CircularDoublyLinkedList.h"
#include "server.h"
// implemented my load_balancer with a circular doubly linked list
struct load_balancer {
doubly_linked_list_t *hash_ring;
};
typedef struct load_balancer load_balancer;
// the elements that I stocked in the hash_ring
struct hr_element {
unsigned int hash;
int server_tag;
int server_id;
// pointer to hashtable
server_memory* pServer;
};
typedef struct hr_element hr_element;
load_balancer* init_load_balancer();
void free_load_balancer(load_balancer* main);
/**
* load_store() - Stores the key-value pair inside the system.
* @arg1: Load balancer which distributes the work.
* @arg2: Key represented as a string.
* @arg3: Value represented as a string.
* @arg4: This function will RETURN via this parameter
* the server ID which stores the object.
*
* The load balancer will use Consistent Hashing to distribute the
* load across the servers. The chosen server ID will be returned
* using the last parameter.
*/
void loader_store(load_balancer* main, char* key, char* value, int* server_id);
/**
* load_retrieve() - Gets a value associated with the key.
* @arg1: Load balancer which distributes the work.
* @arg2: Key represented as a string.
* @arg3: This function will RETURN the server ID
which stores the value via this parameter.
*
* The load balancer will search for the server which should posess the
* value associated to the key. The server will return NULL in case
* the key does NOT exist in the system.
*/
char* loader_retrieve(load_balancer* main, char* key, int* server_id);
/**
* load_add_server() - Adds a new server to the system.
* @arg1: Load balancer which distributes the work.
* @arg2: ID of the new server.
*
* The load balancer will generate 3 replica TAGs and it will
* place them inside the hash ring. The neighbor servers will
* distribute some the objects to the added server.
*/
void loader_add_server(load_balancer* main, int server_id);
/**
* load_remove_server() - Removes a specific server from the system.
* @arg1: Load balancer which distributes the work.
* @arg2: ID of the removed server.
*
* The load balancer will distribute ALL objects stored on the
* removed server and will delete ALL replicas from the hash ring.
*/
void loader_remove_server(load_balancer* main, int server_id);
#endif // LOAD_BALANCER_H_