commit 6a7bfb722fc34473a3463cdf62940a628bd7b699 Author: mahlon@laika.com Date: Thu Nov 19 02:06:45 2020 +0000 Initial layout/commit. FossilOrigin-Name: 5ccedce83232d9c4f5341866293f884fde8bcc9c1df2ea7407740d2d984fae9b diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..ee5f68e --- /dev/null +++ b/.hgignore @@ -0,0 +1,13 @@ +docs/ +tmp/ +\.bundle$ +\.lock$ +\.gemspec$ +\.so$ +spec/\.status +coverage/ +vendor/ +pkg/ +^Session.vim$ +^Makefile$ + diff --git a/.pryrc b/.pryrc new file mode 100644 index 0000000..3b34fda --- /dev/null +++ b/.pryrc @@ -0,0 +1,14 @@ +# -*- ruby -*- +# vim: set nosta noet ts=4 sw=4 ft=ruby: +# encoding: utf-8 + +$LOAD_PATH.unshift( 'lib' ) + +begin + require 'mdbx' +rescue Exception => e + $stderr.puts "Ack! Libraries failed to load: #{e.message}\n\t" + + e.backtrace.join( "\n\t" ) +end + + diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..2ea8461 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +-fd -c diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 0000000..ffea1c5 --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +mdbx diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..860487c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.1 diff --git a/History.md b/History.md new file mode 100644 index 0000000..e69de29 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..e69de29 diff --git a/Manifest.txt b/Manifest.txt new file mode 100644 index 0000000..f4069b7 --- /dev/null +++ b/Manifest.txt @@ -0,0 +1,3 @@ +History.md +LICENSE.txt +README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f3de2b --- /dev/null +++ b/README.md @@ -0,0 +1,128 @@ +# Ruby MDBX + +home +: https://gitlab.com/mahlon/ruby-mdbx + +code +: https://code.martini.nu/ruby-mdbx + +github +: https://github.com/mahlon/ruby-mdbx + +gitlab +: https://gitlab.com/mahlon/ruby-mdbx/-/tree-master + + +docs +: https://martini.nu/docs/ruby-mdbx +#FIXME: ....... somewhere on martini + + +## Description + +This is a Ruby (MRI) binding for the libmdbx database library. + +libmdbx is an extremely fast, compact, powerful, embedded, transactional +key-value database, with permissive license. libmdbx has a specific set +of properties and capabilities, focused on creating unique lightweight +solutions. + + - Allows a swarm of multi-threaded processes to ACIDly read and update + several key-value maps and multimaps in a locally-shared database. + + - Provides extraordinary performance, minimal overhead through + Memory-Mapping and Olog(N) operations costs by virtue of B+ tree. + + - Requires no maintenance and no crash recovery since it doesn't use + WAL, but that might be a caveat for write-intensive workloads with + durability requirements. + + - Compact and friendly for fully embedding. Only ≈25KLOC of C11, + ≈64K x86 binary code of core, no internal threads neither server + process(es), but implements a simplified variant of the Berkeley DB + and dbm API. + + - Enforces serializability for writers just by single mutex and + affords wait-free for parallel readers without atomic/interlocked + operations, while writing and reading transactions do not block each + other. + + - Guarantee data integrity after crash unless this was explicitly + neglected in favour of write performance. + + - Supports Linux, Windows, MacOS, Android, iOS, FreeBSD, DragonFly, + Solaris, OpenSolaris, OpenIndiana, NetBSD, OpenBSD and other systems + compliant with POSIX.1-2008. + + - Historically, libmdbx is a deeply revised and extended descendant + of the amazing Lightning Memory-Mapped Database. libmdbx inherits + all benefits from LMDB, but resolves some issues and adds a set of + improvements. + + +### Examples + +[forthcoming] + + +## Prerequisites + +* Ruby 2.6+ +* libmdbx (https://github.com/erthink/libmdbx) + + +## Installation + + $ gem install mdbx + + +## Contributing + +You can check out the current development source with Mercurial via its +[home repo](https://code.martini.nu/ruby-mdbx), or with Git at its +[project page](https://gitlab.com/mahlon/ruby-mdbx). + +After checking out the source, run: + + $ gem install -Ng + $ rake setup + +This will install dependencies, and do any other necessary setup for +development. + + +## Authors + +- Mahlon E. Smith + + +## License + +Copyright (c) 2020, Mahlon E. Smith +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +* Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + +* Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +* Neither the name of the author/s, nor the names of the project's + contributors may be used to endorse or promote products derived from this + software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE +FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..deda0d9 --- /dev/null +++ b/Rakefile @@ -0,0 +1,22 @@ +# vim: set noet sta sw=4 ts=4 : +# -*- ruby -*- + +require 'rake/deveiate' + +Rake::DevEiate.setup( 'mdbx' ) do |project| + project.summary = <<~END_SUM + A ruby binding to libmdbx, an improved version + of the Lightning Memory Mapped Database. + END_SUM + project.description = <<~END_DESC + This is a native ruby binding to libmdbx, an improved version + of the Lightning Memory Mapped Database. + + libmdbx is an extremely fast, compact, powerful, embedded, + transactional key-value database, with permissive license. + libmdbx has a specific set of properties and capabilities, + focused on creating unique lightweight solutions. + END_DESC + project.authors = [ 'Mahlon E. Smith ' ] +end + diff --git a/ext/mdbx_ext/extconf.rb b/ext/mdbx_ext/extconf.rb new file mode 100755 index 0000000..d5f9299 --- /dev/null +++ b/ext/mdbx_ext/extconf.rb @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# vim: set noet sta sw=4 ts=4 : + +require 'mkmf' + +have_library( 'mdbx' ) or abort "No mdbx library!" +have_header( 'mdbx.h' ) or abort "No mdbx.h header!" + +create_header() +create_makefile( 'mdbx_ext' ) + diff --git a/ext/mdbx_ext/mdbx_ext.c b/ext/mdbx_ext/mdbx_ext.c new file mode 100644 index 0000000..8a4ead8 --- /dev/null +++ b/ext/mdbx_ext/mdbx_ext.c @@ -0,0 +1,15 @@ +/* vim: set noet sta sw=4 ts=4 : */ + +#include "mdbx_ext.h" + + +/* + * MDBX initialization + */ +void +Init_mdbx_ext() +{ + mdbx_mMDBX = rb_define_module( "MDBX" ); + rb_define_const( mdbx_mMDBX, "LIBRARY_VERSION", rb_str_new_cstr(mdbx_version.git.describe) ); +} + diff --git a/ext/mdbx_ext/mdbx_ext.h b/ext/mdbx_ext/mdbx_ext.h new file mode 100644 index 0000000..07ac287 --- /dev/null +++ b/ext/mdbx_ext/mdbx_ext.h @@ -0,0 +1,13 @@ + +#include +#include "extconf.h" + +#include "mdbx.h" + + +/* ------------------------------------------------------------ + Globals + ------------------------------------------------------------ */ + +VALUE mdbx_mMDBX; + diff --git a/gem.deps.rb b/gem.deps.rb new file mode 100644 index 0000000..abe4b1c --- /dev/null +++ b/gem.deps.rb @@ -0,0 +1,13 @@ +source "https://rubygems.org/" + +group( :development ) do + gem 'pry', '~> 0.13' + gem 'rake', '~> 13.0' + gem 'rake-compiler', '~> 1.1' + gem 'rake-deveiate', '~> 0.15', '>= 0.15.1' + gem 'rdoc-generator-fivefish', '~> 0.4' + gem 'rspec', '~> 3.9' + gem 'rubocop', '~> 0.93' + gem 'simplecov', '~> 0.12' +end + diff --git a/lib/mdbx.rb b/lib/mdbx.rb new file mode 100644 index 0000000..705c83e --- /dev/null +++ b/lib/mdbx.rb @@ -0,0 +1,18 @@ +# -*- ruby -*- +# vim: set nosta noet ts=4 sw=4 ft=ruby: +# encoding: utf-8 + +require 'mdbx_ext' + + +# Top level namespace for MDBX. +# +module MDBX + + # The version of this gem. + # Note: the MDBX library version can be found in + # the 'LIBRARY_VERSION' constant. + VERSION = '0.0.1' + +end + diff --git a/spec/lib/helper.rb b/spec/lib/helper.rb new file mode 100644 index 0000000..e80ba3f --- /dev/null +++ b/spec/lib/helper.rb @@ -0,0 +1,39 @@ +# -*- ruby -*- +# vim: set noet sta sw=4 ts=4 : +# frozen_string_literal: true + + +if ENV[ 'COVERAGE' ] + require 'simplecov' + SimpleCov.start +end + +require 'rspec' +require 'mdbx' + + +RSpec.configure do |config| + config.expect_with :rspec do |expectations| + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + expectations.syntax = :expect + end + + config.mock_with( :rspec ) do |mock| + mock.syntax = :expect + mock.verify_partial_doubles = true + end + + config.disable_monkey_patching! + config.example_status_persistence_file_path = "spec/.status" + config.filter_run :focus + config.filter_run_when_matching :focus + config.order = :random + config.profile_examples = 5 + config.run_all_when_everything_filtered = true + # config.warnings = true + + # config.include( Zyre::Testing ) + # config.include( Loggability::SpecHelpers ) +end + + diff --git a/spec/mdbx_spec.rb b/spec/mdbx_spec.rb new file mode 100644 index 0000000..350db96 --- /dev/null +++ b/spec/mdbx_spec.rb @@ -0,0 +1,13 @@ +#!/usr/bin/env rspec -cfd + +require_relative './lib/helper' + + +RSpec.describe( MDBX ) do + + it "can report the MDBX library version" do + expect( described_class::LIBRARY_VERSION ). + to match( /v\d+\.\d+\.\d+\-\d+\-\w+$/ ) + end +end +