Skip to content

Commit e8c5d3e

Browse files
committed
Update configuration
1 parent 94706fd commit e8c5d3e

File tree

5 files changed

+61
-41
lines changed

5 files changed

+61
-41
lines changed

src/gribjump/Config.cc

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,20 @@
1717
namespace gribjump {
1818

1919
// Config options:
20-
// - `type` : Whether GribJump will work locally or forward work to a server. Allowed values are `local` or `remote`.
21-
// - `server` : Configuration for the remote server.
22-
// - `host` : The hostname of the server.
23-
// - `port` : The port number of the server.
24-
// - `threads` : The number of worker threads created for gribjump.extract. Default is 1.
25-
// NOTE Setting env GRIBJUMP_THREADS will override this setting.
26-
// - `cache` : Configuration of the cache.
27-
// - `directory` : The directory where the cache will be stored. Default is `~gribjump/cache/etc/gribjump/cache`.
28-
// Note can be overridden by env var GRIBJUMP_CACHE_DIR.
29-
// - `shadowfdb` : If true, the cache files will be stored in the same directory as data files, instead of `directory`.
30-
// - `enable` : If false, the caching will be disabled.
31-
// - `plugin` : Configuration for using GribJump as a plugin to FDB, which generates jumpinfos on the fly for fdb.archive()
32-
// NOTE Plugin cannot be enabled from config, one must set the envar FDB_ENABLE_GRIBJUMP
33-
// NOTE Setting env FDB_DISABLE_GRIBJUMP will override this setting and disable the plugin.
34-
// - `select` : Defines regex for selecting which FDB keys to generate jumpinfo for. If unset, no jumpinfos will be generated.
35-
// : example `select: date=(20*),stream=(oper|test)`.
20+
// - type // Whether GribJump will work locally or forward work to a remote server. Allowed values are `local` or `remote`.
21+
// - server // Configuration for gribjump-server.
22+
// - port // The port to listen on for incoming work.
23+
// - uri // host:port of remote server to forward work to (requires type:remote)
24+
// - threads // The number of worker threads for gribjump.extract. Default is 1.
25+
// - cache // Configuration of the cache.
26+
// - shadowfdb // If true, the cache files will be stored in the same directory as data files. DEFAULT=true
27+
//  - directory // The directory where the cache will be stored, instead of shadowing the FDB.
28+
// - enable // Whether to look at the cache at all. DEFAULT=true
29+
// - plugin // Configuration for using GribJump as a plugin to FDB, which generates jumpinfos on the fly for fdb.archive()
30+
// // NOTE Plugin cannot be enabled from config, one must set the envar FDB_ENABLE_GRIBJUMP
31+
// // NOTE Setting env FDB_DISABLE_GRIBJUMP will override this setting and disable the plugin.
32+
// - select // Defines regex for selecting which FDB keys to generate jumpinfo for. If unset, no jumpinfos will be generated.
33+
// // example `select: date=(20*),stream=(oper|test)`.
3634

3735
Config::Config() {
3836
}

src/gribjump/info/InfoCache.cc

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,32 @@ InfoCache::~InfoCache() {
4242
InfoCache::InfoCache(): cacheDir_(eckit::PathName()) {
4343

4444
const Config& config = LibGribJump::instance().config();
45+
46+
bool enabled = config.getBool("cache.enabled", true);
47+
if (!enabled) {
48+
persistentCache_ = false;
49+
LOG_DEBUG_LIB(LibGribJump) << "Cache disabled" << std::endl;
50+
return;
51+
}
4552

46-
shadowCache_ = config.getBool("cache.shadowfdb", false);
53+
std::string cache_str = config.getString("cache.directory", "");
54+
shadowCache_ = config.getBool("cache.shadowfdb", cache_str.empty());
4755
if (shadowCache_) {
4856
LOG_DEBUG_LIB(LibGribJump) << "Shadow FDB cache enabled" << std::endl;
4957
return;
5058
}
5159

52-
std::string cache = eckit::Resource<std::string>("$GRIBJUMP_CACHE_DIR", config.getString("cache.directory", ""));
53-
bool enabled = config.getBool("cache.enabled", true);
54-
55-
if(!enabled || cache.empty()) {
56-
persistentCache_ = false;
57-
LOG_DEBUG_LIB(LibGribJump) << "Warning, cache persistence is disabled" << std::endl;
58-
return;
60+
// Shadow FDB has been explicitly disabled
61+
if (cache_str.empty()) {
62+
throw eckit::BadValue("Cache directory not set");
5963
}
6064

61-
cacheDir_ = eckit::PathName(cache);
62-
LOG_DEBUG_LIB(LibGribJump) << "Cache directory " << cacheDir_ << std::endl;
63-
65+
cacheDir_ = eckit::PathName(cache_str);
6466
if (!cacheDir_.exists()) {
6567
throw eckit::BadValue("Cache directory " + cacheDir_ + " does not exist");
6668
}
69+
70+
LOG_DEBUG_LIB(LibGribJump) << "Using cache directory: " << cacheDir_ << std::endl;
6771
}
6872

6973
eckit::PathName InfoCache::cacheFilePath(const eckit::PathName& path) const {

src/gribjump/remote/RemoteGribJump.cc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,25 @@
1919

2020
namespace gribjump {
2121

22-
RemoteGribJump::RemoteGribJump(const Config& config): GribJumpBase(config) {
23-
if (!config.get("remote.host", host_))
24-
throw eckit::UserError("RemoteGribJump requires host to be set in config", Here());
22+
RemoteGribJump::RemoteGribJump(const Config& config): GribJumpBase(config){
23+
std::string uri = config.getString("uri", "");
2524

26-
if (!config.get("remote.port", port_))
27-
throw eckit::UserError("RemoteGribJump requires port to be set in config", Here());
25+
if (uri.empty())
26+
throw eckit::UserError("RemoteGribJump requires uri to be set in config (format host:port)", Here());
27+
28+
// parse uri, expect format "host:port"
29+
size_t pos = uri.find(':');
30+
31+
if (pos == std::string::npos)
32+
throw eckit::UserError("RemoteGribJump uri must be in the format 'host:port'", Here());
33+
34+
host_ = uri.substr(0, pos);
35+
if (host_.empty())
36+
throw eckit::UserError("RemoteGribJump requires host to be set in uri", Here());
37+
38+
port_ = std::stoi(uri.substr(pos+1));
39+
if (port_ == 0)
40+
throw eckit::UserError("RemoteGribJump requires port to be set in uri", Here());
2841
}
2942

3043
RemoteGribJump::~RemoteGribJump() {}

tests/tools/callback_vs_scan.sh.in

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ fdbread="$<TARGET_FILE:fdb-read>"
2020
gjscan="$<TARGET_FILE:gribjump-scan>"
2121
gjextract="$<TARGET_FILE:gribjump-extract>"
2222
gjinfo="$<TARGET_FILE:gribjump-dump-info>"
23+
gribset="$<TARGET_FILE:grib_set>"
2324

2425
srcdir=@CMAKE_CURRENT_SOURCE_DIR@
2526
bindir=@CMAKE_CURRENT_BINARY_DIR@
@@ -49,15 +50,21 @@ spaces:
4950
EOF
5051
done
5152

52-
# Get the mars requests corresponding to the data, for scanning/extracting
53+
# Data from nexus
5354
supporteddata="${bindir}/supported.grib"
5455
unsupporteddata="${bindir}/unsupported.grib"
55-
testdata=${bindir}/alldata.grib
5656

57-
cat $supporteddata $unsupporteddata > $testdata
57+
# Group data based on whether we expect it to be selected by the filter.
58+
# We will be selecting expver=xxxx, and not xxxy.
59+
selected=${bindir}/selected.grib # data to be selected (all other data is filtered)
60+
unselected=${bindir}/unselected.grib # data to be filtered out
61+
testdata=${bindir}/alldata.grib
62+
cat $supporteddata $unsupporteddata > $selected
63+
$gribset -s "expver=xxxy" $selected $unselected
64+
cat $selected $unselected > $testdata
5865

59-
requests=${bindir}/requests
60-
$fdbread --extract ${testdata} /dev/null > $requests
66+
selectedrequests=${bindir}/requests
67+
$fdbread --extract ${selected} /dev/null > $selectedrequests
6168

6269
# -------------------------------------
6370
# 1: Reference FDB
@@ -77,7 +84,7 @@ unset FDB_ENABLE_GRIBJUMP
7784
echo "Writing to FDB without gribjump plugin, then scanning"
7885
$fdbwrite ${testdata}
7986

80-
$gjscan $requests
87+
$gjscan $selectedrequests
8188

8289
# -------------------------------------
8390
# 3: FDB with gribjump plugin

tests/tools/gribjump-fdb.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
---
22
plugin:
3-
select: date=(2*)
4-
cache:
5-
shadowfdb: true
3+
select: expver=(xxxx)

0 commit comments

Comments
 (0)