What Happened??
Container placement and activation
Let's take a moment to dig into what happened when you made this curl
request.
- You run
curl http://hello.localhost:8008/env
maelstromd
tries to resolve the request to a component- The list of
http
event sources is loaded - Each event source's hostname is compared with the request hostname
- If a match is found the component is returned
- The list of
maelstromd
asks the internal router for a reverse proxy endpoint for the component- If a component is running somewhere in the cluster, the endpoint is returned.
- If no component is running, a placement request is made and the request is internally queued until a container for that component is started somewhere in the cluster.
- In this case no component was running so a placement request was made:
- The node attempts to acquire the
placement
role lock - If it acquires the lock it runs the placement sequence locally. Otherwise it makes a RPC call to the node that owns the lock.
- The placement node decides which node in the cluster should run the component and notifies them.
- The target node pulls the docker image and starts the container
- The target node writes updated state to the db and broadcasts its state to its cluster peers
- The original node receives the updated state and proxies the request to that node
- The node proxies the request to the local container
- The node attempts to acquire the
Note that the above steps are performed regardless of cluster size. In our case our cluster has a single node, so all operations were performed locally, but the exact same steps occur in clusters with multiple nodes.
Unsuccessful request
Try making a request with a different hostname. No event source will map to the hostname and an error will be returned:
$ curl http://bogus.localhost:8008/
No component matches the request
Congratulations, you've successfully run your first maelstrom project. Let's try updating it and adding a cron event source.