mirror of
https://github.com/Xahau/xahaud.git
synced 2026-06-04 09:16:36 +00:00
The primary change introduced in this commit is partitioning of the `TaggedCache`, with each partition being indepedent of each other, making it possible to potentially perform multiple cache operations in parallel. In particular, the `sweep` operation is now parallelized by default on systems with at least four cores present. The `TaggedCache` could also be instantiated in 'key-only' mode which complicated the interface significantly but was only used by a single consumer (the `FullBelowCache`). This commit splits the 'key-only' functionality of `TaggedCache`, and incorporates directly into `FullBelowCache`, resulting in simple and cleaner interfaces for both `TaggedCache` and `FullBelowCache` but at a cost: some code duplication. Lastly, this commit includes a medley of changes, including the restructuring of `Transaction`, reducing its size by 48 bytes.
143 lines
4.0 KiB
C++
143 lines
4.0 KiB
C++
//------------------------------------------------------------------------------
|
|
/*
|
|
This file is part of rippled: https://github.com/ripple/rippled
|
|
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*/
|
|
//==============================================================================
|
|
|
|
#include <ripple/app/ledger/LedgerMaster.h>
|
|
#include <ripple/app/main/Application.h>
|
|
#include <ripple/app/misc/HashRouter.h>
|
|
#include <ripple/app/misc/Transaction.h>
|
|
#include <ripple/app/rdb/backend/PostgresDatabase.h>
|
|
#include <ripple/app/rdb/backend/SQLiteDatabase.h>
|
|
#include <ripple/app/tx/apply.h>
|
|
#include <ripple/basics/Log.h>
|
|
#include <ripple/basics/safe_cast.h>
|
|
#include <ripple/core/DatabaseCon.h>
|
|
#include <ripple/core/Pg.h>
|
|
#include <ripple/json/json_reader.h>
|
|
#include <ripple/protocol/ErrorCodes.h>
|
|
#include <ripple/protocol/Feature.h>
|
|
#include <ripple/protocol/jss.h>
|
|
|
|
namespace ripple {
|
|
|
|
//
|
|
// Misc.
|
|
//
|
|
|
|
TransStatus
|
|
sqlTransactionStatus(boost::optional<std::string> const& status)
|
|
{
|
|
char const c = (status) ? (*status)[0] : safe_cast<char>(txnSqlUnknown);
|
|
|
|
switch (c)
|
|
{
|
|
case txnSqlNew:
|
|
return NEW;
|
|
case txnSqlConflict:
|
|
return CONFLICTED;
|
|
case txnSqlHeld:
|
|
return HELD;
|
|
case txnSqlValidated:
|
|
return COMMITTED;
|
|
case txnSqlIncluded:
|
|
return INCLUDED;
|
|
}
|
|
|
|
assert(c == txnSqlUnknown);
|
|
return INVALID;
|
|
}
|
|
|
|
std::variant<
|
|
std::pair<std::shared_ptr<Transaction>, std::shared_ptr<TxMeta>>,
|
|
TxSearched>
|
|
Transaction::load(uint256 const& id, Application& app, error_code_i& ec)
|
|
{
|
|
return load(id, app, std::nullopt, ec);
|
|
}
|
|
|
|
std::variant<
|
|
std::pair<std::shared_ptr<Transaction>, std::shared_ptr<TxMeta>>,
|
|
TxSearched>
|
|
Transaction::load(
|
|
uint256 const& id,
|
|
Application& app,
|
|
ClosedInterval<uint32_t> const& range,
|
|
error_code_i& ec)
|
|
{
|
|
using op = std::optional<ClosedInterval<uint32_t>>;
|
|
|
|
return load(id, app, op{range}, ec);
|
|
}
|
|
|
|
Transaction::Locator
|
|
Transaction::locate(uint256 const& id, Application& app)
|
|
{
|
|
auto const db =
|
|
dynamic_cast<PostgresDatabase*>(&app.getRelationalDatabase());
|
|
|
|
if (!db)
|
|
{
|
|
Throw<std::runtime_error>("Failed to get relational database");
|
|
}
|
|
|
|
return db->locateTransaction(id);
|
|
}
|
|
|
|
std::variant<
|
|
std::pair<std::shared_ptr<Transaction>, std::shared_ptr<TxMeta>>,
|
|
TxSearched>
|
|
Transaction::load(
|
|
uint256 const& id,
|
|
Application& app,
|
|
std::optional<ClosedInterval<uint32_t>> const& range,
|
|
error_code_i& ec)
|
|
{
|
|
auto const db = dynamic_cast<SQLiteDatabase*>(&app.getRelationalDatabase());
|
|
|
|
if (!db)
|
|
{
|
|
Throw<std::runtime_error>("Failed to get relational database");
|
|
}
|
|
|
|
return db->getTransaction(id, range, ec);
|
|
}
|
|
|
|
// options 1 to include the date of the transaction
|
|
Json::Value
|
|
Transaction::getJson(Application& app, JsonOptions options, bool binary) const
|
|
{
|
|
Json::Value ret(mTransaction->getJson(JsonOptions::none, binary));
|
|
|
|
if (mInLedger)
|
|
{
|
|
ret[jss::inLedger] = mInLedger; // Deprecated.
|
|
ret[jss::ledger_index] = mInLedger;
|
|
|
|
if (options == JsonOptions::include_date)
|
|
{
|
|
auto ct = app.getLedgerMaster().getCloseTimeBySeq(mInLedger);
|
|
if (ct)
|
|
ret[jss::date] = ct->time_since_epoch().count();
|
|
}
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
} // namespace ripple
|