ports/contrib (3.6): leveldb: initial import
commit 2050e046f12d598be040e032ddf18fd0fbada764 Author: Danny Rawlins <contact@romster.me> Date: Sun Oct 31 12:06:22 2021 +1100 leveldb: initial import diff --git a/leveldb/.footprint b/leveldb/.footprint new file mode 100644 index 000000000..cb017bf7a --- /dev/null +++ b/leveldb/.footprint @@ -0,0 +1,30 @@ +drwxr-xr-x root/root usr/ +drwxr-xr-x root/root usr/include/ +drwxr-xr-x root/root usr/include/leveldb/ +-rw-r--r-- root/root usr/include/leveldb/c.h +-rw-r--r-- root/root usr/include/leveldb/cache.h +-rw-r--r-- root/root usr/include/leveldb/comparator.h +-rw-r--r-- root/root usr/include/leveldb/db.h +-rw-r--r-- root/root usr/include/leveldb/dumpfile.h +-rw-r--r-- root/root usr/include/leveldb/env.h +-rw-r--r-- root/root usr/include/leveldb/export.h +-rw-r--r-- root/root usr/include/leveldb/filter_policy.h +-rw-r--r-- root/root usr/include/leveldb/iterator.h +-rw-r--r-- root/root usr/include/leveldb/options.h +-rw-r--r-- root/root usr/include/leveldb/slice.h +-rw-r--r-- root/root usr/include/leveldb/status.h +-rw-r--r-- root/root usr/include/leveldb/table.h +-rw-r--r-- root/root usr/include/leveldb/table_builder.h +-rw-r--r-- root/root usr/include/leveldb/write_batch.h +drwxr-xr-x root/root usr/lib/ +drwxr-xr-x root/root usr/lib/cmake/ +drwxr-xr-x root/root usr/lib/cmake/leveldb/ +-rw-r--r-- root/root usr/lib/cmake/leveldb/leveldbConfig.cmake +-rw-r--r-- root/root usr/lib/cmake/leveldb/leveldbConfigVersion.cmake +-rw-r--r-- root/root usr/lib/cmake/leveldb/leveldbTargets-release.cmake +-rw-r--r-- root/root usr/lib/cmake/leveldb/leveldbTargets.cmake +lrwxrwxrwx root/root usr/lib/libleveldb.so -> libleveldb.so.1 +lrwxrwxrwx root/root usr/lib/libleveldb.so.1 -> libleveldb.so.1.23.0 +-rwxr-xr-x root/root usr/lib/libleveldb.so.1.23.0 +drwxr-xr-x root/root usr/lib/pkgconfig/ +-rw-r--r-- root/root usr/lib/pkgconfig/leveldb.pc diff --git a/leveldb/.signature b/leveldb/.signature new file mode 100644 index 000000000..f34a2d099 --- /dev/null +++ b/leveldb/.signature @@ -0,0 +1,11 @@ +untrusted comment: verify with /etc/ports/contrib.pub +RWSagIOpLGJF39EKvHFJ/JaLmdcZnmlncCWhybCpGiBCNCcBAVpzdpAHveKVnGc2sAWhY1WaYW/DxMlEf+C1IoZ0spkI4rJnhg8= +SHA256 (Pkgfile) = 6edb1a1a83d80b560ba816b875fa4565264fa9d3a678e7511ba8deeebdc48e21 +SHA256 (.footprint) = a2336496b573191a8d86d0b913ceabd56246479ef82ef3c332a96c83b5498e5e +SHA256 (leveldb-1.23.tar.gz) = 9a37f8a6174f09bd622bc723b55881dc541cd50747cbd08831c2a82d620f6d76 +SHA256 (0001-Allow-leveldbjni-build.patch) = b4d2ac085822d1ba1bc0c741aab880f98422befa0294718446683526407218b1 +SHA256 (0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch) = e3b396b472a646a5925decad31d907b6007384af0e11660e7ee926f82ec663c7 +SHA256 (0003-allow-Get-calls-to-avoid-copies-into-std-string.patch) = 6bfed9209e624abdccff28d526a8e6a5233219c4f3f59952767b8ea4f3276d14 +SHA256 (0004-bloom_test-failure-on-big-endian-archs.patch) = 0db049bd24a3e5dfb59af921ffd10a0b80c479d977f7a2a7725c44f12a5f800d +SHA256 (0005-Restore-soname-versioning-with-CMake-build.patch) = a051cb72c6a6dfd35242122f53dc548ef7cd7d83d6e8942782e7f4f7845b32dc +SHA256 (0006-revert-no-rtti.patch) = 6e6a0f67429453ba772816dfbe4ac89b113de45dee8b767ba3b6ce9ccbe57fde diff --git a/leveldb/0001-Allow-leveldbjni-build.patch b/leveldb/0001-Allow-leveldbjni-build.patch new file mode 100644 index 000000000..e7b2f9a50 --- /dev/null +++ b/leveldb/0001-Allow-leveldbjni-build.patch @@ -0,0 +1,17 @@ +From: Hiram Chirino <chirino@gmail.com> +Date: Fri, 5 Jul 2013 18:32:28 +0400 +Subject: [PATCH] Allow leveldbjni build + + +diff --git a/include/leveldb/slice.h b/include/leveldb/slice.h +index 2df417d..1af5635 100644 +--- a/include/leveldb/slice.h ++++ b/include/leveldb/slice.h +@@ -86,7 +86,6 @@ class LEVELDB_EXPORT Slice { + return ((size_ >= x.size_) && (memcmp(data_, x.data_, x.size_) == 0)); + } + +- private: + const char* data_; + size_t size_; + }; diff --git a/leveldb/0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch b/leveldb/0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch new file mode 100644 index 000000000..88237082e --- /dev/null +++ b/leveldb/0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch @@ -0,0 +1,118 @@ +From: Hiram Chirino <hiram@hiramchirino.com> +Date: Tue, 30 Oct 2012 16:56:52 -0400 +Subject: [PATCH] Added a DB:SuspendCompations() and DB:ResumeCompactions() + methods. Fixes issue #184 + +https://code.google.com/p/leveldb/issues/detail?id=184 + +diff --git a/db/db_impl.cc b/db/db_impl.cc +index 1a4e459..ae7b96d 100644 +--- a/db/db_impl.cc ++++ b/db/db_impl.cc +@@ -135,6 +135,9 @@ DBImpl::DBImpl(const Options& raw_options, const std::string& dbname) + table_cache_(new TableCache(dbname_, options_, TableCacheSize(options_))), + db_lock_(nullptr), + shutting_down_(false), ++ suspend_cv(&suspend_mutex), ++ suspend_count(0), ++ suspended(false), + background_work_finished_signal_(&mutex_), + mem_(nullptr), + imm_(nullptr), +@@ -1464,6 +1467,39 @@ void DBImpl::GetApproximateSizes(const Range* range, int n, uint64_t* sizes) { + v->Unref(); + } + ++void DBImpl::SuspendCompactions() { ++ MutexLock l(& suspend_mutex); ++ env_->Schedule(&SuspendWork, this); ++ suspend_count++; ++ while( !suspended ) { ++ suspend_cv.Wait(); ++ } ++} ++void DBImpl::SuspendWork(void* db) { ++ reinterpret_cast<DBImpl*>(db)->SuspendCallback(); ++} ++void DBImpl::SuspendCallback() { ++ MutexLock l(&suspend_mutex); ++ Log(options_.info_log, "Compactions suspended"); ++ suspended = true; ++ suspend_cv.SignalAll(); ++ while( suspend_count > 0 ) { ++ suspend_cv.Wait(); ++ } ++ suspended = false; ++ suspend_cv.SignalAll(); ++ Log(options_.info_log, "Compactions resumed"); ++} ++void DBImpl::ResumeCompactions() { ++ MutexLock l(&suspend_mutex); ++ suspend_count--; ++ suspend_cv.SignalAll(); ++ while( suspended ) { ++ suspend_cv.Wait(); ++ } ++} ++ ++ + // Default implementations of convenience methods that subclasses of DB + // can call if they wish + Status DB::Put(const WriteOptions& opt, const Slice& key, const Slice& value) { +diff --git a/db/db_impl.h b/db/db_impl.h +index c7b0172..d955c2a 100644 +--- a/db/db_impl.h ++++ b/db/db_impl.h +@@ -48,6 +48,8 @@ class DBImpl : public DB { + bool GetProperty(const Slice& property, std::string* value) override; + void GetApproximateSizes(const Range* range, int n, uint64_t* sizes) override; + void CompactRange(const Slice* begin, const Slice* end) override; ++ void SuspendCompactions() override; ++ void ResumeCompactions() override; + + // Extra methods (for testing) that are not in the public DB interface + +@@ -170,6 +172,13 @@ class DBImpl : public DB { + // Lock over the persistent DB state. Non-null iff successfully acquired. + FileLock* db_lock_; + ++ port::Mutex suspend_mutex; ++ port::CondVar suspend_cv; ++ int suspend_count; ++ bool suspended; ++ static void SuspendWork(void* db); ++ void SuspendCallback(); ++ + // State below is protected by mutex_ + port::Mutex mutex_; + std::atomic<bool> shutting_down_; +diff --git a/db/db_test.cc b/db/db_test.cc +index 908b41d..2e65370 100644 +--- a/db/db_test.cc ++++ b/db/db_test.cc +@@ -2051,6 +2051,8 @@ class ModelDB : public DB { + }; + + explicit ModelDB(const Options& options) : options_(options) {} ++ virtual void SuspendCompactions() override {} ++ virtual void ResumeCompactions() override {} + ~ModelDB() override = default; + Status Put(const WriteOptions& o, const Slice& k, const Slice& v) override { + return DB::Put(o, k, v); +diff --git a/include/leveldb/db.h b/include/leveldb/db.h +index a13d147..61c29c0 100644 +--- a/include/leveldb/db.h ++++ b/include/leveldb/db.h +@@ -145,6 +145,12 @@ class LEVELDB_EXPORT DB { + // Therefore the following call will compact the entire database: + // db->CompactRange(nullptr, nullptr); + virtual void CompactRange(const Slice* begin, const Slice* end) = 0; ++ ++ // Suspends the background compaction thread. This methods ++ // returns once suspended. ++ virtual void SuspendCompactions() = 0; ++ // Resumes a suspended background compation thread. ++ virtual void ResumeCompactions() = 0; + }; + + // Destroy the contents of the specified database. diff --git a/leveldb/0003-allow-Get-calls-to-avoid-copies-into-std-string.patch b/leveldb/0003-allow-Get-calls-to-avoid-copies-into-std-string.patch new file mode 100644 index 000000000..498f81e3c --- /dev/null +++ b/leveldb/0003-allow-Get-calls-to-avoid-copies-into-std-string.patch @@ -0,0 +1,165 @@ +From: Steve Vinoski <vinoski@ieee.org> +Date: Thu, 20 Dec 2012 16:14:11 -0500 +Subject: [PATCH] allow Get() calls to avoid copies into std::string + +Add a new abstract base class leveldb::Value that applications can easily +derive from to supply their own memory management for values retrieved via +Get(). Add an internal class derived from Value that provides std::string +management to preserve backward compatibility. Overload DBImpl::Get() to +accept a Value*, and to preserve backward compatibility also keep the +original version taking a std::string*. + +diff --git a/db/db_impl.cc b/db/db_impl.cc +index ae7b96d..5c3a05c 100644 +--- a/db/db_impl.cc ++++ b/db/db_impl.cc +@@ -85,6 +85,22 @@ struct DBImpl::CompactionState { + uint64_t total_bytes; + }; + ++Value::~Value() {} ++ ++class StringValue : public Value { ++ public: ++ explicit StringValue(std::string& val) : value_(val) {} ++ ~StringValue() {} ++ ++ StringValue& assign(const char* data, size_t size) { ++ value_.assign(data, size); ++ return *this; ++ } ++ ++ private: ++ std::string& value_; ++}; ++ + // Fix user-supplied options to be reasonable + template <class T, class V> + static void ClipToRange(T* ptr, V minvalue, V maxvalue) { +@@ -1117,6 +1133,13 @@ int64_t DBImpl::TEST_MaxNextLevelOverlappingBytes() { + + Status DBImpl::Get(const ReadOptions& options, const Slice& key, + std::string* value) { ++ StringValue stringvalue(*value); ++ return DBImpl::Get(options, key, &stringvalue); ++} ++ ++Status DBImpl::Get(const ReadOptions& options, ++ const Slice& key, ++ Value* value) { + Status s; + MutexLock l(&mutex_); + SequenceNumber snapshot; +diff --git a/db/db_impl.h b/db/db_impl.h +index d955c2a..3127110 100644 +--- a/db/db_impl.h ++++ b/db/db_impl.h +@@ -42,6 +42,9 @@ class DBImpl : public DB { + Status Write(const WriteOptions& options, WriteBatch* updates) override; + Status Get(const ReadOptions& options, const Slice& key, + std::string* value) override; ++ virtual Status Get(const ReadOptions& options, ++ const Slice& key, ++ Value* value); + Iterator* NewIterator(const ReadOptions&) override; + const Snapshot* GetSnapshot() override; + void ReleaseSnapshot(const Snapshot* snapshot) override; +diff --git a/db/db_test.cc b/db/db_test.cc +index 2e65370..db778d9 100644 +--- a/db/db_test.cc ++++ b/db/db_test.cc +@@ -2065,6 +2065,11 @@ class ModelDB : public DB { + assert(false); // Not implemented + return Status::NotFound(key); + } ++ Status Get(const ReadOptions& options, ++ const Slice& key, Value* value) override { ++ assert(false); // Not implemented ++ return Status::NotFound(key); ++ } + Iterator* NewIterator(const ReadOptions& options) override { + if (options.snapshot == nullptr) { + KVMap* saved = new KVMap; +diff --git a/db/memtable.cc b/db/memtable.cc +index f42774d..4689e2d 100644 +--- a/db/memtable.cc ++++ b/db/memtable.cc +@@ -98,7 +98,7 @@ void MemTable::Add(SequenceNumber s, ValueType type, const Slice& key, + table_.Insert(buf); + } + +-bool MemTable::Get(const LookupKey& key, std::string* value, Status* s) { ++bool MemTable::Get(const LookupKey& key, Value* value, Status* s) { + Slice memkey = key.memtable_key(); + Table::Iterator iter(&table_); + iter.Seek(memkey.data()); +diff --git a/db/memtable.h b/db/memtable.h +index 9d986b1..85c4cce 100644 +--- a/db/memtable.h ++++ b/db/memtable.h +@@ -60,7 +60,7 @@ class MemTable { + // If memtable contains a deletion for key, store a NotFound() error + // in *status and return true. + // Else, return false. +- bool Get(const LookupKey& key, std::string* value, Status* s); ++ bool Get(const LookupKey& key, Value* value, Status* s); + + private: + friend class MemTableIterator; +diff --git a/db/version_set.cc b/db/version_set.cc +index 1963353..c83a4d2 100644 +--- a/db/version_set.cc ++++ b/db/version_set.cc +@@ -256,7 +256,7 @@ struct Saver { + SaverState state; + const Comparator* ucmp; + Slice user_key; +- std::string* value; ++ Value* value; + }; + } // namespace + static void SaveValue(void* arg, const Slice& ikey, const Slice& v) { +@@ -322,7 +322,7 @@ void Version::ForEachOverlapping(Slice user_key, Slice internal_key, void* arg, + } + + Status Version::Get(const ReadOptions& options, const LookupKey& k, +- std::string* value, GetStats* stats) { ++ Value* value, GetStats* stats) { + stats->seek_file = nullptr; + stats->seek_file_level = -1; + +diff --git a/db/version_set.h b/db/version_set.h +index 69f3d70..0f0a463 100644 +--- a/db/version_set.h ++++ b/db/version_set.h +@@ -72,7 +72,7 @@ class Version { + // REQUIRES: This version has been saved (see VersionSet::SaveTo) + void AddIterators(const ReadOptions&, std::vector<Iterator*>* iters); + +- Status Get(const ReadOptions&, const LookupKey& key, std::string* val, ++ Status Get(const ReadOptions&, const LookupKey& key, Value* val, + GetStats* stats); + + // Adds "stats" into the current state. Returns true if a new +diff --git a/include/leveldb/db.h b/include/leveldb/db.h +index 61c29c0..1a93feb 100644 +--- a/include/leveldb/db.h ++++ b/include/leveldb/db.h +@@ -40,6 +40,17 @@ struct LEVELDB_EXPORT Range { + Slice limit; // Not included in the range + }; + ++// Abstract holder for a DB value. ++// This allows callers to manage their own value buffers and have ++// DB values copied directly into those buffers. ++class Value { ++ public: ++ virtual Value& assign(const char* data, size_t size) = 0; ++ ++ protected: ++ virtual ~Value(); ++}; ++ + // A DB is a persistent ordered map from keys to values. + // A DB is safe for concurrent access from multiple threads without + // any external synchronization. diff --git a/leveldb/0004-bloom_test-failure-on-big-endian-archs.patch b/leveldb/0004-bloom_test-failure-on-big-endian-archs.patch new file mode 100644 index 000000000..cb679b65c --- /dev/null +++ b/leveldb/0004-bloom_test-failure-on-big-endian-archs.patch @@ -0,0 +1,27 @@ +From: Yehuda Sadeh <yehuda@inktank.com> +Date: Mon, 2 Jul 2012 14:29:06 -0700 +Subject: [PATCH] bloom_test failure on big endian archs + +When running bloom_test on big endian machines it fails due to unacceptable +false positive rate. I've looked into the issue and it seems that the +reason for that is that it passes a different input than when it runs on +little endian. When transforming the input to be little endian it behaves +as expected. +This issue holds up inclusion of ceph to debian due to ceph's use of +leveldb. The fix can be to bump up the acceptable false positives. + +https://groups.google.com/d/topic/leveldb/SbVPvl4j4vU/discussion + +diff --git a/util/bloom_test.cc b/util/bloom_test.cc +index 520473e..e4053e6 100644 +--- a/util/bloom_test.cc ++++ b/util/bloom_test.cc +@@ -136,7 +136,7 @@ TEST_F(BloomTest, VaryingLengths) { + "False positives: %5.2f%% @ length = %6d ; bytes = %6d\n", + rate * 100.0, length, static_cast<int>(FilterSize())); + } +- ASSERT_LE(rate, 0.02); // Must not be over 2% ++ ASSERT_LE(rate, 0.03); // Must not be over 3% + if (rate > 0.0125) + mediocre_filters++; // Allowed, but not too often + else diff --git a/leveldb/0005-Restore-soname-versioning-with-CMake-build.patch b/leveldb/0005-Restore-soname-versioning-with-CMake-build.patch new file mode 100644 index 000000000..328b48aa7 --- /dev/null +++ b/leveldb/0005-Restore-soname-versioning-with-CMake-build.patch @@ -0,0 +1,32 @@ +From: leveldb Team <no-reply@google.com> +Date: Mon, 1 Apr 2019 08:59:17 -0700 +Subject: [PATCH] Restore soname versioning with CMake build + +Before: + +$ readelf -d build/libleveldb.so | grep soname + 0x000000000000000e (SONAME) Library soname: [libleveldb.so] + +After: +$ readelf -d build/libleveldb.so | grep soname + 0x000000000000000e (SONAME) Library soname: [libleveldb.so.1] + +This matches the soname from v1.20. + +PiperOrigin-RevId: 241334113 + +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f8285b8..9de6c3b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -259,6 +259,10 @@ if(BUILD_SHARED_LIBS) + # Used by include/export.h. + LEVELDB_SHARED_LIBRARY + ) ++ set_target_properties(leveldb ++ PROPERTIES VERSION ${PROJECT_VERSION}) ++ set_target_properties(leveldb ++ PROPERTIES SOVERSION 1) + endif(BUILD_SHARED_LIBS) + + if(HAVE_CLANG_THREAD_SAFETY) diff --git a/leveldb/0006-revert-no-rtti.patch b/leveldb/0006-revert-no-rtti.patch new file mode 100644 index 000000000..d6937ff5b --- /dev/null +++ b/leveldb/0006-revert-no-rtti.patch @@ -0,0 +1,15 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f8285b8..7ab9fe1 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -70,10 +70,6 @@ else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + # Disable C++ exceptions. + string(REGEX REPLACE "-fexceptions" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions") +- +- # Disable RTTI. +- string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") + endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + + # Test whether -Wthread-safety is available. See diff --git a/leveldb/Pkgfile b/leveldb/Pkgfile new file mode 100644 index 000000000..c2a3c9067 --- /dev/null +++ b/leveldb/Pkgfile @@ -0,0 +1,52 @@ +# Description: A fast and lightweight key/value database library +# URL: https://github.com/google/leveldb +# Maintainer: Danny Rawlins, crux at romster dot me +# Depends on: snappy cmake ninja + +name=leveldb +version=1.23 +release=1 +source=(https://github.com/google/leveldb/archive/$version/$name-$version.tar.gz + 0001-Allow-leveldbjni-build.patch + 0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch + 0003-allow-Get-calls-to-avoid-copies-into-std-string.patch + 0004-bloom_test-failure-on-big-endian-archs.patch + 0005-Restore-soname-versioning-with-CMake-build.patch + 0006-revert-no-rtti.patch) + +build() { + patch -d $name-$version -p1 -i $SRC/0001-Allow-leveldbjni-build.patch + patch -d $name-$version -p1 -i $SRC/0002-Added-a-DB-SuspendCompations-and-DB-ResumeCompaction.patch + patch -d $name-$version -p1 -i $SRC/0003-allow-Get-calls-to-avoid-copies-into-std-string.patch + patch -d $name-$version -p1 -i $SRC/0004-bloom_test-failure-on-big-endian-archs.patch + patch -d $name-$version -p1 -i $SRC/0005-Restore-soname-versioning-with-CMake-build.patch + patch -d $name-$version -p1 -i $SRC/0006-revert-no-rtti.patch + + cmake -S $name-$version -B build -G Ninja \ + -D CMAKE_INSTALL_PREFIX=/usr \ + -D CMAKE_INSTALL_LIBDIR=lib \ + -D CMAKE_BUILD_TYPE=Release \ + -D CMAKE_CXX_FLAGS_RELEASE="$CXXFLAGS" \ + -D CMAKE_C_FLAGS_RELEASE="$CFLAGS" \ + -D BUILD_SHARED_LIBS=ON \ + -DLEVELDB_BUILD_TESTS=OFF \ + -DLEVELDB_BUILD_BENCHMARKS=OFF \ + -Wno-dev + + cmake --build build + DESTDIR=$PKG cmake --install build + +cat <<- EOF > leveldb.pc +prefix=/usr +exec_prefix=\${prefix} +includedir=\${prefix}/include +libdir=\${exec_prefix}/lib + +Name: ${name} +Description: A fast and lightweight key/value database library +Version: ${version} +Libs: -L\${libdir} -lleveldb +EOF + + install -Dm644 leveldb.pc $PKG/usr/lib/pkgconfig/leveldb.pc +}
participants (1)
-
crux@crux.nu