V20 Prepare two writer processes
Use your current course session. Preparation and course runner · R script ↓
Optional deep dive. Enable only the options named in each block, after preparing its packages or services.
V20 Prepare two writer processes
Goal: Observe coordinated publication.
Prerequisites: V18a; postgres=TRUE; two local R processes with matching packages and TRAINING_PG_CONNECTION.
The current writer lock is catalog-wide and serializes coordinated write sections. This is a manually started two-process experiment, not an automated load test.
training_step(
"V20",
{
writer_config_path <- file.path(training_root, "writer-config.rds")
saveRDS(pg_config, writer_config_path)
writer_path <- file.path(training_root, "writer.R")
writer_code <- c(
'args <- commandArgs(TRUE)',
'config <- readRDS(args[1])',
'writer <- args[2]',
'data <- data.frame(policy_id=1L, premium=as.numeric(args[3]), cancelled=FALSE)',
'product <- dataraft.core::dr_product(paste0("training.writer.", writer), data)',
'print(dataraft.core::dr_publish(product, to=config))'
)
writeLines(writer_code, writer_path)
cat(
"Terminal A: Rscript ",
shQuote(writer_path),
" ",
shQuote(writer_config_path),
" A 100
",
sep = ""
)
cat(
"Terminal B: Rscript ",
shQuote(writer_path),
" ",
shQuote(writer_config_path),
" B 200
",
sep = ""
)
},
needs = c("V18a"),
enabled = training_options$postgres,
optional = TRUE
)Expected result: Two commands to run in separate terminals. Depending on timing, both finish sequentially or one times out on the lock. Tiny deliveries may not visibly overlap.
Task: Can direct SQL bypass the DataRaft lock?
Show solution
Yes. All writers must use the coordinated protocol; this is not a universal database lock.