Skip to content

Commit

Permalink
Improve comment around locking schema map
Browse files Browse the repository at this point in the history
  • Loading branch information
bnaecker committed Oct 24, 2023
1 parent a67f226 commit c1b2875
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions oximeter/db/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,11 +384,12 @@ impl Client {
let name = sample_schema.timeseries_name.clone();
let mut schema = self.schema.lock().await;

// We need to possibly check that this schema is in the local cache, or
// in the database, all while we hold the lock to ensure there's no
// concurrent additions. This containment check is needed so that we
// check both the local cache and the database, to avoid adding a schema
// a second time.
// We've taken the lock before we do any checks for schema. First, we
// check if we've already got one in the cache. If not, we update all
// the schema from the database, and then check the map again. If we
// find a schema (which now either came from the cache or the latest
// read of the DB), then we check that the derived schema matches. If
// not, we can insert it in the cache and the DB.
if !schema.contains_key(&name) {
self.get_schema_locked(&mut schema).await?;
}
Expand Down

0 comments on commit c1b2875

Please sign in to comment.