Skip to content

Commit

Permalink
[fix] Set fixed iterations count for the flacky benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
reindexer-bot committed Dec 5, 2023
1 parent 8fe18b8 commit 4d72649
Show file tree
Hide file tree
Showing 124 changed files with 1,668 additions and 1,103 deletions.
1 change: 0 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: true
PointerAlignment: Left
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
Expand Down
27 changes: 15 additions & 12 deletions cpp_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,28 @@ include (TargetArch)
target_architecture(COMPILER_TARGET_ARCH)

# Configure compile options
string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
string(REPLACE "-O2" "-O3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE "-O2" "-O3" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
if (NOT ${COMPILER_TARGET_ARCH} STREQUAL "e2k")
string(REPLACE "-g" "-g1" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
else()
string(REPLACE "-g" "-g0" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif()

if (MSVC)
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g1")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g1")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O2 -DNDEBUG")
else ()
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g1")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g1")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
endif ()
if (${COMPILER_TARGET_ARCH} STREQUAL "e2k")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g0")
add_definitions(-D__E2K__)
add_definitions(-D__LCC__)
endif()
endif ()

if (NOT MSVC AND NOT APPLE)
check_linker_flag (-gz cxx_linker_supports_gz)
if (cxx_linker_supports_gz)
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -gz")
endif ()
set (CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} -gz")
endif ()
endif ()

if (MSVC)
Expand Down
3 changes: 2 additions & 1 deletion cpp_src/client/coroqueryresults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,10 @@ Item CoroQueryResults::Iterator::GetItem() {
if (err.ok()) {
return item;
}
return Item();
} catch (const Error &) {
return Item();
}
return Item();
}

int64_t CoroQueryResults::Iterator::GetLSN() {
Expand Down
3 changes: 2 additions & 1 deletion cpp_src/client/queryresults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,10 @@ Item QueryResults::Iterator::GetItem() {
if (err.ok()) {
return item;
}
return Item();
} catch (const Error &) {
return Item();
}
return Item();
}

int64_t QueryResults::Iterator::GetLSN() {
Expand Down
2 changes: 2 additions & 0 deletions cpp_src/client/resultserializer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void ResultSerializer::GetRawQueryParams(ResultSerializer::QueryParams& ret, con
case QueryResultExplain:
ret.explainResults = std::string(data);
break;
default:
throw Error(errLogic, "Unexpected Query tag: %d", tag);
}
}
}
Expand Down
48 changes: 39 additions & 9 deletions cpp_src/client/rpcclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <functional>
#include "client/itemimpl.h"
#include "core/namespacedef.h"
#include "core/schema.h"
#include "gason/gason.h"
#include "tools/cpucheck.h"
#include "tools/errors.h"
Expand Down Expand Up @@ -98,6 +99,7 @@ void RPCClient::run(size_t thIdx) {

workers_[thIdx].stop_.start();
delayedUpdates_.clear();
serialDelays_ = 0;

for (size_t i = thIdx; int(i) < config_.ConnPoolSize; i += config_.WorkerThreads) {
connections_[i].reset(new cproto::ClientConnection(workers_[thIdx].loop_, &connectData_,
Expand Down Expand Up @@ -717,21 +719,39 @@ void RPCClient::onUpdates(net::cproto::RPCAnswer& ans, cproto::ClientConnection*
// If tagsMatcher has been updated but there is no bundled tagsMatcher in cjson
// then we need to ask server to send tagsMatcher.

++serialDelays_;
// Delay this update and all the further updates until we get responce from server.
ans.EnsureHold();
delayedUpdates_.emplace_back(std::move(ans));

QueryResults* qr = new QueryResults;
Select(Query(std::string(nsName)).Limit(0), *qr,
InternalRdxContext(nullptr,
[=](const Error& err) {
delete qr;
// If there are delayed updates then send them to client
auto uq = std::move(delayedUpdates_);
delayedUpdates_.clear();
if (err.ok())
for (auto& a1 : uq) onUpdates(a1, conn);
}),
InternalRdxContext(
nullptr,
[this, qr, conn](const Error& err) {
delete qr;
// If there are delayed updates then send them to client
auto uq = std::move(delayedUpdates_);
delayedUpdates_.clear();

if (!err.ok() || serialDelays_ > 1) {
// This update was already dealyed, but was not able to synchronize tagsmatcher.
// Such situation usually means, that master's namespace was recreated and must be synchronized via force
// sync.
// Current fix is suboptimal and in some cases even incorrect (but still better, than previous
// implementation) - proper fix requires some versioning info about namespaces, which exists
// in v4 only
std::string_view nsName(std::string_view(uq.front().GetArgs(1)[1]));
logPrintf(
LogWarning,
"[repl:%s] Unable to sync tags matcher via online-replication (err: '%s'). Calling UpdatesLost fallback",
nsName, err.what());
serialDelays_ = 0;
observers_.OnUpdatesLost(nsName);
} else {
for (auto& a1 : uq) onUpdates(a1, conn);
}
}),
conn);
return;
} else {
Expand All @@ -748,7 +768,17 @@ void RPCClient::onUpdates(net::cproto::RPCAnswer& ans, cproto::ClientConnection*
ns->tagsMatcher_.deserialize(rdser, wrec.itemModify.tmVersion, ns->tagsMatcher_.stateToken());
}
}
} else if (wrec.type == WalTagsMatcher) {
TagsMatcher tm;
Serializer ser(wrec.data.data(), wrec.data.size());
const auto version = ser.GetVarint();
const auto stateToken = ser.GetVarint();
tm.deserialize(ser, version, stateToken);
auto ns = getNamespace(nsName);
std::lock_guard lck(ns->lck_);
ns->tagsMatcher_ = std::move(tm);
}
serialDelays_ = 0;
observers_.OnWALUpdate(LSNPair(lsn, originLSN), nsName, wrec);
}

Expand Down
2 changes: 2 additions & 0 deletions cpp_src/client/rpcclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class RPCClient {
ev::async stop_;
std::atomic_bool running;
};

Error selectImpl(std::string_view query, QueryResults &result, cproto::ClientConnection *, seconds netTimeout,
const InternalRdxContext &ctx);
Error selectImpl(const Query &query, QueryResults &result, cproto::ClientConnection *, seconds netTimeout,
Expand Down Expand Up @@ -122,6 +123,7 @@ class RPCClient {
UpdatesObservers observers_;
std::atomic<net::cproto::ClientConnection *> updatesConn_;
std::vector<net::cproto::RPCAnswer> delayedUpdates_;
uint64_t serialDelays_ = 0;
cproto::ClientConnection::ConnectData connectData_;
};

Expand Down
195 changes: 195 additions & 0 deletions cpp_src/cmd/reindexer_server/test/test_storage_compatibility.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
#!/bin/bash
# Task: https://github.com/restream/reindexer/-/issues/1188
set -e

function KillAndRemoveServer {
local pid=$1
kill $pid
wait $pid
yum remove -y 'reindexer*' > /dev/null
}

function WaitForDB {
# wait until DB is loaded
set +e # disable "exit on error" so the script won't stop when DB's not loaded yet
is_connected=$(reindexer_tool --dsn $ADDRESS --command '\databases list');
while [[ $is_connected != "test" ]]
do
sleep 2
is_connected=$(reindexer_tool --dsn $ADDRESS --command '\databases list');
done
set -e
}

function CompareNamespacesLists {
local ns_list_actual=$1
local ns_list_expected=$2
local pid=$3

diff=$(echo ${ns_list_actual[@]} ${ns_list_expected[@]} | tr ' ' '\n' | sort | uniq -u) # compare in any order
if [ "$diff" == "" ]; then
echo "## PASS: namespaces list not changed"
else
echo "##### FAIL: namespaces list was changed"
echo "expected: $ns_list_expected"
echo "actual: $ns_list_actual"
KillAndRemoveServer $pid;
exit 1
fi
}

function CompareMemstats {
local actual=$1
local expected=$2
local pid=$3
diff=$(echo ${actual[@]} ${expected[@]} | tr ' ' '\n' | sed 's/\(.*\),$/\1/' | sort | uniq -u) # compare in any order
if [ "$diff" == "" ]; then
echo "## PASS: memstats not changed"
else
echo "##### FAIL: memstats was changed"
echo "expected: $expected"
echo "actual: $actual"
KillAndRemoveServer $pid;
exit 1
fi
}


RX_SERVER_CURRENT_VERSION_RPM="$(basename build/reindexer-*server*.rpm)"
VERSION_FROM_RPM=$(echo "$RX_SERVER_CURRENT_VERSION_RPM" | grep -o '.*server-..')
VERSION=$(echo ${VERSION_FROM_RPM: -2:1}) # one-digit version

echo "## choose latest release rpm file"
if [ $VERSION == 3 ]; then
LATEST_RELEASE=$(python3 cpp_src/cmd/reindexer_server/test/get_last_rx_version.py -v 3)
namespaces_list_expected=$'purchase_options_ext_dict\nchild_account_recommendations\n#config\n#activitystats\nradio_channels\ncollections\n#namespaces\nwp_imports_tasks\nepg_genres\nrecom_media_items_personal\nrecom_epg_archive_default\n#perfstats\nrecom_epg_live_default\nmedia_view_templates\nasset_video_servers\nwp_tasks_schedule\nadmin_roles\n#clientsstats\nrecom_epg_archive_personal\nrecom_media_items_similars\nmenu_items\naccount_recommendations\nkaraoke_items\nmedia_items\nbanners\n#queriesperfstats\nrecom_media_items_default\nrecom_epg_live_personal\nservices\n#memstats\nchannels\nmedia_item_recommendations\nwp_tasks_tasks\nepg'
elif [ $VERSION == 4 ]; then
LATEST_RELEASE=$(python3 cpp_src/cmd/reindexer_server/test/get_last_rx_version.py -v 4)
# replicationstats ns added for v4
namespaces_list_expected=$'purchase_options_ext_dict\nchild_account_recommendations\n#config\n#activitystats\n#replicationstats\nradio_channels\ncollections\n#namespaces\nwp_imports_tasks\nepg_genres\nrecom_media_items_personal\nrecom_epg_archive_default\n#perfstats\nrecom_epg_live_default\nmedia_view_templates\nasset_video_servers\nwp_tasks_schedule\nadmin_roles\n#clientsstats\nrecom_epg_archive_personal\nrecom_media_items_similars\nmenu_items\naccount_recommendations\nkaraoke_items\nmedia_items\nbanners\n#queriesperfstats\nrecom_media_items_default\nrecom_epg_live_personal\nservices\n#memstats\nchannels\nmedia_item_recommendations\nwp_tasks_tasks\nepg'
else
echo "Unknown version"
exit 1
fi

echo "## downloading latest release rpm file: $LATEST_RELEASE"
curl "http://repo.itv.restr.im/itv-api-ng/7/x86_64/$LATEST_RELEASE" --output $LATEST_RELEASE;
echo "## downloading example DB"
curl "https://git.restream.ru/MaksimKravchuk/reindexer_testdata/-/raw/master/big.zip" --output big.zip;
unzip -o big.zip # unzips into mydb_big.rxdump;

ADDRESS="cproto://127.0.0.1:6534/"
DB_NAME="test"

memstats_expected=$'[
{"replication":{"data_hash":24651210926,"data_count":3}},
{"replication":{"data_hash":6252344969,"data_count":1}},
{"replication":{"data_hash":37734732881,"data_count":28}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":1024095024522,"data_count":1145}},
{"replication":{"data_hash":8373644068,"data_count":1315}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":7404222244,"data_count":97}},
{"replication":{"data_hash":94132837196,"data_count":4}},
{"replication":{"data_hash":1896088071,"data_count":2}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":-672103903,"data_count":33538}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":6833710705,"data_count":1}},
{"replication":{"data_hash":5858155773472,"data_count":4500}},
{"replication":{"data_hash":-473221280268823592,"data_count":65448}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":8288213744,"data_count":3}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":0,"data_count":0}},
{"replication":{"data_hash":354171024786967,"data_count":3941}},
{"replication":{"data_hash":-6520334670,"data_count":35886}},
{"replication":{"data_hash":112772074632,"data_count":281}},
{"replication":{"data_hash":-12679568198538,"data_count":1623116}}
]
Returned 27 rows'

echo "##### Forward compatibility test #####"

DB_PATH=$(pwd)"/rx_db"

echo "Database: "$DB_PATH

echo "## installing latest release: $LATEST_RELEASE"
yum install -y $LATEST_RELEASE > /dev/null;
# run RX server with disabled logging
reindexer_server -l warning --httplog=none --rpclog=none --db $DB_PATH &
server_pid=$!
sleep 2;

reindexer_tool --dsn $ADDRESS$DB_NAME -f mydb_big.rxdump --createdb;
sleep 1;

namespaces_1=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command '\namespaces list');
echo $namespaces_1;
CompareNamespacesLists "${namespaces_1[@]}" "${namespaces_list_expected[@]}" $server_pid;

memstats_1=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command 'select replication.data_hash, replication.data_count from #memstats');
CompareMemstats "${memstats_1[@]}" "${memstats_expected[@]}" $server_pid;

KillAndRemoveServer $server_pid;

echo "## installing current version: $RX_SERVER_CURRENT_VERSION_RPM"
yum install -y build/*.rpm > /dev/null;
reindexer_server -l0 --corelog=none --httplog=none --rpclog=none --db $DB_PATH &
server_pid=$!
sleep 2;

WaitForDB

namespaces_2=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command '\namespaces list');
echo $namespaces_2;
CompareNamespacesLists "${namespaces_2[@]}" "${namespaces_1[@]}" $server_pid;

memstats_2=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command 'select replication.data_hash, replication.data_count from #memstats');
CompareMemstats "${memstats_2[@]}" "${memstats_1[@]}" $server_pid;

KillAndRemoveServer $server_pid;
rm -rf $DB_PATH;
sleep 1;

echo "##### Backward compatibility test #####"

echo "## installing current version: $RX_SERVER_CURRENT_VERSION_RPM"
yum install -y build/*.rpm > /dev/null;
reindexer_server -l warning --httplog=none --rpclog=none --db $DB_PATH &
server_pid=$!
sleep 2;

reindexer_tool --dsn $ADDRESS$DB_NAME -f mydb_big.rxdump --createdb;
sleep 1;

namespaces_3=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command '\namespaces list');
echo $namespaces_3;
CompareNamespacesLists "${namespaces_3[@]}" "${namespaces_list_expected[@]}" $server_pid;

memstats_3=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command 'select replication.data_hash, replication.data_count from #memstats');
CompareMemstats "${memstats_3[@]}" "${memstats_expected[@]}" $server_pid;

KillAndRemoveServer $server_pid;

echo "## installing latest release: $LATEST_RELEASE"
yum install -y $LATEST_RELEASE > /dev/null;
reindexer_server -l warning --httplog=none --rpclog=none --db $DB_PATH &
server_pid=$!
sleep 2;

WaitForDB

namespaces_4=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command '\namespaces list');
echo $namespaces_4;
CompareNamespacesLists "${namespaces_4[@]}" "${namespaces_3[@]}" $server_pid;

memstats_4=$(reindexer_tool --dsn $ADDRESS$DB_NAME --command 'select replication.data_hash, replication.data_count from #memstats');
CompareMemstats "${memstats_4[@]}" "${memstats_3[@]}" $server_pid;

KillAndRemoveServer $server_pid;
rm -rf $DB_PATH;
Loading

0 comments on commit 4d72649

Please sign in to comment.