I am trying to develop a distributed system using Docker containers and the Sanic framework for Python. I am starting out by creating a single 'view' or network of redundant servers that share the same data store. Any one of them should be able to be accessed at any time by the client, and they should all back each others' data storage up. However, I am running into what is (probably) a very simple problem but I don't know how to fix.
When I spin up one server, it works fine. I can perform delete operations, put operations, etc, and everything works.
The way things should work when requests are made (desired functionality)
However, once I spin up the second server (so now two servers are running at once), I get an error when trying to perform "view" operations (i.e. deleting a host address from the view or putting a host address into the view) on the second server. It doesn't matter which server I spin up first, the error is always thrown by the second server that was spun up. The first server that was spun up still responds correctly, but the second server will throw an error.
using curl to make delete request of second server, error being thrown (this is the problem pic)
I am new to all of this, including using Docker, (I really like Docker, but I think the documentation is a bit confusing, tbh, but man it just seems all around neat), so any help you guys could give would be greatly appreciated. Thanks so much in advance.
Below is the code from my "view ops" function. It is the "response.json()" calls that seem to be causing the problem (although I don't know why and I suspect the problem is deeper than that, because like I said, that function call works fine as long as it's being called from the first server to be spun up). Essentially, I'm just using a single function to handle all PUT, DELETE, and GET requests. PUT in this case adds a server address to the "view" or address list of redundant servers. GET simply returns the list of active server addresses to the client, and DELETE deletes a server address from the list of active server addresses.
@app.route('/key-value-store-view', methods=["GET", "PUT", "DELETE"])
async def index(request):
if request.method == "GET":
initString = ", "
returnString = initString.join(viewList)
return response.json({"message":"View retrieved successfully","view":returnString})
if request.method == "DELETE":
addrToBeDeletedFromView = request.json['socket-address']
print("THis is from DELETE: " + str(addrToBeDeletedFromView))
try:
viewList.remove(addrToBeDeletedFromView)
except:
return response.json({"error":"Socket address does not exist in the view","message":"Error in DELETE"}, status=404)
return response.json({"message":"Replica deleted successfully from the view"})
if request.method == "PUT":
print("PUT has been hit.")
addrToBeAppendedToView = request.json['socket-address']
if (addrToBeAppendedToView in viewList):
return response.json({"error":"Socket address already exists in the view","message":"Error in PUT"}, status=404)
elif (addrToBeAppendedToView not in viewList and addrToBeAppendedToView in viewListCopy):
viewList.append(addrToBeAppendedToView)
return response.json({"message":"Replica added successfully to the view"}, status=201)