ACID Transactions

ACID Transactions #

Proxima supports distributed ACID transactions with serializable isolation level based on the Proxima Transactions design document.

Transaction Modes #

Each attribute in your model can declare a transactional mode corresponding to TransactionMode:

ModeScope
none (default)No transactional guarantees.
attributeColliding writes within the same attribute are rejected.
keyTransactions scoped to a single entity key of a single entity.
entityTransactions spanning multiple keys of a single entity type.
allGlobal ACID consistency across arbitrary keys and entities.

Current Server Support: TransactionManagerServer currently supports all and none (TransactionMode.ALL and TransactionMode.NONE). Declaring other modes will throw UnsupportedOperationException when starting TransactionManagerServer.

Configuring Transaction Support #

Enabling transactions requires:

  1. Marking transactional attributes with transactional: all and associating them with transaction manager family/families via manager.
  2. Defining commit-log attribute families for the built-in system entity _transaction (request.*, response.*, state, and commit).
  3. Ensuring a transaction serializer scheme is on the classpath (proxima-scheme-proto is recommended; java: from proxima-core also provides a fallback, or you can configure transactions.scheme-provider explicitly).
  4. If persisting transactional attributes to HBase or Bigtable, append ?v=2 to the storage URI so the storage preserves StreamElement.getSequentialId().

Minimal Single-Topic Manager Configuration #

entities {
  gateway {
    attributes {
      status {
        scheme: bytes
        transactional: all
        manager: gateway-transaction-commit-log
      }
      intField {
        scheme: integer
        transactional: all
        manager: gateway-transaction-commit-log
      }
      "device.*" {
        scheme: bytes
        transactional: all
        manager: gateway-transaction-commit-log
      }
    }
  }
}

attributeFamilies {
  gateway-transaction-commit-log {
    entity: _transaction
    attributes: [ "request.*", "response.*", "state" ]
    storage: "kafka://kafka-broker:9092/gateway-transactions"
    type: primary
    access: [ commit-log, state-commit-log, cached-view ]
  }

  transactions-commit {
    entity: _transaction
    attributes: [ "commit" ]
    storage: "kafka://kafka-broker:9092/transactions-commit"
    type: primary
    access: commit-log
  }
}

Important: The attribute family holding _transaction.state must include [ commit-log, state-commit-log, cached-view ] access (backed by a compacted Kafka topic in production), and there must be a primary commit-log family for _transaction.commit.

Scalable Split-Topic Manager Configuration #

For production workloads, split request.*, response.*, and state into dedicated topics so the compacted state topic stays small while high-volume request.* and response.* topics use short retention:

entities {
  gateway {
    attributes {
      "user.*" {
        scheme: bytes
        transactional: all
        manager: [
          all-transaction-request,
          all-transaction-response,
          all-transaction-state
        ]
      }
    }
  }
}

attributeFamilies {
  all-transaction-request {
    entity: _transaction
    attributes: [ "request.*" ]
    storage: "kafka://kafka-broker:9092/tx-request"
  }

  all-transaction-response {
    entity: _transaction
    attributes: [ "response.*" ]
    storage: "kafka://kafka-broker:9092/tx-response"
  }

  all-transaction-state {
    entity: _transaction
    attributes: [ "state" ]
    storage: "kafka://kafka-broker:9092/tx-state"
    # access defaults automatically to [ commit-log, state-commit-log, cached-view ]
  }

  transactions-commit {
    entity: _transaction
    attributes: [ "commit" ]
    storage: "kafka://kafka-broker:9092/tx-commit"
    type: primary
    access: commit-log
  }
}

Using the Transaction API #

Transactions are supported through DirectDataOperator (and transitively via ProximaIO.write and gRPC RetrieveService/IngestService).

The API centers on TransactionalOnlineAttributeWriter.Transaction. Because Proxima uses optimistic concurrency control with serializable conflict detection, execute transactional logic inside a retry loop that restarts on TransactionRejectedException:

Repository repo =
    Repository.ofTest(
        ConfigFactory.parseResources("test-transactions.conf").resolve());

DirectDataOperator direct = repo.getOrCreateOperator(DirectDataOperator.class);

EntityDescriptor gateway = repo.getEntity("gateway");
Regular<Integer> intField = Regular.of(gateway, gateway.getAttribute("intField"));
Wildcard<?> device = Wildcard.of(gateway, gateway.getAttribute("device.*"));

OnlineAttributeWriter writer = direct.getWriter(intField).orElseThrow();
RandomAccessReader reader = direct.getRandomAccess(device).orElseThrow();

Preconditions.checkState(writer.isTransactional());

String gatewayId = "gw1";

while (true) {
  try (Transaction transaction = writer.transactional().begin()) {

    // 1. Read inputs participating in the transaction
    List<KeyValue<?>> kvs = new ArrayList<>();
    reader.scanWildcard(gatewayId, device, kvs::add);

    // 2. Register all read inputs with the transaction manager
    transaction.update(
        KeyAttributes.ofWildcardQueryElements(gateway, gatewayId, device, kvs));

    // 3. Prepare transactional outputs (sequentialId is assigned by the coordinator)
    StreamElement upsert = intField.upsert(
        gatewayId, 1L, kvs.size());

    // 4. Commit and await confirmation
    BlockingQueue<Pair<Boolean, Throwable>> result = new ArrayBlockingQueue<>(1);
    transaction.commitWrite(
        Collections.singletonList(upsert),
        (succ, exc) -> result.offer(Pair.of(succ, exc)));

    // Synchronous wait shown for simplicity; prefer async callbacks in production
    Pair<Boolean, Throwable> taken = ExceptionUtils.uncheckedFactory(result::take);
    if (!taken.getFirst()) {
      if (taken.getSecond() instanceof TransactionRejectedException) {
        // Optimistic conflict detected: re-read state and retry
        continue;
      }
      throw new IllegalStateException("Transaction failed", taken.getSecond());
    }

    // Committed successfully
    break;
  }
}

For transactions spanning multiple attributes that do not share a single primary writer, obtain a global transactional writer via direct.getGlobalTransactionWriter(). When reading transactional attributes from a CachedView, direct.getCachedView(...) automatically wraps the view in a TransactionalCachedView.

Transaction Workflow & Architecture #

Transaction coordination relies on four commit logs:

  • request.* — client transaction lifecycle messages (OPEN, UPDATE, COMMIT, ROLLBACK)
  • response.* — coordinator acknowledgements and conflict rejections routed back to clients
  • state — compacted log of active/committed transaction states and latest sequential IDs per key-attribute
  • commit — atomic commit log carrying accepted outputs, state transitions, and client responses

Proxima guarantees serializable isolation by assigning each committed transaction a monotonically increasing sequentialId, which is stamped onto every output StreamElement written by that transaction. Whenever a client calls transaction.update(...) with the KeyAttributes (and observed sequential IDs) it read and subsequently calls transaction.commitWrite(...), the transaction manager validates that none of the input keys were modified by a newer committed transaction:

  1. On first update(...) (or commitWrite(...)), TransactionalOnlineAttributeWriter sends a Request to _transaction.request.*.
  2. The transaction manager checks conflicts against its in-memory/cached state and emits a Commit to _transaction.commit.
  3. The Replication controller consumes _transaction.commit via the built-in TransactionCommitTransformation and atomically fans out:
    • the accepted data writes to target entity primary commit logs,
    • updated transaction state records to _transaction.state, and
    • Response messages to _transaction.response.* notifying the waiting client.
  4. If a conflict occurred, the client’s callback receives TransactionRejectedException so the application can safely retry.

Runtime Components #

Running ACID transactions requires two runtime services:

  1. Transaction Manager Server (cz.o2.proxima:proxima-direct-transaction-manager, main class TransactionManagerServer):
    • Consumes _transaction.request.* and writes decisions to _transaction.commit.
    • Runs in active/standby mode (multiple instances can be deployed for automatic failover, with one active leader processing requests at a time).
    java -cp my-proxima-tx-manager.jar \
        cz.o2.proxima.direct.transaction.manager.TransactionManagerServer
    
  2. Replication Controller (cz.o2.proxima:proxima-ingest-server-grpc, main class ReplicationController):
    • Runs TransactionCommitTransformation to apply committed transactions to target primary families, _transaction.state, and _transaction.response.*, and replicates updates onward to all replica storages.