Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Freva Ingest
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
freva
Freva Ingest
Commits
52454bda
Commit
52454bda
authored
2 years ago
by
Brian Lewis
Browse files
Options
Downloads
Patches
Plain Diff
Switch to mutex
parent
db8d872a
No related branches found
Branches containing commit
Tags
0.5.0
Tags containing commit
1 merge request
!3
Add caching to cmip6 ingestion
Pipeline
#19223
passed
2 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
freva/src/drs/metadata.rs
+11
-8
11 additions, 8 deletions
freva/src/drs/metadata.rs
with
11 additions
and
8 deletions
freva/src/drs/metadata.rs
+
11
−
8
View file @
52454bda
...
...
@@ -4,7 +4,7 @@ mod config_builder;
pub
mod
custom
;
use
core
::
fmt
;
use
std
::
sync
::
RwLock
;
use
std
::
sync
::
Mutex
;
use
std
::{
collections
::
HashMap
,
fmt
::
Formatter
,
...
...
@@ -21,7 +21,7 @@ use drs::{
use
lazy_static
::
lazy_static
;
use
netcdf
::
AttrValue
;
use
thiserror
::
Error
;
use
tracing
::{
debug
,
error
};
use
tracing
::{
debug
,
error
,
trace
};
pub
use
config_builder
::
ConfigBuilder
;
use
custom
::
Custom
;
...
...
@@ -395,26 +395,29 @@ lazy_static! {
/// This is done as a global cache right now just because performance shouldn't be a large concern as we expect far
/// more reads than writes and this implementation is simpler than e.g. having the [`drs`] crate load and hold the
/// mapping values ahead of time.
static
ref
CMIP6_ATTR_CACHE
:
RwLock
<
HashMap
<
String
,
(
String
,
String
)
>>
=
RwLock
::
new
(
HashMap
::
new
());
static
ref
CMIP6_ATTR_CACHE
:
Mutex
<
HashMap
<
String
,
(
String
,
String
)
>>
=
Mutex
::
new
(
HashMap
::
new
());
}
/// Transforms a [`Cmip6`] object into [`Metadata`]. This is handled differently from the others because CMIP6's path
/// does not contain all the data [`Metadata`] needs. To get the rest we need to either use mapping tables maintained
/// separately from the DRS spec or, as we do here, open the files up and pull the data from their attributes.
fn
metadata_from_cmip6
(
cmip
:
Cmip6
,
root_dir
:
&
Utf8Path
)
->
Result
<
Metadata
,
ExtractMetadataError
>
{
let
(
frequency
,
realm
)
=
if
let
Some
((
freq
,
realm
))
=
CMIP6_ATTR_CACHE
.read
()
.unwrap
()
.get
(
cmip
.metadata.table_id
)
{
let
(
frequency
,
realm
)
=
{
let
mut
guard
=
CMIP6_ATTR_CACHE
.lock
()
.unwrap
();
if
let
Some
((
freq
,
realm
))
=
guard
.get
(
cmip
.metadata.table_id
)
{
(
freq
.clone
(),
realm
.clone
())
}
else
{
trace!
(
"attributes not cached, opening file to extract"
);
let
(
frequency
,
realm
)
=
get_cmip6_attrs
(
&
root_dir
.join
(
cmip
.path
))
?
;
CMIP6_ATTR_CACHE
.write
()
.unwrap
()
.insert
(
guard
.insert
(
cmip
.metadata.table_id
.to_owned
(),
(
frequency
.clone
(),
realm
.clone
()),
);
(
frequency
,
realm
)
};
}
};
let
m
=
&
cmip
.metadata
;
Ok
(
Metadata
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment