0
votes

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)
What is viewList and where is it coming from? My initial impression is that this is an in memory store, and that likely you need some method of sharing data across a distributed system. aka a database - The Brewmaster
yes I'm sorry I should have included that....so viewList is just a list (in Python dictionary form originally, and then transferred into Python list form) of all the server addresses in the view ... and thank you thank you for looking at my question - OldNewb
If that's the case, then what you really need is a third service that both of your containers can connect to. There are so many options here, it would be hard to recommend. If you post the question on the Sanic forums, I'd be happy to have a more in depth conversation (that's not really suited for SO) to help you find a solution. community.sanicframework.org - The Brewmaster
And also, yes, the database operations I haven't coded yet because I'm having this basic communication problem between Docker containers/servers ... If I could solve this problem, I'd be ready to move to coding the actual database operations... - OldNewb
Okay I'm trying to make an account on the sanicframework community site right now...it seems to be taking a while... - OldNewb