Checkpoint upgrade and migration
When upgrading from 2.1.0.0 to 2.1.0.1, check the saver storage your application actually uses. If you have no checkpoints to keep, initialize a new store using the saver guide. If you need to keep old checkpoints, start at step 1. A MemorySaver holds data in the running process and requires no migration.
1. Back up and prepare the existing store
When Before the first 2.1.0.1 instance receives traffic.
- Back up checkpoints and archives. Test restoring the backup in a staging environment, note the conversation's
threadId, and keep the original database or directory and serializer. - Choose the action for your saver. For relational databases, connect to the original schema with a migration account that can run DDL.
| Saver | Action during preparation |
|---|---|
| PostgreSQL | Run PostgresSaver.builder().datasource(migrationDataSource).createOption(CreateOption.CREATE_IF_NOT_EXISTS).build() on the existing schema. See the PostgreSQL example. |
| MySQL and Oracle | Build the saver with managedCheckpoints(true) and createOption(CreateOption.CREATE_IF_NOT_EXISTS). See MySQL or Oracle for required permissions. |
| MongoDB replica set, Redis single primary, or local files | Back up the original store and allow room for a copy of old history. Leave the cutover method for step 3. See MongoDB, Redis, or local files. |
After preparing a relational database, start the application saver with CreateOption.CREATE_NONE. CREATE_OR_REPLACE drops existing tables.
2. Roll out and test mixed versions
When After testing the backup and completing store preparation.
-
Set the Spring AI Alibaba BOM or direct Graph Core dependency to
2.1.0.1. Run the command below in your application module and check that the output containsspring-ai-alibaba-graph-core:jar:2.1.0.1. Package the app and upgrade one deployment at a time. Keep the saver, storage location, serializer, and graph configuration. Leave the per-key options off.mvn dependency:tree -Dincludes=com.alibaba.cloud.ai:spring-ai-alibaba-graph-core -
Before stopping the last old instance, choose a test thread. Write progress to the original
threadIdon the upgraded app. Read it using the old app and confirm it sees the new value. To check across instances, use a newly built saver for the read or configuremaxCachedThreads(0)on an old JDBC or file saver that supports the option. -
Upgrade the remaining readers and writers. Assign each
threadIdto one executor at a time during the rollout. If the mixed-version check fails, keep the current write format while investigating.
3. Pause writes and cut over
Proceed when all three checks pass
- Every app using the store is running
2.1.0.1, and the instance list contains no old processes. - Incoming work and scheduled jobs are paused. In-flight runs, checkpoint writes, archive jobs, and pruning have finished. Old instances and credentials can no longer write.
- A recoverable pre-cutover backup was taken with writes paused. Record the restore point.
Use one migration job to connect to the original store and run the Java call for your saver.
| Saver | Cutover call | After the call succeeds |
|---|---|---|
| PostgreSQL | postgresSaver.activateCheckpointV1Writes(); | Keep traffic paused and go to step 4. |
| MySQL, Oracle, MongoDB, Redis, or local files | saver.activateManagedCheckpointWrites(); | Restart the upgraded app or rebuild the saver and recompile the graph, then go to step 4. |
If the call fails, keep writes paused. Use the saver guide to check permissions, storage space, and history mappings before proceeding.
4. Verify and restore traffic
When After the cutover call returns successfully and any required restarts are complete.
- Use the upgraded app and the original
threadIdto resume a workflow that was paused before cutover. Confirm it completes its next step and saves new progress. - Read the thread with a newly built saver. Confirm both its old history and the latest progress are available. If the application branches from history in production, test a fork as well.
- Restore traffic after the checks pass. To reduce the cost of saving large state, try offloading, deltas, or untracked keys on a few workflows. Keep garbage collection in its default observation mode until you have reviewed archive retention.
If you enable offloading, test cold recovery with a 10 MiB payload. Restart and resume at a node that does not use the key. Body reads and bytes should both be zero. Then read the key and confirm it has the original value. Recovery metrics
Example: Migrate a PostgreSQL approval workflow
In a staging database, use your application's PostgresSaver to pause a workflow before the review node. Run each block in a process using the indicated version. Use the same schema and serializer throughout. In the example, saver is the application's PostgreSQL saver. The migrationDataSource connects to that schema as the migration account.
1. Save a pending approval in 2.1.0.0. Use a thread ID you have not used before. The application saver can use CreateOption.CREATE_NONE once the old application has created the schema.
import java.util.Map;
import com.alibaba.cloud.ai.graph.CompileConfig;
import com.alibaba.cloud.ai.graph.RunnableConfig;
import com.alibaba.cloud.ai.graph.StateGraph;
import com.alibaba.cloud.ai.graph.checkpoint.config.SaverConfig;
import com.alibaba.cloud.ai.graph.state.strategy.ReplaceStrategy;
import static com.alibaba.cloud.ai.graph.StateGraph.END;
import static com.alibaba.cloud.ai.graph.StateGraph.START;
import static com.alibaba.cloud.ai.graph.action.AsyncNodeAction.node_async;
var graph = new StateGraph(() -> Map.of("status", new ReplaceStrategy()))
.addNode("review", node_async(state -> Map.of("status", "APPROVED")))
.addEdge(START, "review")
.addEdge("review", END)
.compile(CompileConfig.builder()
.saverConfig(SaverConfig.builder().register(saver).build())
.interruptBefore("review")
.build());
var thread = RunnableConfig.builder().threadId("migration-order-42").build();
Create the test workflow on the old instance.
graph.stream(Map.of("status", "PENDING"), thread).blockLast();
2. Prepare the schema and check mixed-version writes. Run the first block in a 2.1.0.1 migration process. In the upgraded app, build the same graph and thread and run the second block. In the still-running 2.1.0.0 app, read with a new saver and run the third block. It should print READY.
import com.alibaba.cloud.ai.graph.checkpoint.savers.postgresql.CreateOption;
import com.alibaba.cloud.ai.graph.checkpoint.savers.postgresql.PostgresSaver;
PostgresSaver.builder()
.datasource(migrationDataSource)
.createOption(CreateOption.CREATE_IF_NOT_EXISTS)
.build();
// 2.1.0.1 saves an update while the workflow stays paused.
graph.updateState(graph.getState(thread).config(), Map.of("status", "READY"));
// 2.1.0.0 reads the same thread ID. Expect READY.
System.out.println(graph.getState(thread).state().value("status").orElseThrow());
3. Cut over after draining writes. After the step 3 checks pass, run this code with 2.1.0.1 on the same schema. The schema objects were prepared in the previous step.
var migrationSaver = PostgresSaver.builder()
.datasource(migrationDataSource)
.createOption(CreateOption.CREATE_NONE)
.build();
migrationSaver.activateCheckpointV1Writes();
To check the state with a PostgreSQL client, run this read-only query on the same schema. Expect true during step 2 and false after cutover. In psql, these appear as t and f.
SELECT legacy FROM graph_checkpoint_write_format WHERE singleton;
4. Resume the approval on the upgraded app. Run this code in the 2.1.0.1 app. It should print APPROVED. Restore traffic after the checks in step 4 pass.
var result = graph.invoke(Map.of(), thread.withResume()).orElseThrow();
System.out.println(result.value("status").orElseThrow());
Roll back
| Current stage | Action |
|---|---|
| Before calling the cutover method | Roll the application back to 2.1.0.0 against the existing store. It can read progress written during the compatibility period. |
| After cutover | Roll back to an application build that supports managed reads and writes. If you need 2.1.0.0, keep writes paused, restore the pre-cutover backup recorded in step 3, and confirm the recovery point before reconnecting traffic. Progress written after that backup is outside the recovery point. |
How cutover works and what it covers
Upgrading the dependency and switching the store are separate actions. During the compatibility period, 2.1.0.1 writes the old format (bare state) that 2.1.0.0 can read. After explicit cutover, new writes use the managed format checkpoint-v1. If you only need the application upgrade, you can stay in compatibility mode. Schedule cutover before enabling the per-key options.
The upgraded application can read identifiable old records directly. Older MongoDB or Redis archives without thread mappings, legacy file archives, and custom payload stores require separate handling. Follow the guide for your saver.