Skip to content

oconnes9/Distributed_System

Repository files navigation

Distributed_System

There needs to be 6 folders, ClientStorage, ClientStorage2, ClientStorage3, Server1, Server2 and Server3. The ClientStorage folders must contain a folder named Cache in each. The Server folders must contain some sample .txt files which must then be written into the directory in the ProxyServ() function. They need to be saved to the appropriate list. The paths to the cache etc in the Server, Proxy and Directory files must be changed to fit wherever they are saved. To run the code, the three servers and the directory service must be run first, using " python Directory.py " etc in the command window. The three clients can then be run. The clients apps will ask the user what file they want access to. The file name (not including .txt) must be entered, e.g. ascii. The user then gets asked if they want to edit the file. They must then type yes or no and hit enter.

The code and setup is quite messy but all of the features work well, as explained below.

Firstly, the purpose of my application is to allows the user to read or write to text files saved on a remote server. I attempted 5 of the tasks for the assignment: Distributed Transparent File Access, Directory Service, Replication, Caching and Lock Service. I have used 3 servers and 3 clients to demonstrate. I used sockets for communication and the localhost to test.

Firstly, the application code itself is very short. All of the file access is done in the libraries (named Proxy.py, Proxy2.py and Proxy3.py). All of these libraries are the exact same aparts from the paths to their Caches and "personal storage". This would not be necessary apart from the fact that I was testing all Clients on the same computer so they needed separate paths to their separate storage folders.

To access a file, it is first checked if the file is stored on the clients own machine (folder in this case). If not, it was then checked if it was stored in the cache. If not, then the client connects to the directory. This sends a 'FindFile' message with the name of the desired file. The directory service will find the 'primary copy' of the file by searching through the lists of files in the directory. There is a list for each server. The directory has a file class which saves the name of a file, the lock status and whether it is the primary copy or not. When the primary copy is found, the relevant server's information (host and port) is sent back to the application library. This information is passed into a serverConnect() function, along with the fileName. In this function, the application library connects to the relevant server and sends a request for the file. The server sends the file to the application to read. This file is saved to the cache by joining the cache directy and adding the contents to a new file of the same name there.

The user then has the option to edit the file. If they choose to edit the file, the fileName is passed into a locking function. This function tries to lock the primary copy of the file so that nobody else can access while they write.

This lock function sends an lock message to the directory, which will change the lock status of the file to locked if it was unlocked or will return the message "BUSY" if not. The lock function will keep polling until the file is unlocked by another user. When it is locked, the user can type out the new file contents to update them. A function which returns the details of all servers that contain that file is called. This function requests the information off the directory and subsequently connects to all of the servers, updating the file on each. This is done in the updateVersion() function. The file is then unlocked, by passing the fileName into an unlock() function which tells the Directory to change the lock status. The version number is updated and the file is saved to the cache list (it is already stored in the cache), using the addToCache() function.

This function uses a Least Recently Used system to contorl the number of files stored in it. If the list is full, the last item is evicted and the new one added. Every time a file in the cache is accessed, it is moved to the front of the list, making the front of the list the most recently used and the end the least recently used.

If the file requested is stored in the cache already, the application finds it's original location from the directory, connects to the appropriate server and checks if it has the most up to date version by comparing version numbers. If it does, then it reads from the stored copy in the onCache() function. In this function, the user has the option to edit the text file. Again, the primary copy needs to be locked if it is being edited and unlocked afterwards. All servers containing the file must then be updated.

If the cache does not contain the most up to date version of a file, the updateCacheVersion() function is called. This connects to the relevant server and gets sent the most up to date version, with the version number being updated also.

My code communicates with and send information between servers and clients. It uses a directory to find the locations of files. It locks files if they are being edited, so that nobody else can edit at the same time. It caches files for quicker access and evicts LRU files from the cache. It updates every version of the edited file saved on the remote servers and updates the file on other caches before it is read by the users.

I know it's a little messy so if you've any questions let me know!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages