1
0
forked from blue/lmdbal

pragma once and minor change in transactions

This commit is contained in:
Blue 2024-12-17 20:03:48 +02:00
parent 43d4900809
commit 56d35d4832
Signed by untrusted user: blue
GPG Key ID: 9B203B252A63EE38
29 changed files with 79 additions and 143 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
# LMDBAL 0.6.0 (UNRELEASED)
### Improvements
- Less dereferencing
# LMDBAL 0.5.4 (November 30, 2024) # LMDBAL 0.5.4 (November 30, 2024)
### Improvements ### Improvements
- Technical release just to resolve build issues - Technical release just to resolve build issues

View File

@ -10,7 +10,7 @@ depends=( 'lmdb' )
makedepends=('cmake>=3.16' 'gcc') makedepends=('cmake>=3.16' 'gcc')
optdepends=() optdepends=()
source=("lmdbal-$pkgver.tar.gz::https://git.macaw.me/blue/lmdbal/archive/$pkgver.tar.gz") source=("lmdbal-$pkgver-$pkgrel.tar.gz::https://git.macaw.me/blue/lmdbal/archive/$pkgver.tar.gz")
sha256sums=('SKIP') sha256sums=('SKIP')
build() { build() {
cd "$srcdir/lmdbal" cd "$srcdir/lmdbal"

View File

@ -43,7 +43,7 @@ LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize):
size(_mapSize), size(_mapSize),
environment(), environment(),
storages(), storages(),
transactions(new Transactions()) transactions()
{} {}
/** /**
@ -52,8 +52,6 @@ LMDBAL::Base::Base(const QString& _name, uint16_t _mapSize):
LMDBAL::Base::~Base() { LMDBAL::Base::~Base() {
close(); close();
delete transactions;
for (const std::pair<const std::string, iStorage*>& pair : storages) for (const std::pair<const std::string, iStorage*>& pair : storages)
delete pair.second; delete pair.second;
} }
@ -68,14 +66,14 @@ LMDBAL::Base::~Base() {
*/ */
void LMDBAL::Base::close() { void LMDBAL::Base::close() {
if (opened) { if (opened) {
for (const LMDBAL::TransactionID id : *transactions) for (const LMDBAL::TransactionID id : transactions)
abortTransaction(id, emptyName); abortTransaction(id, emptyName);
for (const std::pair<const std::string, iStorage*>& pair : storages) for (const std::pair<const std::string, iStorage*>& pair : storages)
pair.second->close(); pair.second->close();
mdb_env_close(environment); mdb_env_close(environment);
transactions->clear(); transactions.clear();
opened = false; opened = false;
} }
} }
@ -301,7 +299,7 @@ LMDBAL::TransactionID LMDBAL::Base::beginReadOnlyTransaction(const std::string&
throw Closed("beginReadOnlyTransaction", name, storageName); throw Closed("beginReadOnlyTransaction", name, storageName);
TransactionID txn = beginPrivateReadOnlyTransaction(storageName); TransactionID txn = beginPrivateReadOnlyTransaction(storageName);
transactions->emplace(txn); transactions.emplace(txn);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages) for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionStarted(txn, true); pair.second->transactionStarted(txn, true);
@ -325,7 +323,7 @@ LMDBAL::TransactionID LMDBAL::Base::beginTransaction(const std::string& storageN
throw Closed("beginTransaction", name, storageName); throw Closed("beginTransaction", name, storageName);
TransactionID txn = beginPrivateTransaction(storageName); TransactionID txn = beginPrivateTransaction(storageName);
transactions->emplace(txn); transactions.emplace(txn);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages) for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionStarted(txn, false); pair.second->transactionStarted(txn, false);
@ -349,15 +347,15 @@ void LMDBAL::Base::abortTransaction(LMDBAL::TransactionID id, const std::string&
if (!opened) if (!opened)
throw Closed("abortTransaction", name, storageName); throw Closed("abortTransaction", name, storageName);
Transactions::iterator itr = transactions->find(id); Transactions::iterator itr = transactions.find(id);
if (itr == transactions->end()) //TODO may be it's a good idea to make an exception class for this if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this
throw Unknown(name, "unable to abort transaction: transaction was not found", storageName); throw Unknown(name, "unable to abort transaction: transaction was not found", storageName);
abortPrivateTransaction(id, storageName); abortPrivateTransaction(id, storageName);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages) for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionAborted(id); pair.second->transactionAborted(id);
transactions->erase(itr); transactions.erase(itr);
} }
/** /**
@ -376,15 +374,15 @@ void LMDBAL::Base::commitTransaction(LMDBAL::TransactionID id, const std::string
if (!opened) if (!opened)
throw Closed("abortTransaction", name, storageName); throw Closed("abortTransaction", name, storageName);
Transactions::iterator itr = transactions->find(id); Transactions::iterator itr = transactions.find(id);
if (itr == transactions->end()) //TODO may be it's a good idea to make an exception class for this if (itr == transactions.end()) //TODO may be it's a good idea to make an exception class for this
throw Unknown(name, "unable to commit transaction: transaction was not found", storageName); throw Unknown(name, "unable to commit transaction: transaction was not found", storageName);
commitPrivateTransaction(id, storageName); commitPrivateTransaction(id, storageName);
for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages) for (const std::pair<const std::string, LMDBAL::iStorage*>& pair : storages)
pair.second->transactionCommited(id); pair.second->transactionCommited(id);
transactions->erase(itr); transactions.erase(itr);
} }
/** /**

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_BASE_H #pragma once
#define LMDBAL_BASE_H
#include <map> #include <map>
#include <set> #include <set>
@ -106,7 +105,7 @@ private:
uint16_t size; /**<\brief lmdb map size in MiB*/ uint16_t size; /**<\brief lmdb map size in MiB*/
MDB_env* environment; /**<\brief lmdb environment handle*/ MDB_env* environment; /**<\brief lmdb environment handle*/
Storages storages; /**<\brief Registered storages and caches*/ Storages storages; /**<\brief Registered storages and caches*/
Transactions* transactions; /**<\brief Active public transactions*/ mutable Transactions transactions; /**<\brief Active public transactions*/
inline static const std::string emptyName = ""; /**<\brief Empty string for general fallback purposes*/ inline static const std::string emptyName = ""; /**<\brief Empty string for general fallback purposes*/
}; };
@ -215,5 +214,3 @@ template <class K, class V>
LMDBAL::Cache<K, V>* LMDBAL::Base::getCache(const std::string& storageName) { LMDBAL::Cache<K, V>* LMDBAL::Base::getCache(const std::string& storageName) {
return static_cast<Cache<K, V>*>(storages.at(storageName)); return static_cast<Cache<K, V>*>(storages.at(storageName));
} }
#endif //LMDBAL_BASE_H

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_CACHE_H #pragma once
#define LMDBAL_CACHE_H
#include <map> #include <map>
#include <set> #include <set>
@ -134,5 +133,3 @@ protected:
} }
#include "cache.hpp" #include "cache.hpp"
#endif // LMDBAL_CACHE_H

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_CACHE_HPP #pragma once
#define LMDBAL_CACHE_HPP
#include "cache.h" #include "cache.h"
#include "exceptions.h" #include "exceptions.h"
@ -898,5 +897,3 @@ void LMDBAL::Cache<K, V>::destroyTransactionEntry(const Entry& entry) const {
break; break;
} }
} }
#endif //LMDBAL_CACHE_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_CURSOR_H #pragma once
#define LMDBAL_CURSOR_H
#include <string> #include <string>
@ -105,5 +104,3 @@ private:
#include "cursor.hpp" #include "cursor.hpp"
#endif //LMDBAL_CURSOR_H

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_CURSOR_HPP #pragma once
#define LMDBAL_CURSOR_HPP
#include "cursor.h" #include "cursor.h"
#include <iostream> #include <iostream>
@ -482,7 +481,7 @@ void LMDBAL::Cursor<K, V>::prev (K& key, V& value) {
* \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb * \exception LMDBAL::Unknown thrown if there was some unexpected problem with lmdb
*/ */
template<class K, class V> template<class K, class V>
void LMDBAL::Cursor<K, V>::current (K& key, V& value) const { void LMDBAL::Cursor<K, V>::current (K& key, V& value) const {
operateCursorRead(key, value, MDB_GET_CURRENT, currentMethodName, currentOperationName); operateCursorRead(key, value, MDB_GET_CURRENT, currentMethodName, currentOperationName);
} }
@ -657,5 +656,3 @@ void LMDBAL::Cursor<K, V>::operateCursorRead(
else else
storage->discoveredRecord(key, value, storage->_mdbCursorTxn(cursor)); storage->discoveredRecord(key, value, storage->_mdbCursorTxn(cursor));
} }
#endif //LMDBAL_CURSOR_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_EXCEPTIONS_H #pragma once
#define LMDBAL_EXCEPTIONS_H
#include <stdexcept> #include <stdexcept>
#include <string> #include <string>
@ -237,5 +236,3 @@ private:
}; };
} }
#endif //LMDBAL_EXCEPTIONS_H

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_OPERATORS_HPP #pragma once
#define LMDBAL_OPERATORS_HPP
#include <map> #include <map>
#include <set> #include <set>
@ -209,5 +208,3 @@ QDataStream& operator >> (QDataStream &in, std::list<K>& container) {
return in; return in;
} }
#endif //LMDBAL_OPERATORS_HPP

View File

@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_H #pragma once
#define LMDBAL_SERIALIZER_H
#include <cstring> #include <cstring>
@ -68,5 +68,3 @@ private:
#include "serializer_stdstring.hpp" #include "serializer_stdstring.hpp"
#include "serializer_qstring.hpp" #include "serializer_qstring.hpp"
#include "serializer_qbytearray.hpp" #include "serializer_qbytearray.hpp"
#endif // LMDBAL_SERIALIZER_H

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_HPP #pragma once
#define LMDBAL_SERIALIZER_HPP
#include "serializer.h" #include "serializer.h"
@ -159,5 +158,3 @@ MDB_val LMDBAL::Serializer<T>::getData() {
return val; return val;
} }
#endif //LMDBAL_SERIALIZER_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_DOUBLE_HPP #pragma once
#define LMDBAL_SERIALIZER_DOUBLE_HPP
namespace LMDBAL { namespace LMDBAL {
@ -53,7 +52,5 @@ private:
} }
#endif //LMDBAL_SERIALIZER_DOUBLE_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_FLOAT_HPP #pragma once
#define LMDBAL_SERIALIZER_FLOAT_HPP
namespace LMDBAL { namespace LMDBAL {
@ -52,8 +51,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_FLOAT_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_INT16_HPP #pragma once
#define LMDBAL_SERIALIZER_INT16_HPP
#include <stdint.h> #include <stdint.h>
@ -54,5 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_INT16_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_INT32_HPP #pragma once
#define LMDBAL_SERIALIZER_INT32_HPP
#include <stdint.h> #include <stdint.h>
@ -54,8 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_INT32_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_INT64_HPP #pragma once
#define LMDBAL_SERIALIZER_INT64_HPP
#include <stdint.h> #include <stdint.h>
@ -54,8 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_INT64_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_INT8_HPP #pragma once
#define LMDBAL_SERIALIZER_INT8_HPP
#include <stdint.h> #include <stdint.h>
@ -54,8 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_INT8_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_QBYTEARRAY_HPP #pragma once
#define LMDBAL_SERIALIZER_QBYTEARRAY_HPP
#include <QByteArray> #include <QByteArray>
@ -56,9 +55,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_QBYTEARRAY_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_QSTRING_HPP #pragma once
#define LMDBAL_SERIALIZER_QSTRING_HPP
#include <QString> #include <QString>
#include <QByteArray> #include <QByteArray>
@ -56,10 +55,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_QSTRING_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_STDSTRING_HPP #pragma once
#define LMDBAL_SERIALIZER_STDSTRING_HPP
#include <string> #include <string>
@ -54,9 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_STDSTRING_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_UINT16_HPP #pragma once
#define LMDBAL_SERIALIZER_UINT16_HPP
#include <stdint.h> #include <stdint.h>
@ -54,7 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_UINT16_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_UINT32_HPP #pragma once
#define LMDBAL_SERIALIZER_UINT32_HPP
#include <stdint.h> #include <stdint.h>
@ -54,5 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_UINT32_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_UINT64_HPP #pragma once
#define LMDBAL_SERIALIZER_UINT64_HPP
#include <stdint.h> #include <stdint.h>
@ -54,6 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_UINT64_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_SERIALIZER_UINT8_HPP #pragma once
#define LMDBAL_SERIALIZER_UINT8_HPP
#include <stdint.h> #include <stdint.h>
@ -54,8 +53,3 @@ private:
}; };
} }
#endif //LMDBAL_SERIALIZER_UINT8_HPP

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_STORAGE_H #pragma once
#define LMDBAL_STORAGE_H
#include <type_traits> #include <type_traits>
#include <cstring> #include <cstring>
@ -199,5 +198,3 @@ protected:
} }
#include "storage.hpp" #include "storage.hpp"
#endif //LMDBAL_STORAGE_H

View File

@ -16,8 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef LMDBAL_STORAGE_HPP #pragma once
#define LMDBAL_STORAGE_HPP
#include "storage.h" #include "storage.h"
#include "exceptions.h" #include "exceptions.h"
@ -1182,5 +1181,3 @@ template<>
inline std::string LMDBAL::iStorage::toString(const std::string& value) { inline std::string LMDBAL::iStorage::toString(const std::string& value) {
return value; return value;
} }
#endif //LMDBAL_STORAGE_HPP

View File

@ -1,3 +1,21 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "transaction.h" #include "transaction.h"
/** /**

View File

@ -1,3 +1,21 @@
/*
* LMDB Abstraction Layer.
* Copyright (C) 2023 Yury Gubich <blue@macaw.me>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once #pragma once
#include "base.h" #include "base.h"