You are on page 1of 23

CAR RENTING SYSTEM

Akash Mainali
Suman Basyal
Sulav Shakya

1
INTRODUCTION
- A system to rent, drop off and view customer’s renting details.
- Our system has three entities, the coordinator server, clients and the replication
servers.
- Our system is fault tolerant.
- Facilities:
 All renting as well as users information are replicated on two servers.
 Client can create new account.
 The clients can perform Renting, Viewing cars and Dropping off cars.
 After wakeup from ther server failure the previous operation are updated automatically.

2
SYSTEM REQUIREMENT
Hardware requirement: Software requirement:
 Processor: Intel Pentium IV or above  Operating system:
 Ram: 1GB  Servers: CentOs7
 Clients:CentOs7
 Hard Disk: 80 GB and above
 Coordinator:CentOs7

3
SYSTEM MODEL
Server 1 and Server 2 are replication server.

Coordinator is the front end server which acts as


bridge between the replication server and the
clients.

Active Replication Done.

Transparency is handled by the coordinator


server.

Consistency is handled by the Active replication


(FIFO ordering)

4
Logging
 User and cars details are replicated in both the servers.
 Log files are maintained in all of the servers.

Handling client request:


REPLICATED  The request will be forwarded to the replication server by the
coordinator server (Front end server).

SERVERS DESIGN  If request contains read function, The server fetches the required
result and sends it back to client.
 If request contains write function, the operation is mass to
coordinator which in turn will pass the request to the servers. The
servers perform the operation of renting or unending and will
pass the response to client via the coordinator

5
- Resynchronization and setup
 Step1: Each server sends heartbeat message to coordinator
every second
 Step2: Once a server that was down is up again it sends “alive”
message along with last transaction number in log file.
 Step3: The coordinator keeps polling the status of the servers
using heartbeat message and determine whether they are up or

REPLICATED down
 Step4: Coordinator detects reconnection of servers and sends

SERVERS DESIGN synchronize message to other servers


 Step5: Other servers pull the data after last operation and send
it to the coordinator.
 Step6: The coordinator receives the data and sends it to the
reconnect server.
 Step7: The reconnected server receives data and updates its log
file. After completing the update, it sends resync done message
to the coordinator.

6
struct CarEntity Register(struct CarEntity ); //helps to register

struct CarEntity Login(struct CarEntity); //helps to login

int RentCar(char *, char*,int); //helps to rent METHODS USED


bool CheckCar(char *userCar);//helps to check the car IN REPLICATION
bool CheckForRentedCar(char *); //checks for the rented cars

int GetPriceOfCar(char *); //gets the price of a car


SERVER
void unRentCar(char *, char *); //helps to unrent the cacr

7
bool CheckForRentedCarWithUser(char *, char *); //checks for the rented car

//used for unrented cars

char * FindNotUsedCar(); //finds not used car


METHODS USED
IN REPLICATION
int FindNumberOfLines(char *); //finds the number of lines in the file

//view single information

struct CarEntity viewSingleInfo(char *model); //shows the singlecacr

//view all rented cars


SERVER
struct CarEntity FindRentedCars(struct CarEntity carEntity); //finds all the rented car

8
Handling request from clients
 Every message that are received from the client are forwarded
to the server by coordinator.

COORDINATOR  The server manipulates the data received from the coordinator.
 The server does file handling task of renting, un-renting or

SERVER DESIGN viewing the cars.

Heartbeat for server failure


 Coordinator waits for the heartbeat message sent from the
servers for 1 second and if it does not receive the heartbeat, it
declares the servers as dead.

9
void *HandleClient(void *arg); //takes request from clinet

void Error(char *); //prints the error

METHOD USED
struct CarEntity SendMessageToServer(struct CarEntity );//takes
request to the server

void *Server1_HB_Monitor_Thread(void *); //monitors the heartbeat


of server IN
void *CheckServerStatus(void *arg); //check whether the server is
down or alive COORDINATOR
void *Server2_HB_Monitor_Thread(void *); //monitors the heartbeat
of secondserver

void *Resync(void *); //resync type of message

10
void *HandleClientRequest(void *); //handle request of coordinator

void *MonitorHeartBeat(void *);//monitors the heart beat

void *ReSync1(void *); //deals with resync


METHOD USED
void Error(char *); //displays the error
IN
void delay(double ); //making the delay COORDINATOR
char* getFileContents(char *); //pulls the content of file

void ResyncWriteToFile(char *, char *); //copies the file from one to


another

11
IMPLEMENTATION
Sockets
- UDP sockets for passing the messages from one system to the other.
if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
Error("socket() failed");

- Multiple sockets to handle different functionalities varying the port numbers.

12
IMPLEMENTATION
Message
- Constructed in the form of structure
- Example of message structure used for resyncing purpose:
struct ResyncInfo{
char user[800];
char car[800];
char userCar[800];
char message[25];
};

13
IMPLEMENTATION
Multithreading
- Four different threads to periodically receive the heartbeat message and detect
weather the servers are active or not.
- A thread is used for sending the resynchronize message and to update the log file
in the servers.
- Another additional thread is used to handle the operation of car renting.

14
IMPLEMENTATION
Setting up Socket Properties
- Set a timeout for the recvfrom system call to make it non-blocking after timeout

- The socket timeout property in the socket of coordinator code that monitors
heartbeat messages.

setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));

15
IMPLEMENTATION
Detecting the status of servers
- Heartbeat message time interval of 1000ms

- The server1 and Server2 are continuously sending the message called “alive” to the
coordinator

- If coordinator doesn’t receive the heartbeat message signal, the server is assumed
dead.

16
IMPLEMENTATION
Resynchronization

- Resynchronization signal is issued when the server reconnects again.


- The coordinator knows that the dead server has come alive so it sends the log
transaction of another server to the just alive server.
- The server then takes the message and makes it database consistent.

17
void Error(char *err); //deals with the error

void ViewInfoOfSingleCar(); // gives the details of single car

void ViewRentedCars(); //shows all rented cars

void ViewCars(); //shows all the cars


METHODS USED
void RentCar(); //helps to rent the car IN CLIENT
void UnRentCars();//helps to unrent the car

bool Login(); //helps in login

18
int Quit(); //quiting the application

void DisplayCar(struct CarEntity ); //displays car in console

void Register(); //helps to register

void ViewCar(); // helps to view the single car


METHODS USED
int MainLoop(); //main loop of the program
IN CLIENT
struct CarEntity RequestCoordinator(struct CarEntity entity); //request to the
coordintor

void PrintReceipt(struct CarEntity ); //prints the receipt

bool CheckForChoice(int val); //checks for invalid entries

19
DIFFICULTIES AND SOLUTIONS
Segmentation Fault Core Dumped Error
- Allocated memory size of 100 bytes
- We used to get the error after testing the program couple of times
- Increased the memory size to 800 bytes

20
DIFFICULTIES AND SOLUTIONS
Use of UDP connection
- An unreliable means of communication
- No guarantee of the delivery of the packages
- This could be solved by using TCP connection

21
DIFFICULTIES AND SOLUTIONS
Accessibility of same car by two users
- Two different users from two different clients could reserve the same car if they can
view all the cars.
- We solved it by using MUTEX locking and unlocking.

22
LETS SEE THE SYSTEM NOW!

23