Intermediate Recipe: Using the Atomic Integer ETL Step

Level: Intermediate

Problem:
You need a value that can be shared between multiple processes.

Solution:
Use the Atomic Integer ETL Step.

Discussion:

Sometimes, you will encounter situations where you need to constrain the adjustment of values. The canonical example is that of a bank transaction management system, where the system needs to accurately keep track of the amount of money in the account in between transactions in different accounts.

Say, for instance, you have a database that is like this:

{"_id": "InvoiceNo", "Type": "InvoiceNo", "Value": 45 }
{"_id": "QuotationNo", "Type":"QuotationNo","Value": 100}

The canonical way to do this in programming is by making use of values called atomic values. The term “atomic” comes from the old - and incorrect - assumption that atoms were the smallest molecular structure and indivisible.

Thus, an atomic operation in IT is an operation that is conducted end-to-end without the system permitting interruptions.

In Ambience, this is handled by the Atomic Integer ETL Step as described below:

  • This step reads and increments an integer value in MongoDB in a thread-safe way so that multiple concurrent calls will each receive a different incrementing value.
  • More information can be found in the ETL Dictionary.

These are the steps you should follow to use the ETL step on the database descried above:-

  1. After importing the data, head over to the ETL module.
    More information on how to Import data can be found here: Imports

  2. Create a new ETL Chainset.
    For example,

  3. Add a new Blank Chain.
    For example,

  4. Add the step, “MongoDB Atomic Integer” in the new chain & fill in the fields:
    For example,

    *expand the icon on the top right corner for more details on this step.

  5. For visualization purposes, do add in the following 2 steps, “MongoDB Definition” & “MongoDB Reader”
    For example,

  6. Run Steps.


Output:
// Initial Data

// After running the steps


[Value for InvoiceNo is incremented by 1]

// To increment “QuotationNo”, do add in & configure another “MongoDB Atomic Integer” step.