From cb2975dd413de7e5940516268bfcf2190564f5cc Mon Sep 17 00:00:00 2001 From: CJ Cobb Date: Tue, 13 Jul 2021 20:27:26 +0000 Subject: [PATCH] smaller partitions on keys table --- src/backend/CassandraBackend.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/backend/CassandraBackend.cpp b/src/backend/CassandraBackend.cpp index 439caa7f9..9f2fb5c64 100644 --- a/src/backend/CassandraBackend.cpp +++ b/src/backend/CassandraBackend.cpp @@ -407,10 +407,11 @@ CassandraBackend::fetchAllTransactionHashesInLedger( LedgerPage CassandraBackend::doFetchLedgerPage( - std::optional const& cursor, + std::optional const& cursorIn, std::uint32_t ledgerSequence, std::uint32_t limit) const { + std::optional cursor = cursorIn; auto index = getKeyIndexOfSeq(ledgerSequence); if (!index) return {}; @@ -423,13 +424,13 @@ CassandraBackend::doFetchLedgerPage( << __func__ << " - Cursor = " << ripple::strHex(*cursor); CassandraStatement statement{selectKeys_}; statement.bindInt(index->keyIndex); - if (cursor) - statement.bindBytes(*cursor); - else + if (!cursor) { ripple::uint256 zero; - statement.bindBytes(zero); + cursor = zero; } + statement.bindBytes(cursor->data(), 1); + statement.bindBytes(*cursor); statement.bindUInt(limit + 1); CassandraResult result = executeSyncRead(statement); if (!!result) @@ -447,6 +448,12 @@ CassandraBackend::doFetchLedgerPage( page.cursor = keys.back(); ++(*page.cursor); } + else if (cursor->data()[0] != 0xFF) + { + ripple::uint256 zero; + zero.data()[0] = cursor->data()[0] + 1; + page.cursor = zero; + } auto objects = fetchLedgerObjects(keys, ledgerSequence); if (objects.size() != keys.size()) throw std::runtime_error("Mismatch in size of objects and keys"); @@ -523,6 +530,7 @@ CassandraBackend::writeKeys( auto& [lgrSeq, key] = params.data; CassandraStatement statement{insertKey_}; statement.bindInt(lgrSeq); + statement.bindBytes(key.data(), 1); statement.bindBytes(key); return statement; }; @@ -974,8 +982,8 @@ CassandraBackend::open(bool readOnly) query.str(""); query << "CREATE TABLE IF NOT EXISTS " << tablePrefix << "keys" - << " ( sequence bigint, key blob, PRIMARY KEY " - "(sequence, key))" + << " ( sequence bigint, first_byte blob, key blob, PRIMARY KEY " + "((sequence,first_byte), key))" " WITH default_time_to_live = " << std::to_string(keysTtl); if (!executeSimpleStatement(query.str())) @@ -1072,13 +1080,14 @@ CassandraBackend::open(bool readOnly) query.str(""); query << "INSERT INTO " << tablePrefix << "keys" - << " (sequence, key) VALUES (?, ?)"; + << " (sequence,first_byte, key) VALUES (?, ?, ?)"; if (!insertKey_.prepareStatement(query, session_.get())) continue; query.str(""); query << "SELECT key FROM " << tablePrefix << "keys" - << " WHERE sequence = ? AND key >= ? ORDER BY key ASC LIMIT ?"; + << " WHERE sequence = ? AND first_byte = ? AND key >= ? ORDER BY " + "key ASC LIMIT ?"; if (!selectKeys_.prepareStatement(query, session_.get())) continue;