Update/delete operations using optimistic concurrency - Intergraph Smart API Manager - 2020 (4.0) - Help

Intergraph Smart API Manager Help

Language
English
Product
Intergraph Smart API Manager
Search by Category
Help
Smart API Manager Version
4.0

Optimistic concurrency is a method for managing data modification when multiple clients can compete for resources. The goal is to ensure an update or delete occurs only when you have a current, up-to-date instance of the data.

To support optimistic concurrency checks, a client must pass an ETag value on an HTTP PUT, PATCH or DELETE request.

Smart APIs use the ConcurrencyToken property to manage entity instance state. Its value is updated every time an entity instance changes.

The following list outlines a typical update work-flow (HTTP PATCH request) using ConcurrencyToken.

  1. Two clients (Client A and Client B) get the same Pipe instance at the same time. The response for the Pipe instance includes:

    "ConcurrencyToken": "5247927659359489936"

  2. Client B makes a call to update the Pipe. It issues an HTTP PATCH request with the If-Match request header value set to:

    "5247927659359489936"

  3. The Smart API compares the value received in the request to the current value for the Pipe instance. The values match, so,

    • the instance is updated, and

    • its ConcurrencyToken value is updated to "5247927672931797099" (the Smart API updates the value every time an entity instance changes).

  4. Now, Client A makes a call to update the Pipe. It is not aware of the update Client B has made, so it issues an HTTP PATCH request with the If-Match request header value set to:

    "5247927659359489936"

  5. The Smart API compares the ConcurrencyToken value received ("5247927659359489936") in the request and compares it against the updated entity instance ("5247927672931797099").

    Because the values do not match, the update is refused, and an HTTP 412 (Precondition Failed) is returned.

  • For PUT or PATCH requests, instead of passing the If-Match header with the ConcurrencyToken value, the request body can contain the ConcurrencyToken property and value.

    The same check will be made by the Smart API.

  • To skip concurrency checks for an update or delete operation, set the If-Match header value to "*".