Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete postgresql #4349

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,7 @@ main/StellarCoreVersion.cpp: always
@if cmp -s $@~ $@; then rm -f $@~; else \
mv -f $@~ $@ && printf "echo '%s' > $@\n" "$$(cat $@)"; fi

if USE_POSTGRES
TESTS=test/selftest-pg
else # !USE_POSTGRES
TESTS=test/selftest-nopg
endif # !USE_POSTGRES
TESTS += test/check-nondet

format: always
Expand Down
5 changes: 2 additions & 3 deletions src/bucket/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ receives a single large, atomic write whenever a ledger closes and many
reads during consensus. There is never a write during a read, so all the reads occur on an
effectively
immutable database. This write once read many times paradigm is suited better for a LSM structure
(the bucket list) than SQL DBs. In particular, Postgres is ACID compliant and supports
transactions that can be rolled back. This introduces significant, unnecessary overhead.
(the bucket list) than SQL DBs.
Since our access pattern never has conflicting reads and writes, ACID compliance is not required.
Additionally, the current core implementation never rolls back a SQL transaction. Finally,
all reads occur on an immutable database, opening the door for parallelism.
However, MySQL and Postgres do not treat the DB as immutable during reads
However, SQL DBs do not treat the DB as immutable during reads
and cannot take advantage of this parallelism.

By performing key-value lookup directly on the BucketList, we can remove ACID/rollback overhead,
Expand Down
6 changes: 0 additions & 6 deletions src/bucket/test/BucketTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,10 +987,4 @@ TEST_CASE("bucket apply bench", "[bucketbench][!hide]")
{
runtest(Config::TESTDB_ON_DISK_SQLITE);
}
#ifdef USE_POSTGRES
SECTION("postgresql")
{
runtest(Config::TESTDB_POSTGRESQL);
}
#endif
}
70 changes: 0 additions & 70 deletions src/database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@

#include <lib/soci/src/backends/sqlite3/soci-sqlite3.h>
#include <string>
#ifdef USE_POSTGRES
#include <lib/soci/src/backends/postgresql/soci-postgresql.h>
#endif
#include <sstream>
#include <stdexcept>
#include <thread>
Expand Down Expand Up @@ -75,31 +72,6 @@ static int const MIN_SQLITE_MINOR_VERSION = 45;
static int const MIN_SQLITE_VERSION =
(1000000 * MIN_SQLITE_MAJOR_VERSION) + (1000 * MIN_SQLITE_MINOR_VERSION);

// PostgreSQL pre-10.0 actually used its "minor number" as a major one
// (meaning: 9.4 and 9.5 were considered different major releases, with
// compatibility differences and so forth). After 10.0 they started doing
// what everyone else does, where 10.0 and 10.1 were only "minor". Either
// way though, we have a minimum minor version.
static int const MIN_POSTGRESQL_MAJOR_VERSION = 9;
static int const MIN_POSTGRESQL_MINOR_VERSION = 5;
static int const MIN_POSTGRESQL_VERSION =
(10000 * MIN_POSTGRESQL_MAJOR_VERSION) +
(100 * MIN_POSTGRESQL_MINOR_VERSION);

#ifdef USE_POSTGRES
static std::string
badPgVersion(int vers)
{
std::ostringstream msg;
int maj = (vers / 10000);
int min = (vers - (maj * 10000)) / 100;
msg << "PostgreSQL version " << maj << '.' << min
<< " is too old, must use at least " << MIN_POSTGRESQL_MAJOR_VERSION
<< '.' << MIN_POSTGRESQL_MINOR_VERSION;
return msg.str();
}
#endif

static std::string
badSqliteVersion(int vers)
{
Expand All @@ -118,9 +90,6 @@ Database::registerDrivers()
if (!gDriversRegistered)
{
register_factory_sqlite3();
#ifdef USE_POSTGRES
register_factory_postgresql();
#endif
gDriversRegistered = true;
}
}
Expand Down Expand Up @@ -165,20 +134,6 @@ class DatabaseConfigureSessionOp : public DatabaseTypeSpecificOperation<void>
// Register the sqlite carray() extension we use for bulk operations.
sqlite3_carray_init(sq->conn_, nullptr, nullptr);
}
#ifdef USE_POSTGRES
void
doPostgresSpecificOperation(soci::postgresql_session_backend* pg) override
{
int vers = PQserverVersion(pg->conn_);
if (vers < MIN_POSTGRESQL_VERSION)
{
throw std::runtime_error(badPgVersion(vers));
}
mSession
<< "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL "
"SERIALIZABLE";
}
#endif
};

Database::Database(Application& app)
Expand Down Expand Up @@ -381,38 +336,13 @@ Database::getUpsertTimer(std::string const& entityName)
.TimeScope();
}

void
Database::setCurrentTransactionReadOnly()
{
if (!isSqlite())
{
auto prep = getPreparedStatement("SET TRANSACTION READ ONLY");
auto& st = prep.statement();
st.define_and_bind();
st.execute(false);
}
}

bool
Database::isSqlite() const
{
return mApp.getConfig().DATABASE.value.find("sqlite3://") !=
std::string::npos;
}

std::string
Database::getSimpleCollationClause() const
{
if (isSqlite())
{
return "";
}
else
{
return " COLLATE \"C\" ";
}
}

bool
Database::canUsePool() const
{
Expand Down
28 changes: 4 additions & 24 deletions src/database/Database.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ class StatementContext : NonCopyable
* Object that owns the database connection(s) that an application
* uses to store the current ledger and other persistent state in.
*
* This may represent an in-memory SQLite instance (for testing), an on-disk
* SQLite instance (for running a minimal, self-contained server) or a
* connection to a local Postgresql database, that the node operator must have
* set up on their own.
* This may represent an in-memory SQLite instance (for testing), or an on-disk
* SQLite instance (for running a minimal, self-contained server) that the node
* operator must have set up on their own.
*
* Database connects, on construction, to the target specified by the
* application Config object's Config::DATABASE value; this originates from the
Expand All @@ -81,8 +80,7 @@ class StatementContext : NonCopyable
* worker thread.
*
* All database connections and transactions are set to snapshot isolation level
* (SQL isolation level 'SERIALIZABLE' in Postgresql and Sqlite, neither of
* which provide true serializability).
* (unlike SQL isolation level 'SERIALIZABLE' in Sqlite, which does not provides true serializability).
*/
class Database : NonMovableOrCopyable
{
Expand Down Expand Up @@ -134,21 +132,9 @@ class Database : NonMovableOrCopyable
medida::TimerContext getUpdateTimer(std::string const& entityName);
medida::TimerContext getUpsertTimer(std::string const& entityName);

// If possible (i.e. "on postgres") issue an SQL pragma that marks
// the current transaction as read-only. The effects of this last
// only as long as the current SQL transaction.
void setCurrentTransactionReadOnly();

// Return true if the Database target is SQLite, otherwise false.
bool isSqlite() const;

// Return an optional SQL COLLATION clause to use for text-typed columns in
// this database, in order to ensure they're compared "simply" using
// byte-value comparisons, i.e. in a non-language-sensitive fashion. For
// Postgresql this will be 'COLLATE "C"' and for SQLite, nothing (its
// defaults are correct already).
std::string getSimpleCollationClause() const;

// Call `op` back with the specific database backend subtype in use.
template <typename T>
T doDatabaseTypeSpecificOperation(DatabaseTypeSpecificOperation<T>& op);
Expand Down Expand Up @@ -192,12 +178,6 @@ doDatabaseTypeSpecificOperation(soci::session& session,
if (auto sq = dynamic_cast<soci::sqlite3_session_backend*>(b))
{
return op.doSqliteSpecificOperation(sq);
#ifdef USE_POSTGRES
}
else if (auto pg = dynamic_cast<soci::postgresql_session_backend*>(b))
{
return op.doPostgresSpecificOperation(pg);
#endif
}
else
{
Expand Down
7 changes: 0 additions & 7 deletions src/database/DatabaseTypeSpecificOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0

#include <lib/soci/src/backends/sqlite3/soci-sqlite3.h>
#ifdef USE_POSTGRES
#include <lib/soci/src/backends/postgresql/soci-postgresql.h>
#endif

// Just a visitor type to help write code that's database-specific.
// See Database::doDatabaseTypeSpecificOperation.
Expand All @@ -17,9 +14,5 @@ template <typename T = void> class DatabaseTypeSpecificOperation
{
public:
virtual T doSqliteSpecificOperation(soci::sqlite3_session_backend* sq) = 0;
#ifdef USE_POSTGRES
virtual T
doPostgresSpecificOperation(soci::postgresql_session_backend* pg) = 0;
#endif
};
}
Loading
Loading