Commit Graph

98 Commits

Author SHA1 Message Date
Dennis Heimbigner
efdec07f3d Extend the netcdf API to support programmatic changes to the plugin search path
Replaces PR https://github.com/Unidata/netcdf-c/pull/3024
         and PR https://github.com/Unidata/netcdf-c/pull/3033

re: https://github.com/Unidata/netcdf-c/issues/2753

As suggested by Ed Hartnett, This PR extends the netcdf.h API to support programmatic control over the search path used to locate plugins.

I created several different APIs, but finally settled on the following API as being the simplest possible. It does have the disadvantage that it requires use of a global lock (not implemented) if used in a threaded environment.

Specifically, note that modifying the plugin path must be done "atomically". That is, in a multi-threaded environment, it is important that the sequence of actions involved in setting up the plugin path must be done by a single processor or in some other way as to guarantee that two or more processors are not simultaneously accessing the plugin path get/set operations.

As an example, assume there exists a mutex lock called PLUGINLOCK. Then any processor accessing the plugin paths should operate as follows:
````
lock(PLUGINLOCK);
nc_plugin_path_get(...);
<rebuild plugin path>
nc_plugin_path_set(...);
unlock(PLUGINLOCK);
````
## Internal Architecture

It is assumed here that there only needs to be a single set of plugin path directories that is shared by all filter code and is independent of any file descriptor; it is global in other words. This means, for example, that the path list for NCZarr and for HDF5 will always be the same.

However internally, processing the set of plugin paths depends on the particular NC_FORMATX value (NC_FORMATX_NC_HDF5 and NC_FORMATX_NCZARR, currently). So the *nc_plugin_path_set* function, will take the paths it is given and propagate them to each of the NC_FORMATX dispatchers to store in a way that is appropriate to the given dispatcher.

There is a complication with respect to the *nc_plugin_path_get* function. It is possible for users to bypass the netcdf API and modify the HDF5 plugin paths directly. This can result in an inconsistent plugin path between the value used by HDF5 and the global value used by netcdf-c. Since there is no obvious fix for this, we warn the user of this possibility and otherwise ignore it.

## Test Changes
* New tests<br>
    a. unit_test/run_pluginpaths.sh -- was created to test this new capability.<br>
    b. A new test utility has been added as *unit_test/run_dfaltpluginpath.sh* to test the default plugin path list.
* New test support utilities<br>
    a. unit_test/ncpluginpath.c -- report current state of the plugin path<br>
    b. unit_test/tst_pluginpaths.c -- test program to support run_pluginpaths.sh

## Documentation
* A new file -- docs/pluginpath.md -- provides documentation of the new API. It includes some
  material taken fro filters.md.

## Other Major Changes
1. Cleanup the whole plugin path decision tree. This is described in the *docs/pluginpath.md* document and summarized in Addendum 2 below.
2. I noticed that the ncdump/testpathcvt.sh had been disabled, so fixed and re-enabled it. This necessitated some significant changes to dpathmgr.c.

## Misc. Changes
1. Add some path manipulation utilities to netcf_aux.h
2. Fix some minor bugs in netcdf_json.h
3. Convert netcdf_json.h and netcdf_proplist.h to BUILT_SOURCE.
4. Add NETCDF_ENABLE_HDF5 as synonym for USE_HDF5
5. Fix some size_t <-> int conversion warnings.
6. Encountered and fixed the Windows \r\n problem in tst_pluginpaths.c.
7. Cleanup some minor CMakeLists.txt problems.
8. Provide an implementation of echo -n since it appears to not be
   available on all platforms.
9. Add a property list mechanism to pass environmental information to filters.
10. Cleanup Doxyfile.in
11. Fixed a memory leak in libdap2; surprised that I did not find this earlier.

## Addendum 1: Proposed API

The API makes use of a counted vector of strings representing the sequence of directories in the path. The relevant type definition is as follows.
````
typedef struct NCPluginList {size_t ndirs; char** dirs;} NCPluginList;
````

The API proposed in this PR looks like this (from netcdf-c/include/netcdf_filter.h).

* ````int nc_plugin_path_ndirs(size_t* ndirsp);````
    Arguments: *ndirsp* -- store the number of directories in this memory.

    This function returns the number of directories in the sequence if internal directories of the internal plugin path list.

* ````int nc_plugin_path_get(NCPluginList* dirs);````
    Arguments:  *dirs* -- counted vector for storing the sequence of directies in the internal path list.

    This function returns the current sequence of directories from the internal plugin path list. Since this function does not modify the plugin path, it does not need to be locked; it is only when used to get the path to be modified that locking is required.  If the value of *dirs.dirs* is NULL (the normal case), then memory is allocated to hold the vector of directories. Otherwise, use the memory of *dirs.dirs* to hold the vector of directories.

* ````int nc_plugin_path_set(const NCPluginList* dirs);````
    Arguments: *dirs* -- counted vector for providing the new sequence of directories in the internal path list.

    This function empties the current internal path sequence and replaces it with the sequence of directories argument. Using an *ndirs* argument of 0 will clear the set of plugin paths.

## Addendum 2: Build-Time and Run-Time Constants.

### Build-Time Constants
<table style="border:2px solid black;border-collapse:collapse">
<tr style="outline: thin solid;" align="center"><td colspan="4">Table showing the build-time computation of NETCDF_PLUGIN_INSTALL_DIR and NETCDF_PLUGIN_SEARCH_PATH.</td>
<tr style="outline: thin solid" ><th>--with-plugin-dir<th>--prefix<th>NETCDF_PLUGIN_INSTALL_DIR<th>NETCDF_PLUGIN_SEARCH_PATH
<tr style="outline: thin solid" ><td>undefined<td>undefined<td>undefined<td>PLATFORMDEFALT
<tr style="outline: thin solid" ><td>undefined<td>&lt;abspath-prefix&gt;<td>&lt;abspath-prefix&gt;/hdf5/lib/plugin<td>&lt;abspath-prefix&gt;/hdf5/lib/plugin&lt;SEP&gt;PLATFORMDEFALT
<tr style="outline: thin solid" ><td>&lt;abspath-plugins&gt;<td>N.A.<td>&lt;abspath-plugins&gt;<td>&lt;abspath-plugins&gt;&lt;SEP&gt;PLATFORMDEFALT
</table>

<table style="border:2px solid black;border-collapse:collapse">
<tr style="outline: thin solid" align="center"><td colspan="2">Table showing the computation of the initial global plugin path</td>
<tr style="outline: thin solid"><th>HDF5_PLUGIN_PATH<th>Initial global plugin path
<tr style="outline: thin solid"><td>undefined<td>NETCDF_PLUGIN_SEARCH_PATH
<tr style="outline: thin solid"><td>&lt;path1;...pathn&gt;<td>&lt;path1;...pathn&gt;
</table>
2024-10-18 19:23:59 -06:00
Dennis Heimbigner
ef425b9171 ckp 2024-09-30 14:39:48 -06:00
Manuel Reis
2b8f3af8c5 Clean up aws config test folder 2024-08-20 10:31:58 +02:00
Manuel Reis
a0bde790b4 Use EOF method to write configfiles in bash 2024-08-14 10:08:13 +02:00
Manuel Reis
dc6219236d Address PR#2969 suggestions 2024-08-13 10:46:48 +02:00
Manuel Reis
b05e95ec50 Parse AWS configuration with support for profile section 2024-08-07 17:55:49 +02:00
Manuel Reis
b010c57e10 Test inferred S3 url rebuild 2024-07-09 13:45:40 +02:00
مهدي شينون (Mehdi Chinoune)
c5c2d931cc CMake: Fix running tests on MinGW 2024-05-07 04:44:54 +01:00
Ward Fisher
e5b83cd70f
Merge pull request #2884 from ZedThree/silence-test-warnings
Fix warnings in tests and examples
2024-03-21 17:13:04 -06:00
Kyle Shores
8fd6dcb979 Replace ENABLE_S3 with NETCDF_ENABLE_S3 2024-03-18 15:54:15 -05:00
Kyle Shores
c5f24df396 Replace ENABLE_HDF5 with NETCDF_ENABLE_HDF5 2024-03-18 15:52:02 -05:00
Kyle Shores
dc4830a632 replacing BUILD_UTILITIES 2024-03-18 15:29:24 -05:00
Peter Hill
43871eb5a3
Fix warnings in unit_test 2024-03-12 16:13:41 +00:00
Peter Hill
d07dac918c
Silence conversion warnings from malloc arguments
Mostly just add an explicit cast when calling `malloc` and its
variants. Sometimes instead change the type of a local variable if
this would silence multiple warnings.
2023-11-24 18:20:52 +00:00
Ward Fisher
54102a3cea Update path in s3sdk shell script unit test. 2023-10-16 14:30:43 -06:00
Ward Fisher
3c013ce342 Merged in current state of https://github.com/Unidata/netcdf-c/pulls/2741 2023-09-29 15:05:43 -06:00
Dennis Heimbigner
df3636b959 Mitigate S3 test interference + Unlimited Dimensions in NCZarr
This PR started as an attempt to add unlimited dimensions to NCZarr.
It did that, but this exposed significant problems with test interference.
So this PR is mostly about fixing -- well mitigating anyway -- test
interference.

The problem of test interference is now documented in the document docs/internal.md.
The solutions implemented here are also describe in that document.
The solution is somewhat fragile but multiple cleanup mechanisms
are provided. Note that this feature requires that the
AWS command line utility must be installed.

## Unlimited Dimensions.
The existing NCZarr extensions to Zarr are modified to support unlimited dimensions.
NCzarr extends the Zarr meta-data for the ".zgroup" object to include netcdf-4 model extensions. This information is stored in ".zgroup" as dictionary named "_nczarr_group".
Inside "_nczarr_group", there is a key named "dims" that stores information about netcdf-4 named dimensions. The value of "dims" is a dictionary whose keys are the named dimensions. The value associated with each dimension name has one of two forms
Form 1 is a special case of form 2, and is kept for backward compatibility. Whenever a new file is written, it uses format 1 if possible, otherwise format 2.
* Form 1: An integer representing the size of the dimension, which is used for simple named dimensions.
* Form 2: A dictionary with the following keys and values"
   - "size" with an integer value representing the (current) size of the dimension.
   - "unlimited" with a value of either "1" or "0" to indicate if this dimension is an unlimited dimension.

For Unlimited dimensions, the size is initially zero, and as variables extend the length of that dimension, the size value for the dimension increases.
That dimension size is shared by all arrays referencing that dimension, so if one array extends an unlimited dimension, it is implicitly extended for all other arrays that reference that dimension.
This is the standard semantics for unlimited dimensions.

Adding unlimited dimensions required a number of other changes to the NCZarr code-base. These included the following.
* Did a partial refactor of the slice handling code in zwalk.c to clean it up.
* Added a number of tests for unlimited dimensions derived from the same test in nc_test4.
* Added several NCZarr specific unlimited tests; more are needed.
* Add test of endianness.

## Misc. Other Changes
* Modify libdispatch/ncs3sdk_aws.cpp to optionally support use of the
   AWS Transfer Utility mechanism. This is controlled by the
   ```#define TRANSFER```` command in that file. It defaults to being disabled.
* Parameterize both the standard Unidata S3 bucket (S3TESTBUCKET) and the netcdf-c test data prefix (S3TESTSUBTREE).
* Fixed an obscure memory leak in ncdump.
* Removed some obsolete unit testing code and test cases.
* Uncovered a bug in the netcdf-c handling of big-endian floats and doubles. Have not fixed yet. See tst_h5_endians.c.
* Renamed some nczarr_tests testcases to avoid name conflicts with nc_test4.
* Modify the semantics of zmap\#ncsmap_write to only allow total rewrite of objects.
* Modify the semantics of zodom to properly handle stride > 1.
* Add a truncate operation to the libnczarr zmap code.
2023-09-26 16:56:48 -06:00
Ward Fisher
b5bb7d8837 Correct a couple of typos. 2023-09-14 12:55:45 -06:00
Ward Fisher
571fa068eb Made some changes to spacing, also discovered an issue around specifying rpath on MacOSX when using configure. 2023-09-14 12:01:42 -06:00
Ward Fisher
543eeee980 A few tweaks for readability. 2023-09-14 11:20:10 -06:00
Ward Fisher
22ecb88e8d Turned off verbose debugging in test_s3sdk.c for now. 2023-08-31 10:31:06 -06:00
Ward Fisher
468e98f3b4 Making test cases more verbose, turning off s3-based interoperability tests TEMPORARILY. 2023-08-30 16:11:37 -06:00
Dennis Heimbigner
12ec5711d7 Fix some problems with Earthdata authorization.
re: Issue https://github.com/Unidata/netcdf-c/issues/2704

The issue reported problems accessing e.g. opendap.earthdata.nasa.gov,
which uses the authentication mechanisms of urs.earthdata.nasa.gov.
The file *docs/auth.md* describes how to setup the proper authorization
mechanisms for earthdata, but there turned out to be some bugs
in the code that prevented this from working.

## Primary Changes
* Add some clarification text to *auth.md*.
* Fix the process for loading and merging *.ncrc* and *.dodsrc* file to conform to documentation.
* Fix *NC_s3urlrebuild* so that non-S3 urls are passed through unchanged.
* Fix a bug in the .rc test *test_rcmerge.sh*.
2023-06-10 18:51:13 -06:00
Dennis Heimbigner
fb40a72b45 Improve performance of the nc_reclaim_data and nc_copy_data functions.
re: Issue https://github.com/Unidata/netcdf-c/issues/2685
re: PR https://github.com/Unidata/netcdf-c/pull/2179

As noted in PR https://github.com/Unidata/netcdf-c/pull/2179,
the old code did not allow for reclaiming instances of types,
nor for properly copying them. That PR provided new functions
capable of reclaiming/copying instances of arbitrary types.

However, as noted by Issue https://github.com/Unidata/netcdf-c/issues/2685, using these
most general functions resulted in a significant performance
degradation, even for common cases.

This PR attempts to mitigate the cost of using the general
reclaim/copy functions in two ways.

First, the previous functions operating at the top level by
using ncid and typeid arguments. These functions were augmented
with equivalent versions that used the netcdf-c library internal
data structures to allow direct access to needed information.
These new functions are used internally to the library.

The second mitigation involves optimizing the internal functions
by providing early tests for common cases. This avoids
unnecessary recursive function calls.

The overall result is a significant improvement in speed by a
factor of roughly twenty -- your mileage may vary. These
optimized functions are still not as fast as the original (more
limited) functions, but they are getting close. Additional optimizations are
possible. But the cost is a significant "uglification" of the
code that I deemed a step too far, at least for now.

## Misc. Changes
1. Added a test case to check the proper reclamation/copy of complex types.
2. Found and fixed some places where nc_reclaim/copy should have been used.
3. Replaced, in the netcdf-c library, (almost all) occurrences of nc_reclaim_copy with calls to NC_reclaim/copy. This plus the optimizations is the primary speed-up mechanism.
4. In DAP4, the metadata is held in a substrate in-memory file; this required some changes so that the reclaim/copy code accessed that substrate dispatcher rather than the DAP4 dispatcher.
5. Re-factored and isolated the code that computes if a type is (transitively) variable-sized or not.
6. Clean up the reclamation code in ncgen; adding the use of nc_reclaim exposed some memory problems.
2023-05-20 17:11:25 -06:00
Dennis Heimbigner
98477b9f25 ## Addendum [5/9/23]
It turns out that attempting to test S3 using a github action secret is a very complex process. So, this was disabled for github actions. However, a new *run_tests_s3.yml* action file was added that will eventually encapsulate S3 testing.
2023-05-09 21:13:49 -06:00
Dennis Heimbigner
681abc3fb1 s3-off 2023-04-30 18:41:31 -06:00
Dennis Heimbigner
6eac55dc44 debug11 2023-04-29 21:01:05 -06:00
Dennis Heimbigner
a97cabfb12 debug10 2023-04-29 20:51:46 -06:00
Dennis Heimbigner
ff6b6a72d1 debug7 2023-04-29 20:40:21 -06:00
Dennis Heimbigner
5be7088c9e debug6 2023-04-29 20:36:18 -06:00
Dennis Heimbigner
20065682bb debug1 2023-04-28 14:30:48 -06:00
Dennis Heimbigner
aa82e1b4cb Merge branch 's3update.dmh' of https://github.com/DennisHeimbigner/netcdf-c into s3update.dmh 2023-04-28 14:05:14 -06:00
Dennis Heimbigner
62f8d31415 profile1 2023-04-28 14:05:06 -06:00
Dennis Heimbigner
7e5c4ebe66 debug1 2023-04-27 20:01:39 -06:00
Dennis Heimbigner
7939ec559f forward1 2023-04-27 19:52:03 -06:00
Dennis Heimbigner
44441af5bb clean1 2023-04-27 19:46:34 -06:00
Dennis Heimbigner
5d5ff73847 segv2 2023-04-27 15:26:34 -06:00
Dennis Heimbigner
c8d14cb029 gdb1 2023-04-27 13:32:02 -06:00
Dennis Heimbigner
6707508a26 list1 2023-04-27 12:28:14 -06:00
Dennis Heimbigner
938dcd913e revamp1 2023-04-27 11:10:10 -06:00
Dennis Heimbigner
91473c231b ga2 2023-04-26 20:48:50 -06:00
Dennis Heimbigner
a77bdc0a91 ga1 2023-04-26 20:39:48 -06:00
Dennis Heimbigner
076aad4174 val10 2023-04-26 20:25:43 -06:00
Dennis Heimbigner
aeaf9e4bec notrace 2023-04-26 14:16:22 -06:00
Dennis Heimbigner
b19bdb6bba vg5 2023-04-26 14:05:23 -06:00
Dennis Heimbigner
f584296472 ga1 2023-04-26 13:51:17 -06:00
Dennis Heimbigner
61f42a4404 valg2 2023-04-26 13:31:36 -06:00
Dennis Heimbigner
8ee9453043 valg2 2023-04-26 13:20:54 -06:00
Dennis Heimbigner
5dd237246f fault1 2023-04-26 13:03:21 -06:00
Dennis Heimbigner
3eaa4bbb2c valgrind1 2023-04-26 12:38:11 -06:00