Skip to content

Commit

Permalink
Merge branch '1490_fix_join_fields_access' into 1488_1317_qe_refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
reindexer-bot committed Aug 18, 2023
1 parent 6d4504f commit c38cc13
Show file tree
Hide file tree
Showing 81 changed files with 3,002 additions and 1,783 deletions.
5 changes: 3 additions & 2 deletions cpp_src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -695,15 +695,16 @@ if (NOT WIN32)
SET(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME "server")
SET(DIST_INCLUDE_FILES
"tools/errors.h" "tools/serializer.h" "tools/varint.h" "tools/stringstools.h" "tools/customhash.h" "tools/assertrx.h" "tools/jsonstring.h"
"tools/verifying_updater.h"
"core/reindexer.h" "core/type_consts.h" "core/item.h" "core/payload/payloadvalue.h" "core/payload/payloadiface.h" "core/indexopts.h"
"core/namespacedef.h" "core/keyvalue/variant.h" "core/keyvalue/geometry.h" "core/sortingprioritiestable.h"
"core/rdxcontext.h" "core/activity_context.h" "core/type_consts_helpers.h" "core/payload/fieldsset.h" "core/payload/payloadtype.h"
"core/cbinding/reindexer_c.h" "core/cbinding/reindexer_ctypes.h" "core/transaction.h" "core/payload/payloadfieldtype.h" "core/reindexerconfig.h"
"core/query/query.h" "core/query/queryentry.h" "core/queryresults/queryresults.h" "core/indexdef.h" "core/queryresults/aggregationresult.h"
"core/queryresults/itemref.h" "core/namespace/stringsholder.h" "core/keyvalue/key_string.h" "core/key_value_type.h" "core/keyvalue/uuid.h"
"core/expressiontree.h" "core/lsn.h" "core/cjson/tagspath.h" "core/cjson/ctag.h"
"estl/cow.h" "estl/overloaded.h" "estl/one_of.h" "estl/h_vector.h" "estl/mutex.h" "estl/intrusive_ptr.h" "estl/trivial_reverse_iterator.h"
"estl/span.h" "estl/chunk.h" "estl/fast_hash_traits.h" "estl/debug_macros.h" "estl/defines.h"
"estl/cow.h" "estl/overloaded.h" "estl/one_of.h" "estl/h_vector.h" "estl/mutex.h" "estl/intrusive_ptr.h" "estl/trivial_reverse_iterator.h"
"estl/span.h" "estl/chunk.h" "estl/fast_hash_traits.h" "estl/debug_macros.h" "estl/defines.h"
"client/reindexer.h" "client/item.h" "client/reindexerconfig.h" "client/queryresults.h" "client/resultserializer.h"
"client/internalrdxcontext.h" "client/transaction.h"
"client/cororeindexer.h" "client/coroqueryresults.h" "client/corotransaction.h"
Expand Down
194 changes: 194 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,194 @@
#!/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

if [ $VERSION == 3 ]; then
LATEST_RELEASE=$(curl -s http://repo.restream.ru/itv-api-ng/7/x86_64/ | grep -o '>reindexer-server-.*.rpm' | tail -n1 | cut -c 2-)
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=$(curl -s http://repo.restream.ru/itv-api-ng/7/x86_64/ | grep -o '>reindexer-4-server-.*.rpm' | tail -n1 | cut -c 2-)
# 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;
4 changes: 2 additions & 2 deletions cpp_src/cmd/reindexer_tool/commandsexecutor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,8 @@ Error CommandsExecutor<DBInterface>::commandBench(const std::string& command) {
LineParser parser(command);
parser.NextToken();

int benchTime = reindexer::stoi(parser.NextToken());
if (benchTime == 0) benchTime = kBenchDefaultTime;
const std::string_view benchTimeToken = parser.NextToken();
const int benchTime = benchTimeToken.empty() ? kBenchDefaultTime : reindexer::stoi(benchTimeToken);

db().DropNamespace(kBenchNamespace);

Expand Down
4 changes: 2 additions & 2 deletions cpp_src/core/cjson/fieldextractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FieldsExtractor {
};

FieldsExtractor() = default;
FieldsExtractor(VariantArray *va, KeyValueType expectedType, int expectedPathDepth, FieldsSet *filter = nullptr,
FieldsExtractor(VariantArray *va, KeyValueType expectedType, int expectedPathDepth, const FieldsSet *filter,
FieldParams *params = nullptr) noexcept
: values_(va), expectedType_(expectedType), expectedPathDepth_(expectedPathDepth), filter_(filter), params_(params) {}
FieldsExtractor(FieldsExtractor &&other) = default;
Expand Down Expand Up @@ -165,7 +165,7 @@ class FieldsExtractor {
VariantArray *values_ = nullptr;
KeyValueType expectedType_{KeyValueType::Undefined{}};
int expectedPathDepth_ = 0;
FieldsSet *filter_;
const FieldsSet *filter_;
FieldParams *params_;
};

Expand Down
33 changes: 18 additions & 15 deletions cpp_src/core/cjson/tagsmatcherimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <sstream>
#include <string>

#include "core/keyvalue/key_string.h"
#include "core/payload/payloadtype.h"
#include "core/payload/payloadtypeimpl.h"
#include "ctag.h"
Expand Down Expand Up @@ -75,25 +74,29 @@ class TagsMatcherImpl {
if (content == "*"sv) {
node.MarkAllItems(true);
} else {
int index = stoi(content);
if (index == 0 && content != "0"sv && ev) {
VariantArray values = ev(content);
if (values.size() != 1) {
throw Error(errParams, "Index expression_ has wrong syntax: '%s'", content);
auto index = try_stoi(content);
if (!index) {
if (ev) {
VariantArray values = ev(content);
if (values.size() != 1) {
throw Error(errParams, "Index expression_ has wrong syntax: '%s'", content);
}
values.front().Type().EvaluateOneOf(
[](OneOf<KeyValueType::Double, KeyValueType::Int, KeyValueType::Int64>) noexcept {},
[&](OneOf<KeyValueType::Bool, KeyValueType::String, KeyValueType::Tuple, KeyValueType::Composite,
KeyValueType::Null, KeyValueType::Undefined, KeyValueType::Uuid>) {
throw Error(errParams, "Wrong type of index: '%s'", content);
});
node.SetExpression(content);
index = values.front().As<int>();
} else {
throw Error(errParams, "Can't convert '%s' to number", content);
}
values.front().Type().EvaluateOneOf(
[](OneOf<KeyValueType::Double, KeyValueType::Int, KeyValueType::Int64>) noexcept {},
[&](OneOf<KeyValueType::Bool, KeyValueType::String, KeyValueType::Tuple, KeyValueType::Composite,
KeyValueType::Null, KeyValueType::Undefined, KeyValueType::Uuid>) {
throw Error(errParams, "Wrong type of index: '%s'", content);
});
node.SetExpression(content);
index = values.front().As<int>();
}
if (index < 0) {
throw Error(errLogic, "Array index value cannot be negative");
}
node.SetIndex(index);
node.SetIndex(*index);
}
field = field.substr(0, openBracketPos);
}
Expand Down
6 changes: 0 additions & 6 deletions cpp_src/core/comparator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ void Comparator::Bind(const PayloadType &type, int field) {
}
}

void Comparator::BindEqualPosition(int field, const VariantArray &val, CondType cond) { cmpEqualPosition.BindField(field, val, cond); }

void Comparator::BindEqualPosition(const TagsPath &tagsPath, const VariantArray &val, CondType cond) {
cmpEqualPosition.BindField(tagsPath, val, cond);
}

bool Comparator::isNumericComparison(const VariantArray &values) const {
if (valuesType_.Is<KeyValueType::Undefined>() || values.empty()) return false;
const KeyValueType keyType{values.front().Type()};
Expand Down
8 changes: 5 additions & 3 deletions cpp_src/core/comparator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class Comparator : public ComparatorVars {
bool Compare(const PayloadValue &lhs, int rowId);
void ExcludeDistinct(const PayloadValue &, int rowId);
void Bind(const PayloadType &type, int field);
void BindEqualPosition(int field, const VariantArray &val, CondType cond);
void BindEqualPosition(const TagsPath &tagsPath, const VariantArray &val, CondType cond);
template <typename F>
void BindEqualPosition(F &&field, const VariantArray &val, CondType cond) {
cmpEqualPosition.BindField(std::forward<F>(field), val, cond);
}
void ClearDistinct() {
cmpInt.ClearDistinct();
cmpBool.ClearDistinct();
Expand Down Expand Up @@ -116,7 +118,7 @@ class Comparator : public ComparatorVars {
ComparatorImpl<PayloadValue> cmpComposite;
ComparatorImpl<Point> cmpGeom;
ComparatorImpl<Uuid> cmpUuid;
CompositeArrayComparator cmpEqualPosition;
EqualPositionComparator cmpEqualPosition;
KeyValueType valuesType_{KeyValueType::Undefined{}};
};

Expand Down
40 changes: 16 additions & 24 deletions cpp_src/core/compositearraycomparator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,29 @@
#include <limits.h>
namespace reindexer {

CompositeArrayComparator::CompositeArrayComparator() {}
void EqualPositionComparator::BindField(int field, const VariantArray &values, CondType cond) { bindField(field, values, cond); }

void CompositeArrayComparator::BindField(int field, const VariantArray &values, CondType condType) {
void EqualPositionComparator::BindField(const FieldsPath &fieldPath, const VariantArray &values, CondType cond) {
bindField(fieldPath, values, cond);
}

template <typename F>
void EqualPositionComparator::bindField(F field, const VariantArray &values, CondType cond) {
fields_.push_back(field);
Context &ctx = ctx_.emplace_back();

ctx.cond = condType;
ctx.cmpBool.SetValues(condType, values);
ctx.cmpInt.SetValues(condType, values);
ctx.cmpInt64.SetValues(condType, values);
ctx.cmpString.SetValues(condType, values, CollateOpts());
ctx.cmpDouble.SetValues(condType, values);
ctx.cmpUuid.SetValues(condType, values);
ctx.cond = cond;
ctx.cmpBool.SetValues(cond, values);
ctx.cmpInt.SetValues(cond, values);
ctx.cmpInt64.SetValues(cond, values);
ctx.cmpString.SetValues(cond, values, CollateOpts());
ctx.cmpDouble.SetValues(cond, values);
ctx.cmpUuid.SetValues(cond, values);

assertrx(ctx_.size() == fields_.size());
}

void CompositeArrayComparator::BindField(const TagsPath &tagsPath, const VariantArray &values, CondType condType) {
fields_.push_back(tagsPath);
Context &ctx = ctx_.emplace_back();

ctx.cond = condType;
ctx.cmpBool.SetValues(condType, values);
ctx.cmpInt.SetValues(condType, values);
ctx.cmpInt64.SetValues(condType, values);
ctx.cmpString.SetValues(condType, values, CollateOpts());
ctx.cmpDouble.SetValues(condType, values);
ctx.cmpUuid.SetValues(condType, values);
}

bool CompositeArrayComparator::Compare(const PayloadValue &pv, const ComparatorVars &vars) {
bool EqualPositionComparator::Compare(const PayloadValue &pv, const ComparatorVars &vars) {
ConstPayload pl(vars.payloadType_, pv);
size_t len = INT_MAX;

Expand Down Expand Up @@ -64,7 +56,7 @@ bool CompositeArrayComparator::Compare(const PayloadValue &pv, const ComparatorV
return false;
}

bool CompositeArrayComparator::compareField(size_t field, const Variant &v, const ComparatorVars &vars) {
bool EqualPositionComparator::compareField(size_t field, const Variant &v, const ComparatorVars &vars) {
return v.Type().EvaluateOneOf(
[&](KeyValueType::Bool) { return ctx_[field].cmpBool.Compare(ctx_[field].cond, static_cast<bool>(v)); },
[&](KeyValueType::Int) { return ctx_[field].cmpInt.Compare(ctx_[field].cond, static_cast<int>(v)); },
Expand Down
Loading

0 comments on commit c38cc13

Please sign in to comment.