Module 11 · Lesson 11 of 15Detailed study · about 25 min

Prove rollback, retry, deletes and older-event replay

Failure testing should demonstrate that uncommitted target changes and stream advancement are both undone, then show that replay does not regress current state.

Understand the idea

We first append order 101 version 3 DELETE. An intentional failure after MERGE should leave its committed version 2 amount 120 intact and keep the delete pending. This is the critical atomicity check.

Key ideas in simple English
ConceptWhat it means
Failure after MERGETests rollback after actual work, not just before it.
RetryReprocess the still-pending interval.
Older replayMust not overwrite a newer committed version.
Empty callShould leave target state unchanged.

A concrete example

Expect committed 101/version2/120 and 102/version1/50 unchanged, with 1 pending event.

Remember: Retry is safe only when the data changes and acknowledgement share the intended transaction boundary.

Explain it step by step · full theory

Understand the concept

We first append order 101 version 3 DELETE. An intentional failure after MERGE should leave its committed version 2 amount 120 intact and keep the delete pending. This is the critical atomicity check.

A retry without the failure switch should retain a tombstone at version 3. Active reports exclude that row but its version remains available for later comparisons.

Walk through the behavior

Then append old version 1 again and a new order 103. The old event must not resurrect 101; 103 is inserted. A second call with no new events should be a harmless no-op.

Run the failure CALL separately. Clients often stop on an error, so verification queries must be executed afterward explicitly. This is a manual learner experiment, not an automated test performed by this website.

Words used in this lesson
Failure after MERGE
Tests rollback after actual work, not just before it.
Retry
Reprocess the still-pending interval.
Older replay
Must not overwrite a newer committed version.
Empty call
Should leave target state unchanged.

See how it works

Choose a step to explore the idea at your own pace.

Open the interactive explanation
Interactive explainer1 / 3

Prove rollback, retry, deletes and older-event replay

Source data
Change boundary

Start with the source

Failure testing should demonstrate that uncommitted target changes and stream advancement are both undone, then show that replay does not regress current state.

Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.

Read the complete diagram explanation
  1. Start with the source

    Failure testing should demonstrate that uncommitted target changes and stream advancement are both undone, then show that replay does not regress current state.

  2. Follow the work

    We first append order 101 version 3 DELETE. An intentional failure after MERGE should leave its committed version 2 amount 120 intact and keep the delete pending. This is the critical atomicity check.

  3. Explain the outcome

    Retry is safe only when the data changes and acknowledgement share the intended transaction boundary.

Try the SQL or command

Read → predict → run in your learning environment → compare. You can also learn by reading without an account.

New to SQL? Where to run it and how to read it

A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.

  1. No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
  2. For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
  3. Read the entire example, including comments beginning with --. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor.
  4. Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
SELECT / FROM
Choose the values to return / identify their input.
VALUES / COLUMN1
VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
AS / WITH
AS gives a result a readable name. WITH names a temporary query step within one statement.
NULL / ::
NULL means missing or unknown. The :: notation converts a value to a named data type.
Session
One connection and its settings. Keep related transaction steps in the same session.
Database.schema.table
A full address for stored data. It is separate from the warehouse that processes queries.

Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →

Help with common practice errors
  • No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
  • Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
  • Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
  • Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.

Before running this lesson

Manual learning lab; nothing runs on this website. Complete lesson 1 setup in L2_OBJECTS_LAB.M11_LAB and follow the lesson order. Use the same authorized role and warehouse for manual SQL. Task templates use <lab_warehouse>: replace it with an approved warehouse name. Do not activate several consumers against the same stream. Each task starts suspended; running or resuming it can consume compute credits.

Append a delete and intentionally fail

SQL · example
INSERT INTO ORDER_EVENTS VALUES (4,101,3,'DELETE',NULL);
CALL APPLY_EVENTS(TRUE);
-- Expected error. Execute these separately afterward:
SELECT * FROM ORDER_STATE ORDER BY ORDER_ID;
SELECT COUNT(*) AS PENDING FROM EVENT_CHANGES;

What to expect and why

Expect committed 101/version2/120 and 102/version1/50 unchanged, with 1 pending event.

Retry and retain the tombstone

SQL · example
CALL APPLY_EVENTS(FALSE);
SELECT * FROM ORDER_STATE ORDER BY ORDER_ID;

What to expect and why

Order 101 is version 3, AMOUNT NULL and IS_DELETED true. Order 102 remains active with 50.

Replay an older event and append a new order

SQL · example
INSERT INTO ORDER_EVENTS VALUES (1,101,1,'UPSERT',100),(5,103,1,'UPSERT',70);
CALL APPLY_EVENTS(FALSE);
CALL APPLY_EVENTS(FALSE);
SELECT ORDER_ID,AMOUNT FROM ORDER_STATE WHERE NOT IS_DELETED ORDER BY ORDER_ID;
SELECT COUNT(*) FROM EVENT_CHANGES;

What to expect and why

Active rows: 102/50 and 103/70, total 120. The tombstone for 101 remains version 3. The second empty call changes no business state; pending count is 0.

Check your understanding

Choose an answer, then check your reasoning. This is practice, not a scored test.

What should happen to the stream offset when the procedure rolls back?

Try it yourself

What would happen if we physically deleted 101 and forgot its version?

Compare your reasoning

The replayed older upsert could appear unmatched and recreate it. The tombstone prevents that resurrection.

Official sources and curriculum

Module 11 · See module scope