# On The Distributed Resource Allocation Protocol

#### Distributed Resource Allocation Protocol Description

The objective of the protocol is to enable safe distributed atomic reservation of a collection of resources. For instance any two distinct agents and may require any resource collections and , where .

The protocol must guarantee that each agent gets all or nothing – partial request satisfaction is not permitted – and ensure that every agent request will be eventually satisfied as long as certain degenerated situations are avoided. A resource itself has an attributed memory, where requests can be stored together with a read pointer , and a promise pointer – the largest {promised} index in the request pool.

In this stage an agent attempts to negotiate a distributed lane. The negotation process continues until a lane is negotiated.

An agent which intends to lock a collection of resources generates a request to request pools associated with resources . Such requests are sent and received in no particular order and contain only agent name . We define such message as and write to state it is addressed to resource .

Once a request pool receives request it replies with a promised pointer index and then increments .

After sending all messages an agent awaits for all replies to arrive which carry values . Depending on the collection of reply values following actions should be taken:

If all reply values on reception are equal then should write at index to request pools .

If all values on reception are not equal then the agent must renegotiate a new index. This time an agent sends new (special) requests to resources. We define such message as \textbf{}.

Once a request pool receives a special request it replies with the following message where the maximum value of the current value or received index.

This stage begins when an agent completes negotiating its distributed lane. The original version of this stage was trivial and only consisted of , and steps and basically was just a single message sent by resource to an agent to inform the resource can be consumed now. But, due to possible write message arrival delays another kind of deadlock could have been present in our system.

A pre-ready message is sent by a resource to inform a next in line agent that it is available for consumption and we define such message .

An agent waits for all pre-ready messages to arrive and once it receives them it sends a lock message to resources as follows .

A request pool which receives a lock message will respond with a message where . The message is sent if resource has not been locked by other agent yet. If confirm message is sent, the request pool suspends sending pre-ready messages until an unlock or release message is received. If resource was locked beforehand – a message is sent.

An agent waits for all respond messages to arrive and depending on these messages following actions will be taken.

If one of the messages is a deny message, an agent will send an release messages to all resources which replied with confirm message. We define such message as follows
.

If all messages were confirm messages, an agent can proceed with resource consumption.

An agent will eventually release a resource by sending a message to all consumed resources, as follows . Once resource receives a release message, it will remove the request from its request pool and will update the read pointer to the the next minimum value.




#### Formal Protocol Model in Event-B

We apply the Event-B formalism to develop a high-fidelity functional model and prove the protocol functional correctness requirements.

Event-B Model: Refinement Plan

Abstract Model: Context

Abstract Model: Machine

First Refinement: Machine

The refinement step expands on the previous refinement by introducing resources into the model. Instead of simply consuming an objective an agent captures resources until an objective is fulfilled. Captured resources are stored in newly created variable whereas objective an agent will try to complete in the function .

In contrary to capturing a single objective an agent might need to consume multiple resources in order to fulfil its objective. For the iterative process we previously introduced a two event pattern which we instantiate in this refinement step for capturing and releasing events. The loop body event takes any agent with previously initialised objective and assign a new resource to the variable . The agent must be at state and the resources must be within agent’s objective and not yet be captured by any agent.

The loop completion event would be triggered as soon as the objective has been fulfilled (guard ) and program counter would be updated to new state – . Similarly in this refinement we transform event according to the pattern presented.

Message Modelling: Contexts and Machine Variables

The second group of contexts are used to define various message types and a separate context is created for an individual message type. In fact message contexts can be generalised in the following pattern and instantiated to the specific message type in the Event-B model.

To begin with we create a generic message carrier set which is used as an extractor in constant functions. Three constant functions are defined for messages: message source, message destination and optionally a message value. Depending on the message type the source of the message can be both agents and resources thus in our general form example we simplify to a general source function range. Likewise for the message destination constant functions form we give a general destination the message. All constant message functions are surjective functions meaning they are total in domain and range and therefore must be interval for messages which carry a natural number. Lastly in addition to constant function axioms we introduce another axiom which states that there always exists a suitable message between any agent and resource.

To introduce a new message type in the machine we extend that machine with a specific context and introduce a three letter message channel variable. As messages are added and removed from the channel typically local variable () must be introduced when an agent needs to track what messages have been sent. The channel variables are modified by message sending events and we identified two message sending event patterns.

Communication Modelling Example: message (Ref. )