Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
06f7ea5
Initial commit
zainkabani Oct 13, 2023
1cd957e
Cleanup and add stats
zainkabani Oct 13, 2023
af6c2ea
Use an arc instead of full clones to store the parse packets
zainkabani Oct 13, 2023
2247f86
Use mutex instead
zainkabani Oct 13, 2023
d4d88c4
Merge branch 'main' into zain/reimplment-prepared-statements-with-glo…
zainkabani Oct 13, 2023
d2927d0
fmt
zainkabani Oct 13, 2023
fb23e33
clippy
zainkabani Oct 13, 2023
2fb3d4a
fmt
zainkabani Oct 13, 2023
a59aa63
fix?
zainkabani Oct 13, 2023
e2963e9
fix?
zainkabani Oct 13, 2023
8111582
fmt
zainkabani Oct 13, 2023
6e85fb2
typo
zainkabani Oct 13, 2023
46c8f9e
Update docs
zainkabani Oct 14, 2023
9a80b47
Refactor custom protocol
zainkabani Oct 14, 2023
19d8478
fmt
zainkabani Oct 14, 2023
a07874a
move custom protocol handling to before parsing
zainkabani Oct 14, 2023
bf5a39c
Support describe
zainkabani Oct 14, 2023
6a87a68
Add LRU for server side statement cache
zainkabani Oct 14, 2023
b528b95
rename variable
zainkabani Oct 15, 2023
0177af8
Refactoring
zainkabani Oct 15, 2023
cd7942b
Move docs
zainkabani Oct 15, 2023
6205548
Fix test
zainkabani Oct 15, 2023
9cd675e
fix
zainkabani Oct 15, 2023
89e2651
Update tests
zainkabani Oct 16, 2023
d37514f
trigger build
zainkabani Oct 16, 2023
bcce2d5
Add more tests
zainkabani Oct 16, 2023
63aa0c7
Reorder handling sync
zainkabani Oct 17, 2023
e392607
Support when a named describe is sent along with Parse (go pgx) and e…
zainkabani Oct 17, 2023
53880f2
don't talk to client if not needed when client sends Parse
zainkabani Oct 17, 2023
2842c85
fmt :(
zainkabani Oct 17, 2023
5604546
refactor tests
zainkabani Oct 17, 2023
6a1d7f6
nit
zainkabani Oct 17, 2023
a5d4bcf
Reduce hashing
zainkabani Oct 19, 2023
dd021c2
Reducing work done to decode describe and parse messages
zainkabani Oct 19, 2023
116a681
minor refactor
zainkabani Oct 19, 2023
72826e6
Merge branch 'main' into zain/reimplment-prepared-statements-with-glo…
zainkabani Oct 20, 2023
cfe8e9f
Merge branch 'main' into zain/reimplment-prepared-statements-with-glo…
zainkabani Oct 20, 2023
b27c918
Rewrite extended and prepared protocol message handling to better sup…
zainkabani Oct 21, 2023
d107bbe
An attempt to better handle if there are DDL changes that might break…
zainkabani Oct 21, 2023
21b9cde
fix
zainkabani Oct 21, 2023
d791f06
Minor stats fixed and cleanup
zainkabani Oct 21, 2023
a57550d
Cosmetic fixes (#64)
levkk Oct 23, 2023
db70499
Change server drop for statement cache error to a `deallocate all`
zainkabani Oct 23, 2023
7fa1147
Updated comments and added new idea for handling DDL changes impactin…
zainkabani Oct 23, 2023
005029d
fix test?
zainkabani Oct 23, 2023
6928d31
Revert test change
zainkabani Oct 23, 2023
b889b4b
trigger build, flakey test
zainkabani Oct 23, 2023
0dd5e88
Avoid potential race conditions by changing get_or_insert to promote …
zainkabani Oct 24, 2023
962090a
remove ps enabled variable on the server in favor of using an option
zainkabani Oct 24, 2023
80aa607
Add close to the Extended Protocol buffer
zainkabani Oct 24, 2023
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Avoid potential race conditions by changing get_or_insert to promote …
…for pool LRU
  • Loading branch information
zainkabani committed Oct 24, 2023
commit 0dd5e88414e0672c55deb373342bc6264cf00cb0
11 changes: 5 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ where
// TODO: Consider adding the close logic that this function can send for eviction to the client buffer instead
// In this case we don't want to send the parse message to the server since the client is sending it
self.register_parse_to_server_cache(
false, hash, &parse, &pool, server, &address,
false, &hash, &parse, &pool, server, &address,
)
.await?;

Expand Down Expand Up @@ -1661,7 +1661,7 @@ where
debug!("Prepared statement `{}` found in cache", parse.name);
// In this case we want to send the parse message to the server
// since pgcat is initiating the prepared statement on this specific server
self.register_parse_to_server_cache(true, *hash, parse, pool, server, address)
self.register_parse_to_server_cache(true, hash, parse, pool, server, address)
.await?;
}

Expand All @@ -1682,15 +1682,14 @@ where
async fn register_parse_to_server_cache(
&self,
should_send_parse_to_server: bool,
hash: u64,
hash: &u64,
parse: &Arc<Parse>,
pool: &ConnectionPool,
server: &mut Server,
address: &Address,
) -> Result<(), Error> {
// We want to update this in the LRU to know this was recently used and add it if it isn't there already
// This could be the case if it was evicted or if doesn't exist (ie. we reloaded and it got removed)
pool.register_parse_to_cache(hash, parse);
// We want to promote this in the pool's LRU
pool.promote_prepared_statement_hash(hash);

if let Err(err) = server
.register_prepared_statement(parse, should_send_parse_to_server)
Expand Down
14 changes: 14 additions & 0 deletions src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ impl PreparedStatementCache {
}
}
}

/// Marks the hash as most recently used if it exists
pub fn promote(&mut self, hash: &u64) {
self.cache.promote(hash);
}
}

/// An identifier for a PgCat pool,
Expand Down Expand Up @@ -1071,6 +1076,15 @@ impl ConnectionPool {
None => None,
}
}

/// Promote a prepared statement hash in the LRU
pub fn promote_prepared_statement_hash(&self, hash: &u64) {
// We should only be calling this function if the cache is enabled
if let Some(ref prepared_statement_cache) = self.prepared_statement_cache {
let mut cache = prepared_statement_cache.lock();
cache.promote(hash);
}
}
}

/// Wrapper for the bb8 connection pool.
Expand Down