Skip to content

feat: add process name to 2pc transaction ID#1248

Merged
levkk merged 22 commits into
mainfrom
levkk-pod-transaction-name
Jul 23, 2026
Merged

feat: add process name to 2pc transaction ID#1248
levkk merged 22 commits into
mainfrom
levkk-pod-transaction-name

Conversation

@levkk

@levkk levkk commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Globally unique transaction ID

Without hopefully going over the 200 bytes limit.

Example:

__pgdog_2pc_pgdog-node-1_1231424234

The last part (the number) can be up to 20 chars long (usize::MAX), so I'm optimistic people don't name their nodes something 150 characters long, but I may be proven wrong.

Misc

  • Refactor cluster readiness into its own module.
  • Maybe? add code coverage to CI for integration tests? Still not sure if its working.
  • Add explicit SIGTERM handler which calls std::process:exit.

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

@levkk levkk changed the title feat: add process name to 2pc transaction ID feat: add process name to 2pc transaction ID + cleanup abandoned Jul 22, 2026
@levkk
levkk requested review from meskill and sgrif July 22, 2026 00:09
Comment thread pgdog/src/frontend/client/query_engine/two_pc/manager.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/statement.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/statement.rs Outdated
Comment thread pgdog/src/util.rs Outdated
Comment thread pgdog/src/backend/pool/connection/binding.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/transaction.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/transaction.rs Outdated
fn test_instance_id() {
for id in [1024, 11111111, usize::MAX, usize::MIN] {
let transaction = TwoPcTransaction(id);
let instance_id = instance_id(); // Generate it, it's a singleton.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels really gross having TwoPcTransaction rely on global state for its Display impl. Can we separate that out into something that allows the state to be injected?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does, yeah. We could call it more explicitly for sure, but we also want to avoid ever rendering a "non-unique" ID by accident.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I'm thinking we remove the Display impl and have fn display_name(&self, deployment_id: Option<&str>, instance_id: &str), pushing the state up to the caller and making this easier to test

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That'll be a lot of places, which I guess...doesn't really help, since we can fat-finger the calling site. And those are very much invariants/identifiers which we never ever want to confuse.

Comment thread pgdog/src/util.rs
instance_id().split("-").last().unwrap().parse()
}

static DEPLOYMENT_ID: Lazy<Option<String>> = Lazy::new(|| env::var("DEPLOYMENT_ID").ok());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEPLOYMENT_ID is a really generic name. Should we prefix this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like PGDOG_DEPLOYMENT_ID or something?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe. We already use other similar-named env variables there, e.g. NODE_ID. I don't expect ppl to run pgdog in an env shared by another app, and if they do, they certainly wouldn't be sharding, and if they did, I would be like...damn. But yeah, gotta be careful with breaking changes, like I'd want to change all env variables to match the new PGDOG_ format, but I cant :(

levkk and others added 4 commits July 22, 2026 06:49
Co-authored-by: Sage Griffin <sage@sagetheprogrammer.com>
Co-authored-by: Sage Griffin <sage@sagetheprogrammer.com>
Co-authored-by: Sage Griffin <sage@sagetheprogrammer.com>
Comment thread pgdog-config/src/general.rs Outdated
Comment thread pgdog-config/src/general.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/statement.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/manager.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/manager.rs Outdated
@levkk levkk changed the title feat: add process name to 2pc transaction ID + cleanup abandoned feat: add process name to 2pc transaction ID Jul 23, 2026
Comment thread pgdog/src/frontend/client/query_engine/two_pc/transaction.rs Outdated
Comment thread pgdog/src/frontend/client/query_engine/two_pc/manager.rs Outdated
Comment thread pgdog/src/backend/pool/cluster_launch.rs Outdated
Comment thread pgdog/src/backend/pool/cluster_launch.rs
@blacksmith-sh

This comment has been minimized.

@levkk
levkk requested a review from meskill July 23, 2026 13:08
Comment on lines +113 to +115
for shard in self.shards() {
shard.wait_schema_loaded().await;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be able to run in parallel.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah. Those are just waiters, the actual schema fetching runs in parallel, so these will resolve quickly.

@levkk

levkk commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

Still trying to figure out how to get coverage on integration tests -- will use this PR as guinea pig until I give up / it works.

@levkk

levkk commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

Pretty sure its working guys, let me know if you spot anything:

image

@levkk

levkk commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

@sgrif can you tell me if this is hallucinated:

/// Install a SIGTERM handler that exits the process via [`exit`], running

@sgrif

sgrif commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

It's accurate, but if this is purely for code coverage purposes I'd be sending SIGINT instead of SITGERM to the server (presumably we already gracefully shutdown on sigint)

@levkk

levkk commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

It's accurate, but if this is purely for code coverage purposes I'd be sending SIGINT instead of SITGERM to the server

Hmm, I wonder who's sending SIGTERM...nevermind, the call is coming from inside the house, it's our CI script.

@levkk

levkk commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

(presumably we already gracefully shutdown on sigint)

Correct

@levkk

levkk commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

Aight, well...maybe I'll just keep the handler? It seems like a nice to have feature, plus we get a logline, so that's cool.

@levkk
levkk merged commit c32b154 into main Jul 23, 2026
45 checks passed
@levkk
levkk deleted the levkk-pod-transaction-name branch July 23, 2026 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants