From 5c53b9008f17c0aad62f2e0d9d69100b32823159 Mon Sep 17 00:00:00 2001 From: Akanksha Mahajan Date: Fri, 11 Feb 2022 10:22:22 -0800 Subject: [PATCH] Fix failure in c_test (#9547) Summary: When tests are run with TMPD, c_test may fail because TMPD is not created by the test. It results in IO error: No such file or directory: While mkdir if missing: /tmp/rocksdb_test_tmp/rocksdb_c_test-0: No such file or directory Pull Request resolved: https://github.com/facebook/rocksdb/pull/9547 Test Plan: make -j32 c_test; TEST_TMPDIR=/tmp/rocksdb_test ./c_test Reviewed By: riversand963 Differential Revision: D34173298 Pulled By: akankshamahajan15 fbshipit-source-id: 5b5a01f5b842c2487b05b0708c8e9532241db7f8 --- HISTORY.md | 1 + db/c.cc | 5 +++++ db/c_test.c | 4 ++++ include/rocksdb/c.h | 2 ++ 4 files changed, 12 insertions(+) diff --git a/HISTORY.md b/HISTORY.md index 5e510ee2e..4bea93fb9 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -70,6 +70,7 @@ * Introduced an option `BlockBasedTableBuilder::detect_filter_construct_corruption` for detecting corruption during Bloom Filter (format_version >= 5) and Ribbon Filter construction. * Improved the SstDumpTool to read the comparator from table properties and use it to read the SST File. * Extended the column family statistics in the info log so the total amount of garbage in the blob files and the blob file space amplification factor are also logged. Also exposed the blob file space amp via the `rocksdb.blob-stats` DB property. +* Introduced the API rocksdb_create_dir_if_missing in c.h that calls underlying file system's CreateDirIfMissing API to create the directory. ## 6.29.0 (01/21/2022) Note: The next release will be major release 7.0. See https://github.com/facebook/rocksdb/issues/9390 for more info. diff --git a/db/c.cc b/db/c.cc index aa48708d6..c6f23adf2 100644 --- a/db/c.cc +++ b/db/c.cc @@ -4321,6 +4321,11 @@ rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create( return writer; } +void rocksdb_create_dir_if_missing(rocksdb_env_t* env, const char* path, + char** errptr) { + SaveError(errptr, env->rep->CreateDirIfMissing(std::string(path))); +} + rocksdb_sstfilewriter_t* rocksdb_sstfilewriter_create_with_comparator( const rocksdb_envoptions_t* env, const rocksdb_options_t* io_options, const rocksdb_comparator_t* /*comparator*/) { diff --git a/db/c_test.c b/db/c_test.c index eaff94f19..8b224e049 100644 --- a/db/c_test.c +++ b/db/c_test.c @@ -447,6 +447,10 @@ int main(int argc, char** argv) { cmp = rocksdb_comparator_create(NULL, CmpDestroy, CmpCompare, CmpName); dbpath = rocksdb_dbpath_create(dbpathname, 1024 * 1024); env = rocksdb_create_default_env(); + + rocksdb_create_dir_if_missing(env, GetTempDir(), &err); + CheckNoError(err); + cache = rocksdb_cache_create_lru(100000); options = rocksdb_options_create(); diff --git a/include/rocksdb/c.h b/include/rocksdb/c.h index f0d32bd41..9d9e999ca 100644 --- a/include/rocksdb/c.h +++ b/include/rocksdb/c.h @@ -1818,6 +1818,8 @@ extern ROCKSDB_LIBRARY_API rocksdb_envoptions_t* rocksdb_envoptions_create( void); extern ROCKSDB_LIBRARY_API void rocksdb_envoptions_destroy( rocksdb_envoptions_t* opt); +extern ROCKSDB_LIBRARY_API void rocksdb_create_dir_if_missing( + rocksdb_env_t* env, const char* path, char** errptr); /* SstFile */