mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 12:05:53 +00:00
Add user defined literals for megabytes and kilobytes
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include <ripple/app/misc/ValidatorKeys.h>
|
||||
#include <ripple/app/paths/PathRequests.h>
|
||||
#include <ripple/app/tx/apply.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/basics/ResolverAsio.h>
|
||||
#include <ripple/basics/Sustain.h>
|
||||
#include <ripple/basics/PerfLog.h>
|
||||
@@ -609,7 +610,6 @@ public:
|
||||
return nodeIdentity_;
|
||||
}
|
||||
|
||||
|
||||
PublicKey const &
|
||||
getValidationPublicKey() const override
|
||||
{
|
||||
@@ -1029,8 +1029,7 @@ public:
|
||||
boost::filesystem::space_info space =
|
||||
boost::filesystem::space (config_->legacy ("database_path"));
|
||||
|
||||
constexpr std::uintmax_t bytes512M = 512 * 1024 * 1024;
|
||||
if (space.available < (bytes512M))
|
||||
if (space.available < megabytes(512))
|
||||
{
|
||||
JLOG(m_journal.fatal())
|
||||
<< "Remaining free disk space is less than 512MB";
|
||||
@@ -1074,7 +1073,7 @@ public:
|
||||
<< "Note that this does not take into account available disk "
|
||||
"space.";
|
||||
|
||||
if (freeSpace < bytes512M)
|
||||
if (freeSpace < megabytes(512))
|
||||
{
|
||||
JLOG(m_journal.fatal())
|
||||
<< "Free SQLite space for transaction db is less than "
|
||||
@@ -1194,11 +1193,11 @@ bool ApplicationImp::setup()
|
||||
|
||||
getLedgerDB ().getSession ()
|
||||
<< boost::str (boost::format ("PRAGMA cache_size=-%d;") %
|
||||
(config_->getSize (siLgrDBCache) * 1024));
|
||||
(config_->getSize (siLgrDBCache) * kilobytes(1)));
|
||||
|
||||
getTxnDB ().getSession ()
|
||||
<< boost::str (boost::format ("PRAGMA cache_size=-%d;") %
|
||||
(config_->getSize (siTxnDBCache) * 1024));
|
||||
(config_->getSize (siTxnDBCache) * kilobytes(1)));
|
||||
|
||||
mTxnDB->setupCheckpointing (m_jobQueue.get(), logs());
|
||||
mLedgerDB->setupCheckpointing (m_jobQueue.get(), logs());
|
||||
|
||||
38
src/ripple/basics/ByteUtilities.h
Normal file
38
src/ripple/basics/ByteUtilities.h
Normal file
@@ -0,0 +1,38 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2018 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.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_BASICS_BYTEUTILITIES_H_INCLUDED
|
||||
#define RIPPLE_BASICS_BYTEUTILITIES_H_INCLUDED
|
||||
|
||||
namespace ripple {
|
||||
|
||||
template<class T>
|
||||
constexpr auto kilobytes(T value) noexcept
|
||||
{
|
||||
return value * 1024;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
constexpr auto megabytes(T value) noexcept
|
||||
{
|
||||
return kilobytes(1) * kilobytes(1) * value;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -21,6 +21,7 @@
|
||||
#define RIPPLE_BASICS_QALLOC_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <boost/intrusive/list.hpp>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
@@ -67,10 +68,7 @@ private:
|
||||
block* free_ = nullptr;
|
||||
|
||||
public:
|
||||
enum
|
||||
{
|
||||
block_size = 256 * 1024
|
||||
};
|
||||
static constexpr auto block_size = kilobytes(256);
|
||||
|
||||
qalloc_impl() = default;
|
||||
qalloc_impl (qalloc_impl const&) = delete;
|
||||
|
||||
@@ -20,6 +20,8 @@
|
||||
#ifndef RIPPLE_CORE_COROINL_H_INCLUDED
|
||||
#define RIPPLE_CORE_COROINL_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
template <class F>
|
||||
@@ -40,7 +42,7 @@ Coro(Coro_create_t, JobQueue& jq, JobType type,
|
||||
#ifndef NDEBUG
|
||||
finished_ = true;
|
||||
#endif
|
||||
}, boost::coroutines::attributes (1024 * 1024))
|
||||
}, boost::coroutines::attributes (megabytes(1)))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/core/ConfigSections.h>
|
||||
#include <ripple/core/SociDB.h>
|
||||
#include <ripple/core/Config.h>
|
||||
@@ -129,7 +130,7 @@ size_t getKBUsedAll (soci::session& s)
|
||||
{
|
||||
if (! getConnection (s))
|
||||
Throw<std::logic_error> ("No connection found.");
|
||||
return static_cast <size_t> (sqlite_api::sqlite3_memory_used () / 1024);
|
||||
return static_cast <size_t> (sqlite_api::sqlite3_memory_used () / kilobytes(1));
|
||||
}
|
||||
|
||||
size_t getKBUsedDB (soci::session& s)
|
||||
@@ -140,7 +141,7 @@ size_t getKBUsedDB (soci::session& s)
|
||||
int cur = 0, hiw = 0;
|
||||
sqlite_api::sqlite3_db_status (
|
||||
conn, SQLITE_DBSTATUS_CACHE_USED, &cur, &hiw, 0);
|
||||
return cur / 1024;
|
||||
return cur / kilobytes(1);
|
||||
}
|
||||
Throw<std::logic_error> ("");
|
||||
return 0; // Silence compiler warning.
|
||||
@@ -159,7 +160,6 @@ void convert (soci::blob& from, std::string& to)
|
||||
std::vector<std::uint8_t> tmp;
|
||||
convert (from, tmp);
|
||||
to.assign (tmp.begin (), tmp.end());
|
||||
|
||||
}
|
||||
|
||||
void convert (std::vector<std::uint8_t> const& from, soci::blob& to)
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
//==============================================================================
|
||||
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/crypto/csprng.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <array>
|
||||
@@ -55,7 +56,7 @@ csprng_engine::load_state (std::string const& file)
|
||||
if (!file.empty())
|
||||
{
|
||||
std::lock_guard<std::mutex> lock (mutex_);
|
||||
RAND_load_file (file.c_str (), 1024);
|
||||
RAND_load_file (file.c_str (), kilobytes(1));
|
||||
RAND_write_file (file.c_str ());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#ifndef RIPPLE_NET_HTTPCLIENT_H_INCLUDED
|
||||
#define RIPPLE_NET_HTTPCLIENT_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/core/Config.h>
|
||||
#include <boost/asio/io_service.hpp>
|
||||
#include <boost/asio/streambuf.hpp>
|
||||
@@ -34,10 +35,7 @@ class HTTPClient
|
||||
public:
|
||||
explicit HTTPClient() = default;
|
||||
|
||||
enum
|
||||
{
|
||||
maxClientHeaderBytes = 32 * 1024
|
||||
};
|
||||
static constexpr auto maxClientHeaderBytes = kilobytes(32);
|
||||
|
||||
static void initializeSSLContext (Config const& config, beast::Journal j);
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include <ripple/app/main/Application.h>
|
||||
#include <ripple/basics/StringUtilities.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/net/RPCCall.h>
|
||||
#include <ripple/net/RPCErr.h>
|
||||
#include <ripple/basics/base64.h>
|
||||
@@ -1534,7 +1535,7 @@ void fromNetwork (
|
||||
|
||||
// Number of bytes to try to receive if no
|
||||
// Content-Length header received
|
||||
const int RPC_REPLY_MAX_BYTES (256*1024*1024);
|
||||
constexpr auto RPC_REPLY_MAX_BYTES = megabytes(256);
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
auto constexpr RPC_NOTIFY = 10min;
|
||||
|
||||
@@ -40,14 +40,10 @@ class NuDBBackend
|
||||
: public Backend
|
||||
{
|
||||
public:
|
||||
enum
|
||||
{
|
||||
// This needs to be tuned for the
|
||||
// distribution of data sizes.
|
||||
arena_alloc_size = 16 * 1024 * 1024,
|
||||
|
||||
currentType = 1
|
||||
};
|
||||
// This needs to be tuned for the
|
||||
// distribution of data sizes.
|
||||
static constexpr std::size_t arena_alloc_size = megabytes(16);
|
||||
static constexpr std::size_t currentType = 1;
|
||||
|
||||
beast::Journal j_;
|
||||
size_t const keyBytes_;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#if RIPPLE_ROCKSDB_AVAILABLE
|
||||
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/core/Config.h> // VFALCO Bad dependency
|
||||
#include <ripple/nodestore/Factory.h>
|
||||
#include <ripple/nodestore/Manager.h>
|
||||
@@ -117,7 +118,7 @@ public:
|
||||
|
||||
if (keyValues.exists ("cache_mb"))
|
||||
table_options.block_cache = rocksdb::NewLRUCache (
|
||||
get<int>(keyValues, "cache_mb") * 1024L * 1024L);
|
||||
get<int>(keyValues, "cache_mb") * megabytes(1));
|
||||
|
||||
if (auto const v = get<int>(keyValues, "filter_bits"))
|
||||
{
|
||||
@@ -131,7 +132,7 @@ public:
|
||||
|
||||
if (keyValues.exists ("file_size_mb"))
|
||||
{
|
||||
m_options.target_file_size_base = 1024 * 1024 * get<int>(keyValues,"file_size_mb");
|
||||
m_options.target_file_size_base = megabytes(1) * get<int>(keyValues,"file_size_mb");
|
||||
m_options.max_bytes_for_level_base = 5 * m_options.target_file_size_base;
|
||||
m_options.write_buffer_size = 2 * m_options.target_file_size_base;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#if RIPPLE_ROCKSDB_AVAILABLE
|
||||
|
||||
#include <ripple/basics/contract.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <ripple/core/Config.h> // VFALCO Bad dependency
|
||||
#include <ripple/nodestore/Factory.h>
|
||||
#include <ripple/nodestore/Manager.h>
|
||||
@@ -109,7 +110,7 @@ public:
|
||||
"Missing path in RocksDBQuickFactory backend");
|
||||
|
||||
// Defaults
|
||||
std::uint64_t budget = 512 * 1024 * 1024; // 512MB
|
||||
std::uint64_t budget = megabytes(512);
|
||||
std::string style("level");
|
||||
std::uint64_t threads=4;
|
||||
|
||||
@@ -128,7 +129,7 @@ public:
|
||||
m_options.OptimizeUniversalStyleCompaction(budget);
|
||||
|
||||
if (style == "point")
|
||||
m_options.OptimizeForPointLookup(budget / 1024 / 1024); // In MB
|
||||
m_options.OptimizeForPointLookup(budget / megabytes(1)); // In MB
|
||||
|
||||
m_options.IncreaseParallelism(threads);
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#define RIPPLE_PROTOCOL_PROTOCOL_H_INCLUDED
|
||||
|
||||
#include <ripple/basics/base_uint.h>
|
||||
#include <ripple/basics/ByteUtilities.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace ripple {
|
||||
@@ -38,7 +39,7 @@ namespace ripple {
|
||||
std::size_t constexpr txMinSizeBytes = 32;
|
||||
|
||||
/** Largest legal byte size of a transaction. */
|
||||
std::size_t constexpr txMaxSizeBytes = 1024 * 1024;
|
||||
std::size_t constexpr txMaxSizeBytes = megabytes(1);
|
||||
|
||||
/** The maximum number of unfunded offers to delete at once */
|
||||
std::size_t constexpr unfundedOfferRemoveLimit = 1000;
|
||||
|
||||
Reference in New Issue
Block a user