forked from Unidata/netcdf-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix major bug in the NCZarr cache management
re: PR Unidata#2734 re: Issue Unidata#2733 As a result of an investigation by https://github.com/uweschulzweida, I discovered a significant bug in the NCZarr cache management. This PR extends the above PR to fix that bug. ## Change Overview * Insert extra checks for cache overflow. * Added test cases contingent on the --enable-large-file-tests option. * The Columbia server is down, so it has been temporarily disabled.
- Loading branch information
1 parent
032b910
commit 9094d25
Showing
8 changed files
with
296 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/bin/sh | ||
|
||
if test "x$srcdir" = x ; then srcdir=`pwd`; fi | ||
. ../test_common.sh | ||
|
||
. "$top_srcdir/nczarr_test/test_nczarr.sh" | ||
|
||
set -e | ||
|
||
s3isolate "testdir_cachtest" | ||
THISDIR=`pwd` | ||
cd $ISOPATH | ||
|
||
# This shell script tests support for the NC_STRING type | ||
|
||
testcase() { | ||
zext=$1 | ||
|
||
echo "*** Test: cache operation" | ||
|
||
# Get pure zarr args | ||
fileargs tmp_scalar_zarr "mode=zarr,$zext" | ||
zarrurl="$fileurl" | ||
zarrfile="$file" | ||
|
||
# setup | ||
deletemap $zext $zarrfile | ||
|
||
echo "*** write cache" | ||
${execdir}/test_writecaching | ||
|
||
echo "*** read cache" | ||
${execdir}/test_readcaching | ||
} | ||
|
||
testcase file | ||
if test "x$FEATURE_NCZARR_ZIP" = xyes ; then testcase zip; fi | ||
if test "x$FEATURE_S3TESTS" = xyes ; then testcase s3; fi | ||
|
||
if test "x$FEATURE_S3TESTS" = xyes ; then s3sdkdelete "/${S3ISOPATH}" ; fi # Cleanup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <sys/resource.h> | ||
|
||
#if defined(__APPLE__) && defined(__MACH__) | ||
#include <mach/mach.h> | ||
#endif | ||
|
||
#include "netcdf.h" | ||
|
||
#define filename "file://tmp_cachetest.zarr#mode=zarr,file" | ||
#define chunkSize (size_t)(1<<17) /* 128k */ | ||
#define numCells (size_t)(50 * chunkSize) | ||
#define numSteps (size_t)360 | ||
|
||
static float var[numCells]; | ||
|
||
size_t getPeakRSS(void) | ||
{ | ||
struct rusage rusage; | ||
getrusage( RUSAGE_SELF, &rusage ); | ||
#if defined(__APPLE__) && defined(__MACH__) | ||
return (size_t)rusage.ru_maxrss; | ||
#else | ||
return (size_t)(rusage.ru_maxrss * 1024L); | ||
#endif | ||
} | ||
|
||
static void | ||
nce(int istat) | ||
{ | ||
if (istat != NC_NOERR) | ||
{ | ||
fprintf(stderr, "%s\n", nc_strerror(istat)); | ||
exit(-1); | ||
} | ||
} | ||
|
||
int | ||
main(void) | ||
{ | ||
printf("read: chunkSize=%zu, numCells=%zu, numSteps=%zu, filename=%s\n", chunkSize, numCells, numSteps, filename); | ||
|
||
int ncId; | ||
nce(nc_open(filename, NC_NOWRITE, &ncId)); | ||
|
||
int varId; | ||
nce(nc_inq_varid(ncId, "var", &varId)); | ||
|
||
size_t size, nelems; | ||
float preemption; | ||
nce(nc_get_var_chunk_cache(ncId, varId, &size, &nelems, &preemption)); | ||
printf("default chunk cache: size=%zu, nelems=%zu, preemption=%g\n", size, nelems, preemption); | ||
size = 4 * numCells; // one float field at one time step | ||
nelems = 1000; | ||
preemption = 0.5; | ||
nce(nc_set_var_chunk_cache(ncId, varId, size, nelems, preemption)); | ||
printf("set chunk cache: size=%zu, nelems=%zu, preemption=%g\n", size, nelems, preemption); | ||
|
||
{ | ||
for (size_t i = 0; i < numCells; ++i) var[i] = 0.0f; | ||
for (size_t i = 0; i < numSteps; ++i) | ||
{ | ||
size_t start[2], count[2]; | ||
start[0] = i; start[1] = 0; | ||
count[0] = 1; count[1] = numCells; | ||
nce(nc_get_vara_float(ncId, varId, start, count, var)); | ||
} | ||
} | ||
|
||
nce(nc_close(ncId)); | ||
|
||
{ | ||
size_t mbused = getPeakRSS() / (1024 * 1024); | ||
printf("Max mem: %zu MB\n", mbused); | ||
if(mbused > 100) { | ||
fprintf(stderr,"*** Failed: used: %luMB expected: < 100MB\n",mbused); | ||
return (1); | ||
} | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.