Skip to content

Commit

Permalink
add more relaxed acid
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardAH committed Feb 14, 2025
1 parent 44157d1 commit 8aedbba
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/ripple/nodestore/backend/MySQLFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ static constexpr auto INSERT_NODE = R"SQL(
ON DUPLICATE KEY UPDATE data = VALUES(data)
)SQL";

static constexpr auto SET_ISOLATION_LEVEL = R"SQL(
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
)SQL";

class MySQLConnection
{
private:
Expand Down Expand Up @@ -76,6 +80,14 @@ class MySQLConnection
if (!conn)
return false;

// Set isolation level for dirty reads
if (mysql_query(mysql_.get(), SET_ISOLATION_LEVEL))
{
JLOG(journal_.warn()) << "Failed to set isolation level: "
<< mysql_error(mysql_.get());
return false;
}

// Create database (unconditionally)
std::string query(1024, '\0');
int length = snprintf(
Expand Down Expand Up @@ -532,12 +544,7 @@ class MySQLBackend : public Backend
return;
}

if (mysql_stmt_execute(stmt))
{
mysql_stmt_close(stmt);
return;
}

mysql_stmt_execute(stmt);
mysql_stmt_close(stmt);
}

Expand All @@ -551,20 +558,20 @@ class MySQLBackend : public Backend
if (!conn->ensureConnection())
return;

if (mysql_query(conn->get(), "START TRANSACTION"))
return;
// if (mysql_query(conn->get(), "START TRANSACTION"))
// return;

try
{
for (auto const& e : batch)
store(e);

if (mysql_query(conn->get(), "COMMIT"))
mysql_query(conn->get(), "ROLLBACK");
// if (mysql_query(conn->get(), "COMMIT"))
// mysql_query(conn->get(), "ROLLBACK");
}
catch (...)
{
mysql_query(conn->get(), "ROLLBACK");
// mysql_query(conn->get(), "ROLLBACK");
throw;
}
}
Expand Down

0 comments on commit 8aedbba

Please sign in to comment.