Compare commits

..

2 Commits

Author SHA1 Message Date
Bruno Postle 99cfa2bd56 Use version preprocessor guards for RocksDB unique_ptr API, retain unique_ptr internally 2026-06-05 09:26:11 +01:00
Bruno Postle 8402dfd304 Support RocksDB shared library and new unique_ptr DB::Open API
Some distributions (e.g. Fedora) ship only a shared RocksDB that exports
RocksDB::rocksdb-shared rather than RocksDB::rocksdb. The CMake target
selection now falls back to the shared target when the static one is absent.

Newer RocksDB also changed DB::Open and DB::OpenForReadOnly to take
std::unique_ptr<DB>* instead of DB**. IfcFile.cpp uses SFINAE tag dispatch
to build against both old and new APIs without version detection.
2026-06-04 22:52:41 +01:00
18 changed files with 41 additions and 54 deletions
+7 -3
View File
@@ -258,10 +258,14 @@ if(WITH_ROCKSDB)
set(ROCKSDB_LIBRARIES "IFCOPENSHELL_RocksDB")
target_compile_definitions(IFCOPENSHELL_RocksDB INTERFACE IFOPSH_WITH_ROCKSDB)
set(SWIG_DEFINES ${SWIG_DEFINES} -DIFOPSH_WITH_ROCKSDB)
# Shared binaries for `rocksdb` only support limited API (only `c.h`), but we use `db.h` API.
# So rocksdb supported only as a static library.
# See https://github.com/facebook/rocksdb/issues/981.
target_link_libraries(IFCOPENSHELL_RocksDB INTERFACE RocksDB::rocksdb)
if(TARGET RocksDB::rocksdb)
target_link_libraries(IFCOPENSHELL_RocksDB INTERFACE RocksDB::rocksdb)
elseif(TARGET RocksDB::rocksdb-shared)
target_link_libraries(IFCOPENSHELL_RocksDB INTERFACE RocksDB::rocksdb-shared)
else()
message(FATAL_ERROR "RocksDB found but neither RocksDB::rocksdb nor RocksDB::rocksdb-shared target exists")
endif()
if(WITH_ZSTD)
# @todo do we actually need the zstd include dir or rather just pass
@@ -48,7 +48,6 @@
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <cstdint>
#include <BRepExtrema_TriangleSet.hxx>
#include <BRepLProp_SLProps.hxx>
#include <BVH_BinaryTree.hxx>
@@ -1,7 +1,5 @@
#include "clash_utils.h"
#include <cassert>
#include <cstdint>
#include <cfloat>
#define GU_CULLING_EPSILON_RAY_TRIANGLE FLT_EPSILON*FLT_EPSILON
#define PX_MAX_F32 3.4028234663852885981170418348452e+38F
-1
View File
@@ -7,7 +7,6 @@
#include "../../ifcparse/IfcLogger.h"
#include <mutex>
#include <cstdint>
#define INCLUDE_SCHEMA(x) STRINGIFY(../../ifcparse/x.h)
#include INCLUDE_SCHEMA(IfcSchema)
+7 -14
View File
@@ -17,13 +17,6 @@
#include <tuple>
#include <exception>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <array>
#include <limits>
#include <functional>
#include <algorithm>
#include <stdexcept>
#ifndef TAXONOMY_USE_UNIQUE_PTR
#ifndef TAXONOMY_USE_NAKED_PTR
@@ -1632,19 +1625,19 @@ typedef item const* ptr;
// @todo Sad... now that we have templated collection members,
// we can't generally use collection_base anymore as a cast target.
if (auto s = std::dynamic_pointer_cast<taxonomy::collection>(i)) {
ifcopenshell::geometry::visit<taxonomy::collection>(s, fn);
visit<taxonomy::collection>(s, fn);
} else if (auto s = std::dynamic_pointer_cast<taxonomy::loop>(i)) {
ifcopenshell::geometry::visit<taxonomy::loop>(s, fn);
visit<taxonomy::loop>(s, fn);
} else if (auto s = std::dynamic_pointer_cast<taxonomy::face>(i)) {
ifcopenshell::geometry::visit<taxonomy::face>(s, fn);
visit<taxonomy::face>(s, fn);
} else if (auto s = std::dynamic_pointer_cast<taxonomy::shell>(i)) {
ifcopenshell::geometry::visit<taxonomy::shell>(s, fn);
visit<taxonomy::shell>(s, fn);
} else if (auto s = std::dynamic_pointer_cast<taxonomy::solid>(i)) {
ifcopenshell::geometry::visit<taxonomy::solid>(s, fn);
visit<taxonomy::solid>(s, fn);
} else if (auto s = std::dynamic_pointer_cast<taxonomy::loft>(i)) {
ifcopenshell::geometry::visit<taxonomy::loft>(s, fn);
visit<taxonomy::loft>(s, fn);
} else if (auto s = std::dynamic_pointer_cast<taxonomy::boolean_result>(i)) {
ifcopenshell::geometry::visit<taxonomy::boolean_result>(s, fn);
visit<taxonomy::boolean_result>(s, fn);
}
else {
fn(i);
-1
View File
@@ -27,7 +27,6 @@
#include "utils.h"
#include <atomic>
#include <cstdint>
#include <boost/shared_ptr.hpp>
class aggregate_of_instance;
+1 -1
View File
@@ -201,7 +201,7 @@ namespace {
if (character >= 0x20 && character <= 0x7e) {
stream.put((char)character);
} else {
stream << "\\u" << static_cast<uint32_t>(character);
stream << "\\u" << character;
}
});
return stream.str();
-3
View File
@@ -36,9 +36,6 @@
#endif
#include <cstdint>
#include <cstring>
#include <boost/optional.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/logic/tribool.hpp>
+24 -9
View File
@@ -4,9 +4,12 @@
#ifdef IFOPSH_WITH_ROCKSDB
#include <rocksdb/table.h>
#include <rocksdb/convenience.h>
#include <rocksdb/version.h>
#endif
#include <fstream>
#include <memory>
#include <utility>
#include <sys/types.h>
#include <sys/stat.h>
@@ -410,10 +413,8 @@ IfcUtil::IfcBaseClass* IfcParse::impl::rocks_db_file_storage::assert_existance(s
}
namespace {
rocksdb::DB* init_db(const std::string& filepath, bool readonly) {
rocksdb::DB* db = nullptr;
std::unique_ptr<rocksdb::DB> init_db(const std::string& filepath, bool readonly) {
#ifdef IFOPSH_WITH_ROCKSDB
rocksdb::Options options;
// options.disable_auto_compactions = true;
options.create_if_missing = true;
@@ -445,16 +446,31 @@ namespace {
options.table_factory.reset(rocksdb::NewBlockBasedTableFactory(tbo));
rocksdb::Status status;
std::unique_ptr<rocksdb::DB> db;
if (readonly) {
#if ROCKSDB_MAJOR > 9 || (ROCKSDB_MAJOR == 9 && ROCKSDB_MINOR >= 11)
status = rocksdb::DB::OpenForReadOnly(options, filepath, &db);
#else
rocksdb::DB* raw = nullptr;
status = rocksdb::DB::OpenForReadOnly(options, filepath, &raw);
db.reset(raw);
#endif
} else {
#if ROCKSDB_MAJOR > 9 || (ROCKSDB_MAJOR == 9 && ROCKSDB_MINOR >= 11)
status = rocksdb::DB::Open(options, filepath, &db);
#else
rocksdb::DB* raw = nullptr;
status = rocksdb::DB::Open(options, filepath, &raw);
db.reset(raw);
#endif
}
if (!status.ok()) {
return nullptr;
}
#endif // IFOPSH_WITH_ROCKSDB#
return db;
#else
return nullptr;
#endif
}
}
@@ -463,12 +479,12 @@ IfcParse::impl::rocks_db_file_storage::rocks_db_file_storage(const std::string&
: file(ffile)
, db(init_db(filepath, readonly))
// @todo streaming serializer does not populate the byguid map
, byguid_internal_(db, "g|")
, byguid_internal_(db.get(), "g|")
, byguid_(&byguid_internal_, [this](size_t v) { return assert_existance(v, entityinstance_ref); }, [](IfcUtil::IfcBaseClass* v) { return v->identity(); })
, instance_ids_(db, "i|")
, instance_ids_(db.get(), "i|")
, instance_by_name_(&instance_ids_, [this](size_t v) { return assert_existance(v, entityinstance_ref); })
, bytype_(db, "t|")
, byref_excl_(db, "v|")
, bytype_(db.get(), "t|")
, byref_excl_(db.get(), "v|")
// @todo by_identity is probably not correct here, this mapping is Name -> Identity, so Fn should have access to full pair?
// , byidentity_(&byid_, [this](size_t v) { return assert_existance(v, by_identity); }, [](IfcUtil::IfcBaseClass* v) { return v->identity(); })
{
@@ -491,7 +507,6 @@ IfcParse::impl::rocks_db_file_storage::~rocks_db_file_storage()
assert(s.ok());
db->Close();
delete db;
#endif
}
-1
View File
@@ -34,7 +34,6 @@
#include <boost/circular_buffer.hpp>
#include <iterator>
#include <map>
#include <cstdint>
#ifdef IFOPSH_WITH_ROCKSDB
#include <rocksdb/merge_operator.h>
-2
View File
@@ -25,9 +25,7 @@
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <cctype>
#include <cstdint>
#include <iterator>
#include <memory>
#include <string>
#include <vector>
-1
View File
@@ -26,7 +26,6 @@
#include <boost/shared_ptr.hpp>
#include <set>
#include <vector>
#include <algorithm>
namespace IfcParse {
class declaration;
-2
View File
@@ -30,8 +30,6 @@
#include <utility>
#include <iterator>
#include <cstddef>
#include <cstdint>
#include <cstring>
template <typename T>
struct is_std_tuple : std::false_type {};
+2 -3
View File
@@ -25,12 +25,11 @@ namespace rocksdb {
#include <variant>
#include <iterator>
#include <cstdint>
#include <cstring>
#include <type_traits>
#include <iostream>
#include <vector>
#include <list>
#include <memory>
#ifndef SWIG
@@ -308,7 +307,7 @@ namespace IfcParse {
class IFC_PARSE_API rocks_db_file_storage {
public:
rocksdb::DB* db;
std::unique_ptr<rocksdb::DB> db;
rocksdb::WriteOptions wopts;
rocksdb::ReadOptions ropts;
IfcParse::IfcFile* file;
-4
View File
@@ -33,10 +33,6 @@ variant - which is the maximum size of its constituents - is reduced.
#include <utility>
#include <memory>
#include <tuple>
#include <cstdint>
#include <cstring>
#include <cstddef>
#include <limits>
#include "IfcException.h"
-2
View File
@@ -23,8 +23,6 @@
#include "../ifcparse/utils.h"
#include <cstdint>
#ifdef WITH_PROJ
#include <proj.h>
#endif
-1
View File
@@ -34,7 +34,6 @@
#include <numeric>
#include <functional>
#include <cmath>
#include <cstdint>
#ifdef USE_BINARY
#define write_shape write_binary
-3
View File
@@ -4,9 +4,6 @@
#include <rocksdb/options.h>
#include <cstdint>
#include <cstring>
#include "../ifcparse/IfcLogger.h"
RocksDbSerializer::RocksDbSerializer(IfcParse::IfcFile* file, const std::string& rocksdb_filename)