Skip to content

Commit

Permalink
Merge pull request #260 from ecmwf/bugfix/ecc-1898_clean_cache_when_u…
Browse files Browse the repository at this point in the history
…nalias_is_called

ECC-1898 GRIB: Key 'levelist' persists despite being taken out of the mars namespace
  • Loading branch information
shahramn authored Oct 28, 2024
2 parents 8581938 + 6180c42 commit 29f8220
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/action_class_alias.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h)
if (x->name_space_ == NULL)
x->name_space_ = act->name_space;

// TODO(maee): Make sure that the accessor is added to the trie

grib_context_log(p->h->context, GRIB_LOG_DEBUG, "alias: add only namespace: %s.%s",
act->name_space, act->name);
i = 0;
Expand Down Expand Up @@ -178,6 +180,13 @@ static int create_accessor(grib_section* p, grib_action* act, grib_loader* h)
act->name_space, act->name, y->name_);
/* printf("[%s %s]\n",y->all_names_[i], y->all_name_spaces_[i]); */

// ECC-1898: Remove accessor from cache
grib_handle* hand = grib_handle_of_accessor(y);
if (hand->use_trie && y->all_name_spaces_[i] != NULL && strcmp(y->name_, act->name) != 0) {
int id = grib_hash_keys_get_id(hand->context->keys, act->name);
hand->accessors[id] = NULL;
}

while (i < MAX_ACCESSOR_NAMES - 1) {
y->all_names_[i] = y->all_names_[i + 1];
y->all_name_spaces_[i] = y->all_name_spaces_[i + 1];
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ if( HAVE_BUILD_TOOLS )
grib_ecc-1764
grib_ecc-1792
grib_ecc-1806
grib_ecc-1898
grib_ecc-1907
grib_ecc-1941
grib_ecc-1942
Expand Down
38 changes: 38 additions & 0 deletions tests/grib_ecc-1898.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
# (C) Copyright 2005- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by
# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction.
#

. ./include.ctest.sh

label="grib_ecc-1898_test"

tempGrib=temp.$label.grib
tempOut=temp.${label}.txt

$tools_dir/grib_dump -Da $samp_dir/reduced_gg_pl_32_grib2.tmpl > $tempOut
grep -q '288-288 g2level level = 1000 \[vertical.level, mars.levelist\]' $tempOut

# For given MARS stream/types, we unalias the mars.levelist key
$tools_dir/grib_set -s stream=gfas,type=gsd $samp_dir/reduced_gg_pl_32_grib2.tmpl $tempGrib

# Check that the key is unaliased
$tools_dir/grib_dump -Da $tempGrib > $tempOut
grep -q '288-288 g2level level = 1000 \[vertical.level\]' $tempOut

$tools_dir/grib_dump -p levelist -Da $tempGrib 2> $tempOut
grep -q 'levelist: Key/value not found' $tempOut

result=$($tools_dir/grib_get -fp levelist $tempGrib)
[ "$result" = "not_found" ]

result=$($tools_dir/grib_get -fp mars.levelist $tempGrib)
[ "$result" = "not_found" ]

# Clean up
rm -f $tempGrib $tempOut
11 changes: 11 additions & 0 deletions tests/grib_uerra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -98,5 +98,16 @@ $grib2_sample $temp1
grib_check_key_equals $temp1 'marsExpver,mars.expver' '0078 0078'


# Stream 'dame'
${tools_dir}/grib_set -s productionStatusOfProcessedData=10 $grib2_sample $temp1
grib_check_key_equals $temp1 'mars.time,mars.step' '1200 0'

${tools_dir}/grib_set -s \
productionStatusOfProcessedData=10,productDefinitionTemplateNumber=8,outerLoopTypeOfTimeIncrement=1,outerLoopLengthOfTimeRange=21 \
$grib2_sample $temp1
grib_check_key_equals $temp1 'mars.stream' 'dame'
result=$(${tools_dir}/grib_get -fp mars.time,mars.step $temp1)
[ "$result" = "not_found not_found" ]

# Clean up
rm -f $temp1 $temp2 $tempSample

0 comments on commit 29f8220

Please sign in to comment.