but after I scaling up to 2 machines (following the instructions here epic-stack/docs/database.md at main · epicweb-dev/epic-stack · GitHub) I’ve started to see these issues come through and see the same when connecting prisma studio to the primary machine and attempting to update records there.
is there some configuration I’m missing? currently have 2 machines in lhr region (with one of them currently the primary) and another couple in ewr.
Perhaps you were unknowingly connecting to the other machine in the primary region, rather than to the actual primary machine? (They do hand off, in some circumstances.)
fly logs should help narrow this down, either way…
How would I ensure that this write is always attempted on this primary?
I’m also pretty confused as to why I get the same error when connecting to the primary machine with prisma studio, when I am definitely choosing the primary machine?
One of them is that you can’t perform writes within a GET request. (From the logs, it looks like you might have such.)
I’m surprised by this part, too.
How about trying with the sqlite3 command line—from within fly ssh console—to reduce moving parts?
$ fly ssh console --machine ...336d8 # primary
# # note: this script is a little defensive about env vars not being defined, etc.
# test -d "${LITEFS_DIR:-not-there}" || echo litefs dir at unexpected location.
# test -f "${LITEFS_DIR}"/.primary && echo not primary. # should not exist
# sqlite3 "${DATABASE_PATH:-/not-there/missing.db}"
> create table TST (X int);
> insert into TST values (7);
> .q
Scanning the logs for recent primary lease acquired messages, to make sure they still match the machine ID, might also be prudent.