An atomic add-and-get strategy using StreamBase Query Tables

An atomic add-and-get strategy using StreamBase Query Tables

book

Article ID: KB0076097

calendar_today

Updated On:

Products Versions
TIBCO Streaming -

Description

I want to have concurrent access to the query table but be thread safe. In Java a good way would be to use atomicLong.addAndGet(long delta).

Suppose I wanted to do several of these operations on a single row in the table.  Would the row be locked for the batch of updates, or just column by column where each individual update is atomic, but not the group as a whole?

Issue/Introduction

Query Table row-updates are atomic and thread-safe.

Resolution

Concurrent thread-safe access to a Query Table is managed by the StreamBase platform and it is guaranteed when using the StreamBase APIs, whether as an EventFlow application (.sbapp) or from the Operator API (Operator.getTableAccessor()). In general, when using the StreamBase API's you have guaranteed thread safety to all available objects. This is one of the platform benefits.

Within an EventFlow Query operator the atomic "add and get" operation is performed with a Query Operator "Update" where the update expression is old.theField+input.addend, and the output is new.theField which is the in-table result of the operation.

If you use one Query operator to update multiple fields within a row, then the individual field updates will be performed in one operation atomically. The table is locked for the duration of the execution of the Query regardless how many fields are to be updated. This is true regardless of where the Table is physically in your application in relation to the Query operator. If you use two or more Query operators sequentially in the same flow, the individual updates are no longer atomic-as-a-group and a concurrent process could read or modify the row between the execution of each Query operator.