惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

阮一峰的网络日志
阮一峰的网络日志
Blog — PlanetScale
Blog — PlanetScale
B
Blog RSS Feed
L
LangChain Blog
Jina AI
Jina AI
爱范儿
爱范儿
C
Check Point Blog
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
月光博客
月光博客
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Stack Overflow Blog
Stack Overflow Blog
V
V2EX
A
About on SuperTechFans
有赞技术团队
有赞技术团队
Microsoft Azure Blog
Microsoft Azure Blog
The GitHub Blog
The GitHub Blog
博客园 - Franky
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Transaction Commit Granularity and Rollback Boundaries in...
Michael · 2026-06-04 · via DEV Community

Michael

Many "re‑runs keep getting harder" problems in GBase 8a batch processing don't come from the scheduler — they come from commit granularity, batch boundaries, and rollback strategies that were never explicitly designed. A multi‑step script fails halfway; nobody can say which steps are already committed and which are still in the session; re‑running either doubles the results or leaves stale data, and teams end up fixing things by hand.

Why Transaction Boundaries Matter in Batch Work

Analytical databases mostly read in bulk, but as soon as you do any of the following, transaction boundaries become critical:

  • Writing intermediate results in stages
  • Bulk‑updating status flags
  • Delete‑before‑insert or truncate‑before‑build patterns
  • Maintaining multiple tables for the same batch
  • Re‑running or rolling back after a failure

The real question is: when a job fails, is the state already written to the database explainable, cleanable, and re‑runnable?

The First Three Questions to Ask

1. Whole‑batch commit or piecewise commit?

Commit Style Short‑term Benefit Production Risk
Whole‑batch commit Logically complete Big blast radius on failure — is the rollback truly controllable?
Piecewise commit Clear stage boundaries May leave partial work behind — is the re‑run strategy clear?

Neither is inherently better. What matters is that the business boundary of each piece is explicitly defined.

2. Is the script idempotent?

If a failed job can't safely run again, the situation will only get worse. Check for: DROP IF EXISTS or batch‑aware overwrites, batch identifiers in table names, whether a re‑run will stack old results on top, and whether cleanup steps exist after a failure.

3. Who handles the aftermath of a failure?

Don't assume "just rollback" covers a multi‑table, multi‑script chain. Remediation must be designed into the job itself.

A Realistic Field Example

A daily report job has three steps: delete today's old results → build a staging table → merge into the final table.

DELETE FROM rpt_store_day WHERE rpt_dt = '2026-03-31';

CREATE TABLE stg_store_day_20260331 AS
SELECT store_id, SUM(pay_amt) AS amt_sum
FROM fact_order WHERE dt = '2026-03-31'
GROUP BY store_id;

INSERT INTO rpt_store_day
SELECT '2026-03-31' AS rpt_dt, store_id, amt_sum
FROM stg_store_day_20260331;

Enter fullscreen mode Exit fullscreen mode

If step 3 fails, the situation is ugly: the final table's data for the day is already deleted, the staging table exists, but the new results were never written. "Can we rollback?" — without a clear boundary and a recovery plan, the answer is usually "only by hand."

A More Robust Approach

  1. Embed a batch identifier — a date‑tagged staging table name makes the batch explicit.
  2. Make the final table write re‑runnable — delete by batch condition, then insert from the verified staging table.
  3. Add a row‑count sanity check between stages so operators have a baseline for validation.

A re‑designed script:

BIZ_DT=2026-03-31
gccli -h ${DBHOST} -u ${DBUSER} ${DBNAME} <<SQL
DROP TABLE IF EXISTS stg_store_day_${BIZ_DT//-/};

CREATE TABLE stg_store_day_${BIZ_DT//-/} AS
SELECT store_id, SUM(pay_amt) AS amt_sum
FROM fact_order WHERE dt = '${BIZ_DT}'
GROUP BY store_id;

SELECT COUNT(*) AS stg_cnt FROM stg_store_day_${BIZ_DT//-/};

DELETE FROM rpt_store_day WHERE rpt_dt = '${BIZ_DT}';

INSERT INTO rpt_store_day
SELECT '${BIZ_DT}' AS rpt_dt, store_id, amt_sum
FROM stg_store_day_${BIZ_DT//-/};
SQL

Enter fullscreen mode Exit fullscreen mode

The difference isn't in clever SQL — it's in knowing which batch to clean, rebuild, and re‑insert after a failure.

Four Common Pitfalls

  1. Deletes, builds, and writes all jumbled in one script without explicit boundaries — makes it nearly impossible to determine what state the database is in after a failure.
  2. Staging tables with no batch identifier — after a re‑run, you can't tell whether this table belongs to the current run or a previous one.
  3. Designing only the happy path — the most common path in production is failure, retry, and catch‑up.
  4. Treating rollback as something that just exists — across multi‑step operations, a database transaction and job‑level remediation are completely different things.

Summary

Scenario Recommended Approach Why
Single‑batch final writes Explicit batch‑scoped delete & insert Easy cleanup and re‑run
Complex multi‑stage calculation Stage first, merge later Intermediate results are verifiable
Frequent re‑runs after failures Idempotency first Lower manual repair cost
Multi‑table coordinated updates Separate business boundaries first Reduce partially‑completed states

What makes a batch job truly maintainable isn't whether it "finishes successfully" — it's what state it leaves behind when it fails. Designing commit granularity, batch boundaries, and retry logic up front will save you far more time than patching things up after every incident in a gbase database.