mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Improve NuDB block size configuration with early return pattern and 32K support
- Implement early return pattern in parseBlockSize function to reduce nesting - Fix unqualified assignment by using properly scoped const variable - Decreased maximum block size limit from 64K to 32K (32768 bytes) - Update configuration documentation to reflect correct 32K maximum - Add guidance for 32K block size usage in high-performance scenarios - Apply clang-format fixes to resolve CI formatting checks This enhances NuDB performance configurability while maintaining code quality and following modern C++ best practices. The 32K limit reflects the actual maximum supported by NuDB as confirmed by testing.
This commit is contained in:
@@ -978,7 +978,7 @@
|
||||
# Optional keys for NuDB only:
|
||||
#
|
||||
# nudb_block_size Block size in bytes for NuDB storage.
|
||||
# Must be a power of 2 between 4096 and 65536.
|
||||
# Must be a power of 2 between 4096 and 32768.
|
||||
# Default is 4096.
|
||||
#
|
||||
# This parameter controls the fundamental storage unit
|
||||
@@ -997,10 +997,10 @@
|
||||
# alignment. Can reduce metadata overhead for large
|
||||
# databases.
|
||||
#
|
||||
# - 32768-65536 bytes: Suitable for specialized
|
||||
# high-throughput scenarios with very fast storage.
|
||||
# May increase memory usage and reduce efficiency
|
||||
# for smaller databases.
|
||||
# - 32768 bytes (32K): Maximum supported block size
|
||||
# for high-performance scenarios with very fast
|
||||
# storage. May increase memory usage and reduce
|
||||
# efficiency for smaller databases.
|
||||
#
|
||||
# Note: This setting cannot be changed after database
|
||||
# creation without rebuilding the entire database.
|
||||
|
||||
@@ -370,38 +370,40 @@ private:
|
||||
{
|
||||
std::size_t blockSize = 4096; // Default 4K
|
||||
std::string blockSizeStr;
|
||||
|
||||
if (get_if_exists(keyValues, "nudb_block_size", blockSizeStr))
|
||||
|
||||
if (!get_if_exists(keyValues, "nudb_block_size", blockSizeStr))
|
||||
{
|
||||
try
|
||||
{
|
||||
blockSize = beast::lexicalCastThrow<std::size_t>(blockSizeStr);
|
||||
|
||||
// Validate: must be power of 2 between 4K and 64K
|
||||
if (blockSize < 4096 || blockSize > 65536 ||
|
||||
(blockSize & (blockSize - 1)) != 0)
|
||||
{
|
||||
JLOG(journal.warn())
|
||||
<< "Invalid nudb_block_size: " << blockSize
|
||||
<< ". Must be power of 2 between 4096 and 65536. Using default 4096.";
|
||||
blockSize = 4096;
|
||||
}
|
||||
else
|
||||
{
|
||||
JLOG(journal.info())
|
||||
<< "Using custom NuDB block size: " << blockSize << " bytes";
|
||||
}
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
JLOG(journal.warn())
|
||||
<< "Invalid nudb_block_size value: " << blockSizeStr
|
||||
<< ". Using default 4096. Error: " << e.what();
|
||||
blockSize = 4096;
|
||||
}
|
||||
return blockSize; // Early return with default
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
std::size_t const parsedBlockSize =
|
||||
beast::lexicalCastThrow<std::size_t>(blockSizeStr);
|
||||
|
||||
// Validate: must be power of 2 between 4K and 32K
|
||||
if (parsedBlockSize < 4096 || parsedBlockSize > 32768 ||
|
||||
(parsedBlockSize & (parsedBlockSize - 1)) != 0)
|
||||
{
|
||||
JLOG(journal.warn())
|
||||
<< "Invalid nudb_block_size: " << parsedBlockSize
|
||||
<< ". Must be power of 2 between 4096 and 32768. Using "
|
||||
"default 4096.";
|
||||
return 4096;
|
||||
}
|
||||
|
||||
JLOG(journal.info())
|
||||
<< "Using custom NuDB block size: " << parsedBlockSize
|
||||
<< " bytes";
|
||||
return parsedBlockSize;
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
JLOG(journal.warn())
|
||||
<< "Invalid nudb_block_size value: " << blockSizeStr
|
||||
<< ". Using default 4096. Error: " << e.what();
|
||||
return 4096;
|
||||
}
|
||||
|
||||
return blockSize;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user