Repository navigation
DBOS Transact for Java 1.4.0
// Gradle
implementation("dev.dbos:transact:1.4.0")<!-- Maven -->
<dependency>
<groupId>dev.dbos</groupId>
<artifactId>transact</artifactId>
<version>1.4.0</version>
</dependency>1.4 adds suspend mode, a Transact Enterprise feature that lets a workflow waiting in recv or sleep leave memory until its wait ends. Workflow management now keeps a workflow's queue, partition key and priority through cancel, resume, rewind and fork. Queue concurrency limits are enforced exactly across executors, and a workflow status this version doesn't know reads as UNKNOWN instead of failing. The system database migrates to version 130.
Important
With withMigrate(false), apply migrations 126–130 with dbosctl v0.14.0 or later before upgrading. A 1.4 DBOSClient needs them too. See System database migrations.
Important
Conductor users must upgrade dev.dbos:transact-enterprise to 1.4.0 with dev.dbos:transact. A 1.3 enterprise artifact is refused at launch.
Warning
Cancel, resume, rewind and fork now keep a workflow's queue. A resumed or rewound workflow goes back to its own queue, not the internal queue. See Workflow management keeps the queue.
Warning
Turn on suspend mode only once every executor reading the system database knows the SUSPENDED status: Java 1.4, Python 3.5.0 or TypeScript 5.5 or later. See Suspend mode.
New features
Suspend mode
DBOS.recv(topic, timeout, true) and DBOS.sleep(duration, true) suspend a workflow instead of holding a thread and an executor slot while it waits (#670, dbos-enterprise-java#24). Its execution exits and its status becomes SUSPENDED. When a message arrives on its topic, the recv times out, or the sleep ends, DBOS puts it back on its queue, or the internal queue if it had none, and it resumes from its last completed step.
var config = DBOSConfig.defaults("my-app")
.withDatabaseUrl(System.getenv("DBOS_SYSTEM_JDBC_URL"))
.withConductorKey(System.getenv("DBOS_CONDUCTOR_KEY"))
.withSuspendMode(true);
@Workflow
public String approval(String request) {
// Suspend for up to a week while waiting for a decision.
return dbos.<String>recv("approval", Duration.ofDays(7), true).orElse("timed out");
}- Suspend mode needs
dev.dbos:transact-enterprise, and a DBOS key for itssuspendWorkflowsentitlement: your Conductor key, or a Transact Enterprise key in development. Without a key, launch throwsIllegalStateException, unless the application runs on DBOS Cloud or a self-hosted Conductor grants the entitlement without one. With suspend mode off,recvorsleepwithsuspendtrue throwsIllegalStateException, as it does outside a workflow or in a step. - If a message is already waiting,
recvreturns it without suspending. A sleep with a second or less left stays in its thread. - Every send wakes a suspended receiver waiting on its topic: a send from
DBOS, fromDBOSClient, from a process without suspend mode, or from thesend_messageSQL function. A send from Java 1.3 doesn't, so arecvit should wake waits until its timeout. - Suspending throws
DBOSWorkflowSuspendedException, which extendsErrorso workflow code catchingExceptiondoesn't swallow it. Code that catchesThrowableorErrormust rethrow it. - A suspended workflow doesn't count against its queue's concurrency. When it wakes, it waits for capacity like any enqueued workflow. Workflow timeouts and cancellation still apply while it is suspended.
- Turn suspend mode on in every process that may run a suspending workflow. A process without it throws
IllegalStateExceptionwhen it runs, recovers or resumes a workflow that reaches a suspendingrecvorsleep, even one whose wait was already recorded. Processes with suspend mode on wake their own application's suspended workflows, in a pass once a second; a send, from any process, only marks a workflow due. - The Spring Boot starter has no property for it yet; set it with a
DBOSConfigCustomizerbean. - A suspended workflow's wake time is set on the database's clock, so clock skew between an executor and the database doesn't move it. See Durable waits use the database's clock.
Transact Enterprise key
Before DBOS loads a Transact Enterprise feature, it checks with DBOS Conductor that your organization is entitled to it (#664). Suspend mode is the first such feature in Java. The check uses DBOSConfig.withTransactEnterpriseKey(...) (dbos.transact-enterprise-key in Spring Boot), or your Conductor key if that isn't set. With a Conductor key you don't need anything else. A refusal throws IllegalStateException at launch. DBOS's hosted Conductor fails open when it can't be reached: DBOS logs a warning and launches. A self-hosted Conductor fails closed.
Resuming into a partition
resumeWorkflow(workflowId, queueName, queuePartitionKey) and resumeWorkflows(workflowIds, queueName, queuePartitionKey), on DBOS and DBOSClient, resume onto a partition of a partitioned queue (#669). Naming only a key moves the workflow to that partition of its own queue. Conductor's resume passes a partition key through (dbos-enterprise-java#23).
Conductor
These need dev.dbos:transact-enterprise 1.4.0.
- Bulk rewind (#675, dbos-enterprise-java#26). Conductor can rewind several workflows at once, each from its own start step, all or nothing.
- Export and import keep more of a workflow (dbos-enterprise-java#29): whether it counts against its queue's rate limit, the topic a suspended
recvwaits on, and the messages sent to it, received or not. An export is now read from one database snapshot, so it can't mix states a running workflow passed through. Exports from 1.3 still import. - A status this version doesn't know passes through Conductor's listings, export and import as stored (dbos-enterprise-java#27, dbos-enterprise-java#32). An export from a version that knows the status imports with it. Import refuses a workflow whose status it can't name, rather than store
UNKNOWN.
Upgrading from 1.3
System database migrations
At launch, 1.4 migrates the system database from 125 to 130 (#666). These are the migrations Python 3.5.0 and TypeScript 5.5 added for suspend mode: a suspend_key column, two indexes built without blocking writes on Postgres, and a send_message SQL function that wakes a suspended receiver. None removes anything 1.3 relies on, so 1.3 executors keep working on a migrated database.
With withMigrate(false) (dbos.datasource.migrate=false in Spring Boot), run dbosctl sysdb migrate from dbosctl v0.14.0 or later first; otherwise launch throws IllegalStateException. A 1.4 DBOSClient never migrates and also requires version 130.
Migration 130 recreates send_message, since Java created it with its fourth parameter named idempotency_key and every other SDK names it message_id:
- Cross 130 with Java 1.4 or dbosctl v0.14.0 or later. Only Java and dbosctl drop and recreate
send_message: Python's migration 130 (3.5 and later) and TypeScript's (5.5 and later) replace it in place, so they fail on a Java-created database with "cannot change name of input parameter". If yours stopped at 129 that way, runDROP FUNCTION "<schema>".send_message(text, json, text, text);and relaunch. - The function is then owned by the role that ran the migration. Re-grant any
EXECUTEyou restricted to specific roles. - SQL calling it with the named argument
idempotency_key => ...must usemessage_id. Positional calls are unaffected. - An object that depends on
send_message, such as aBEGIN ATOMICSQL function, blocks the migration until it is dropped.
Workflow management keeps the queue
Workflow management now keeps a workflow's queue, partition key and priority (#669), as Python 3.6 does:
- Cancel, dead-lettering and timeouts no longer clear the queue. A workflow cancelled while waiting behind a queue's limits keeps its place on that queue.
- Resume and rewind put the workflow back on its own queue and partition, falling back to the internal queue only if it had none. Before, they always used the internal queue. To keep the old behavior, resume or rewind onto a queue of your own with no flow control.
- Fork runs the new workflow on the original's queue, partition key and priority, unless
ForkOptionsnames others. - On
DBOS, resume, fork and rewind check only what you name: a named queue must exist, and a partition key needs a partitioned queue. Resume didn't validate before.DBOSClientstill doesn't validate.
Naming a partitioned queue without a key, for a workflow that has no key, leaves it on that queue where a partitioned dequeue never picks it up. Resume it again with a key.
Running 1.3 and 1.4 together
- Don't turn on suspend mode until no 1.3 executor or client reads the system database, and then turn it on in every executor that may run a suspending workflow. 1.3 fails to list or read a
SUSPENDEDworkflow, and a 1.3 send doesn't wake one. - Queue concurrency is exact only once every claimer locks (#667). Java 1.4, Python 3.5.0 and TypeScript 5.5 serialize claims against a shared limit with an advisory lock; Java 1.3 and Go don't yet, so a queue they also serve can briefly exceed its limit, as before.
- Debouncing works across both. 1.4 extends a debounced workflow under the deduplication ID 1.3 writes, and under the one the next release will write (#681), and still writes 1.3's.
Rolling back to 1.3
1.3 runs against a schema migrated to 130. Before rolling back:
- stop suspending: deploy code that no longer passes
trueassuspend, with suspend mode still on, since a suspendingrecvorsleepthrows once it is off; - wait until no workflow is
SUSPENDED, or cancel the ones that are, and only then turn suspend mode off, since only a process with it on wakes them. The new code is a new computed application version, and a suspended workflow runs only on its own version's executors, so keep those running with suspend mode on until they drain, or pinwithAppVersion; - downgrade
dev.dbos:transact-enterpriseto 1.3.0 along withdev.dbos:transact.
After rolling back, resume and rewind go to the internal queue again.
Source changes
The existing DBOS and DBOSClient methods are unchanged. However:
WorkflowStategainsSUSPENDEDandUNKNOWN. Aswitchexpression over it with nodefaultstops compiling.- Record components.
DBOSConfiggainstransactEnterpriseKeyandsuspendMode; code calling its canonical constructor must pass them.WorkflowStatusgainsunknownStatus, and keeps its previous constructor. Recompile against 1.4: 1.3-compiled code that callsDBOSConfig's constructor fails withNoSuchMethodError. - The Transact Enterprise contract moved to
dev.dbos.transact.spi(#671).ConductorProvider,ConductorEngineandConductorSystemDatabasebecomeEnterpriseProvider,EnterpriseEngineandEnterpriseSystemDatabase;WorkflowForkmoves unchanged;ConductorProvidersis removed; andSystemDatabase.forConductor()becomesforEnterprise(). They're the contract betweendev.dbos:transactanddev.dbos:transact-enterprise, not application API.
Behavior changes
Workflow status
- A status this version doesn't know reads as
WorkflowState.UNKNOWN(#679, #689), with the stored status inWorkflowStatus.unknownStatus(), which is null for every known status. DBOS leaves the stored status as it is. Before, listings,getWorkflowStatus,getResult, stream reads and debouncing threw on it.UNKNOWNis neither active nor terminal: result waits and stream reads keep waiting, rewind refuses it, andwithStatus(WorkflowState.UNKNOWN)lists every such workflow. JSON writesUNKNOWNwithunknownStatusbeside it, and Conductor's listings, export and import carry the stored status. SUSPENDEDcounts as in flight everywhere active workflows are read: listings, the timeout sweep, application rename, debouncing and result waits (#670). Rewind refuses aSUSPENDEDworkflow, as it does aPENDINGone.
Recorded outcomes
- A workflow error the serializer can't write is recorded as a stand-in
RuntimeException("<class>: <message>")with the original's stack trace, and the workflow endsERROR(#678). Before, the workflow stayedPENDING, and recovery ran its body again until it was dead-lettered. The first caller still gets the original exception; a replay gets the stand-in. - A step error or result the serializer can't write is recorded as an error, and the workflow body gets that recorded error, so a
catchtakes the same branch on the first run and on replay. Before, nothing was recorded and a replay ran the step again. This covers transactional steps too. - A recorded error whose class can't be read back returns a
PortableWorkflowExceptionnaming the recorded class and message, instead of failing the read (#673). This covers a class that was removed or changed incompatibly, and three DBOS exceptions whose serialized form changed:DBOSSystemDatabaseExceptionrecorded by 1.0,DBOSWorkflowFunctionNotFoundExceptionrecorded by 1.0–1.1, andDBOSWorkflowExecutionConflictExceptionrecorded by 1.0–1.2. Code catching the recorded class doesn't catch the stand-in.
Durable waits use the database's clock
- A durable sleep's wake time, and a
recvorgetEventtimeout in a workflow, are set on the database's clock (#688), and the wait is measured from that reading on the JVM's monotonic clock. Before, they were set and checked on the JVM's wall clock, so a workflow recovered on a host whose clock differed woke early or late by the skew. Suspend mode's wake times are on the database's clock too. - A retry keeps the first attempt's reading, so a failed attempt doesn't push the wake time out.
- The recorded format is unchanged: a sleep or timeout recorded by 1.3 replays as before.
getEventoutside a workflow still uses the JVM's clock. Debounce deadlines and the end of awithDelayare also still on the JVM's clock.
Queues
- Claims against a shared limit are serialized (#667): queue
concurrency, partition concurrency, and either rate limit. Two executors could each admit a workflow to a queue withconcurrency1 when they picked different heads of the queue. On CockroachDB, which has no advisory locks, those claims run atSERIALIZABLEinstead.
Configuration
- An empty or whitespace-only
conductorKeyorconductorDomainmeans unset (#664). For example,dbos.conductor.key=${KEY:}withKEYunset starts without Conductor; before, an empty key threw and a whitespace-only key connected with it. Surrounding whitespace, such as a trailing newline from a secret file, is stripped from these and fromtransactEnterpriseKey. DBOSConfig.toStringmasksconductorKey,transactEnterpriseKeyand any credentials inconductorDomain.
System database
- A sharded system schema is refused at launch and by
DBOSClient(#672), withIllegalStateException, before anything is created or read. Python, TypeScript and Go can create one through their enterprise packages; Java doesn't support it. Before, Java migrated or read it as an unsharded schema.
Fixes
- A debounce whose key is held by a workflow with a status this version doesn't know fails with
DBOSQueueDuplicatedExceptioninstead of retrying forever (#679). - The
updateQueuejavadoc states which limits allow pausing a queue (#677).
Full Changelog: 1.3.0...1.4.0