Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom settings for Reindexer #19

Merged
merged 139 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 136 commits
Commits
Show all changes
139 commits
Select commit Hold shift + click to select a range
6bbe288
[fix] Rework code according to Valgrind's recommendations
Oct 8, 2024
d27da93
Clear code
Oct 9, 2024
81ca870
Avoid PEP's warnings
Oct 9, 2024
2f9edd5
Update code
Oct 9, 2024
0ded690
Support sync transactions
Oct 14, 2024
de64dac
Rewrite query results wrapper
Oct 14, 2024
0392983
Properly use NewItem method. Reorganize code
Oct 15, 2024
1cbd051
Implement transaction py API
Oct 15, 2024
1a77b8e
Add transaction py-tests
Oct 15, 2024
3ac3485
Update Readme.md
Oct 16, 2024
0d44728
[fix] Fix build pyreindexer with reindexer v.4.15
Oct 16, 2024
2f01596
Try fix MacOS tests
Oct 17, 2024
ce25efa
Merge branch 'fix/rework_code_according_to_valgrinds_recommendations'…
Oct 17, 2024
da03def
Correct style
Oct 17, 2024
e016c33
Update tests
Oct 17, 2024
a7b03c2
Reorganize README
Oct 17, 2024
d0d732d
Correct test_item
Oct 18, 2024
afa4770
Merge branch 'fix/build_pyreindexer_with_v4.15.0_GetAggregationResult…
Oct 18, 2024
99099fa
Update transaction test
Oct 23, 2024
ae9dcd4
Simplify code
Oct 23, 2024
5454cf9
Style changes
Oct 23, 2024
247b231
Start of implementation of query builder
Oct 23, 2024
b3fad40
Part I: start of implementation of query builder
Oct 24, 2024
1f53241
Part II: start of implementation of query builder
Oct 25, 2024
122c00c
Part III: start of implementation of query builder
Oct 25, 2024
25c868a
Part IV: start of implementation of query builder
Oct 25, 2024
f403305
Merge branch 'master' into feature/add_transaction_support
Oct 25, 2024
a68c5b7
Merge branch 'feature/add_transaction_support' into feature/add_query…
Oct 25, 2024
5b10ceb
Part V: start of implementation of query builder
Oct 25, 2024
cbc34aa
Part VI: start of implementation of query builder
Oct 28, 2024
cd35c30
Add commit_with_count()
Oct 28, 2024
8f7542d
Add commit_with_count(). Fix code and check in test
Oct 29, 2024
0972bc7
Merge branch 'feature/add_transaction_support' into feature/add_query…
Oct 29, 2024
c9070b4
Rewrite query_wrapper
Oct 29, 2024
30b8806
Rewrite query_wrapper. Part II
Oct 30, 2024
bd55939
Rewrite query_wrapper. Part III: add where for Variant
Oct 30, 2024
2d64757
Rewrite query_wrapper. Part IV: add where for Variant. Clean code
Oct 30, 2024
2d6423f
Part VII: start of implementation of query builder. Add where
Oct 30, 2024
5280a2b
Part VIII: start of implementation of query builder. Add Point and dw…
Oct 30, 2024
dd7aceb
Part IX: start of implementation of query builder. Add simple aggregate
Oct 30, 2024
35dd3ed
Part X: start of implementation of query builder. Add sort
Oct 31, 2024
eee1335
Part XI: start of implementation of query builder. Add aggregation
Oct 31, 2024
87cf4a6
Part XI: start of implementation of query builder. Add aggregation. Fix
Nov 1, 2024
3e04ec2
Part XII: start of implementation of query builder. Add SetObject
Nov 1, 2024
ea30af2
Part XIII: start of implementation of query builder. Add Join
Nov 1, 2024
066efca
Part XIV: start of implementation of query builder. Add Delete. Part I
Nov 1, 2024
c14a9ae
Part XV: start of implementation of query builder. Add Insert\Delete\…
Nov 2, 2024
5cd9e40
Part XV: start of implementation of query builder. Add Insert\Delete\…
Nov 2, 2024
d051dba
Part XV: start of implementation of query builder. Add Insert\Delete\…
Nov 5, 2024
cc74f67
[ref] tests
Nov 5, 2024
e6fee62
Part XVI: start of implementation of query builder. Add Get(firstItem…
Nov 5, 2024
4286c1b
Part XVII: clear code. Hide all context unimplemented functions
Nov 5, 2024
f412d96
Prevent warning on build
Nov 5, 2024
e57ed58
Update comments
Nov 6, 2024
4ab751e
[ref] more test refactoring
Nov 6, 2024
5f242fe
[fix] bump setup version
Nov 6, 2024
7fca19e
[fix] fix imports for ci
Nov 6, 2024
35c2fd0
[fix] bump version
Nov 6, 2024
e57fa7a
[fix] update package_data
Nov 6, 2024
20b70d9
[fix] fix imports and package_data
Nov 6, 2024
5351f97
Part XVIII: add using fetch count
Nov 6, 2024
c328388
Merge branch 'ref_tests' into feature/add_query_support
Nov 6, 2024
c629d18
[ref] small code ref
Nov 6, 2024
4b40a64
[ref] ref tests with tx
Nov 6, 2024
319e615
Merge remote-tracking branch 'origin/feature/add_query_support' into …
Nov 6, 2024
c255552
Clear code after review
Nov 6, 2024
dc5a7d3
Part XVIII: rollback using fetch count. Fix execute method
Nov 6, 2024
d5bb868
Part XIX: remove Query aliases from connector (select\delete\update)
Nov 6, 2024
02908c5
Simplify example code
Nov 6, 2024
08941cf
Remove `-Wold-style-cast` cmake flag
Nov 6, 2024
d60c9f6
Merge remote-tracking branch 'origin/feature/add_query_support' into …
Nov 7, 2024
e2a8ea8
[fix] fix tests with tx
Nov 7, 2024
0c72d21
add initial query tests
Nov 7, 2024
19e881f
Part XX: remove support of FetchCount from Query object
Nov 7, 2024
17009b8
Simplify code
Nov 7, 2024
b3303be
add new query tests
Nov 7, 2024
c4b8f08
Part XXI: bug fix. Segmentation fault
Nov 8, 2024
3cf7a9a
add new query select tests
Nov 8, 2024
bb98bca
Merge branch 'master' into feature/add_query_support
Nov 8, 2024
edf2f41
Part XXII: update readme generation (pydoc_markdown)
Nov 8, 2024
599410c
Part XXIII: enum for LogLevel
Nov 8, 2024
e4fc259
Small updates
Nov 8, 2024
f38e721
Part XXIV: Add support GetExplainResults
Nov 11, 2024
192e168
add query tests: update, delete
Nov 11, 2024
603ac96
Update markdown
Nov 11, 2024
2553303
Part XXV: Bug fixes
Nov 11, 2024
fae7270
Part XXV: Bug fixes. Part II
Nov 12, 2024
c9e74da
[fix] err for select and update, querytests
Nov 12, 2024
835b7dc
[fix] more query test fixes
Nov 12, 2024
f4946b5
[fix] fix forced_sort test
Nov 13, 2024
49eb82e
Part XXV: Bug fixes. Part III: set & set_object
Nov 13, 2024
60d071a
add more query tests
Nov 13, 2024
b091390
Simplify code
Nov 13, 2024
46afcd5
Part XXV: Bug fixes. Part IV: expected: <[{'id': -1}]> but: was <[{'i…
Nov 13, 2024
7bc415e
add more tests with negative
Nov 13, 2024
2164fcf
add null to create items test
Nov 13, 2024
89a7465
Part XXVI: add return TotalCount
Nov 15, 2024
26d70c2
Part XXVII: disable WAL-queries
Nov 18, 2024
7c0bc72
Part XXVII: disable WAL-queries. Catch unhandled exception
Nov 18, 2024
4480dec
Part XXVIII: Return JOIN result. Part
Nov 19, 2024
9a4abfb
Part XXIX: where_query check
Nov 20, 2024
c57663f
Part XXX: where_composite fixes. Part
Nov 21, 2024
fdcfe30
Part XXX: where_composite fixes. Part
Nov 21, 2024
49ddd64
Part XXX: where_composite fixes. Part. Fix
Nov 21, 2024
cfce014
Part XXX: where_composite done
Nov 21, 2024
4378562
Part XXXI: join support/ Part
Nov 25, 2024
bbf4b41
Part XXXI: join support. Part
Nov 25, 2024
9ec593f
Part XXXI: join support. Simplify code
Nov 26, 2024
6910083
add join tests
Nov 27, 2024
0d09c11
Part XXXII: fix v.4 build
Nov 27, 2024
ca7916e
Corrections and fixes
Nov 29, 2024
c23fb33
Simplify code, correct style
Nov 29, 2024
ceea55b
Merge branch 'master' into feature/add_query_support
Dec 2, 2024
1f726be
Fix. Add default value
Dec 2, 2024
d2c0a66
Update minimal Reindexer version
Dec 2, 2024
d3fd315
Client configuration support for Reindexer
Dec 3, 2024
1bccaae
add exceptions
Dec 3, 2024
a2f80cd
Client configuration support for Reindexer. Fix MacOS build
Dec 3, 2024
db70321
Client configuration support for Reindexer. ReFix MacOS build
Dec 3, 2024
fcba1b5
fix raises in docstrings
Dec 3, 2024
aaeb1fa
small ref, fix expected exception
Dec 4, 2024
b4360b3
Update readme file
Dec 4, 2024
28ff2dc
Fix build
Dec 4, 2024
4748384
Fix build
Dec 4, 2024
794eb5f
Fix build
Dec 5, 2024
ab66015
Review changes
Dec 5, 2024
a39b966
Review changes
Dec 5, 2024
f280c66
Review changes
Dec 9, 2024
1325842
Merge branch 'master' into feature/add_query_support
Dec 9, 2024
1e4a49f
Review changes. Fix build
Dec 9, 2024
efd1436
Add query in transaction
Dec 10, 2024
b15395b
Update version
Dec 10, 2024
a1b0666
Merge branch 'feature/add_query_support' into feature/reindexer_confi…
Dec 10, 2024
c568aac
Merge branch 'master' into feature/reindexer_config_support
Dec 12, 2024
d6479e5
Update version
Dec 12, 2024
985b530
Correct README
Dec 12, 2024
7777016
Merge branch 'master' into feature/reindexer_config_support
Dec 16, 2024
70ef6a7
Review changes
Dec 16, 2024
cc37833
Update version
Dec 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyreindexer/example/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ def query_example(db, namespace):
print('Item: ', item)

def rx_example():
db = RxConnector('builtin:///tmp/pyrx')
# db = RxConnector('cproto://127.0.0.1:6534/pyrx')
db = RxConnector('builtin:///tmp/pyrx', max_replication_updates_size = 10 * 1024 * 1024)
# db = RxConnector('cproto://127.0.0.1:6534/pyrx', enable_compression = True, fetch_amount = 500)

namespace = 'test_table'

Expand Down
59 changes: 39 additions & 20 deletions pyreindexer/lib/src/rawpyreindexer.cc
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#include "rawpyreindexer.h"

#include "pyobjtools.h"
#include "queryresults_wrapper.h"
#include "query_wrapper.h"
#include "transaction_wrapper.h"
#include "pyobjtools.h"
#include "tools/serializer.h"

namespace pyreindexer {

using reindexer::Error;
using reindexer::IndexDef;
using reindexer::NamespaceDef;
using reindexer::WrSerializer;

namespace {
uintptr_t initReindexer() {
auto db = std::make_unique<DBInterface>();
uintptr_t initReindexer(const ReindexerConfig& cfg) {
auto db = std::make_unique<DBInterface>(cfg);
return reinterpret_cast<uintptr_t>(db.release());
}

Expand Down Expand Up @@ -59,7 +58,27 @@ PyObject* queryResultsWrapperIterate(uintptr_t qresWrapperAddr) {
// common --------------------------------------------------------------------------------------------------------------

static PyObject* Init(PyObject* self, PyObject* args) {
uintptr_t rx = initReindexer();
ReindexerConfig cfg;
char* clientName = nullptr;
int connectTimeout = 0;
int requestTimeout = 0;
unsigned enableCompression = 0;
unsigned startSpecialThread = 0;
unsigned maxReplUpdatesSize = 0;
if (!PyArg_ParseTuple(args, "iiiIIsIif", &cfg.fetchAmount, &connectTimeout, &requestTimeout,
&enableCompression, &startSpecialThread, &clientName, &maxReplUpdatesSize,
&cfg.allocatorCacheLimit, &cfg.allocatorCachePart)) {
return nullptr;
}

cfg.connectTimeout = std::chrono::seconds(connectTimeout);
cfg.requestTimeout = std::chrono::seconds(requestTimeout);
cfg.enableCompression = (enableCompression != 0);
cfg.requestDedicatedThread = (startSpecialThread != 0);
cfg.appName = clientName;
cfg.maxReplUpdatesSize = maxReplUpdatesSize;

uintptr_t rx = initReindexer(cfg);
if (rx == 0) {
PyErr_SetString(PyExc_RuntimeError, "Initialization error");

Expand Down Expand Up @@ -153,7 +172,7 @@ static PyObject* EnumNamespaces(PyObject* self, PyObject* args) {
return nullptr;
}

std::vector<NamespaceDef> nsDefs;
std::vector<reindexer::NamespaceDef> nsDefs;
auto err = getWrapper<DBInterface>(rx)->EnumNamespaces(nsDefs, reindexer::EnumNamespacesOpts().WithClosed(enumAll));
if (!err.ok()) {
return Py_BuildValue("is[]", err.code(), err.what().c_str());
Expand Down Expand Up @@ -333,7 +352,7 @@ PyObject* itemModify(PyObject* self, PyObject* args, ItemModifyMode mode) {
err = getWrapper<DBInterface>(rx)->Delete(ns, item);
break;
default:
err = reindexer::Error(ErrorCode::errLogic, "Unknown item modify mode");
err = Error(ErrorCode::errLogic, "Unknown item modify mode");
}

return pyErr(err);
Expand Down Expand Up @@ -573,7 +592,7 @@ PyObject* modifyTransaction(PyObject* self, PyObject* args, ItemModifyMode mode)
err = transaction->Modify(std::move(item), mode);
return pyErr(err);
default:
return pyErr(reindexer::Error(ErrorCode::errLogic, "Unknown item modify transaction mode"));
return pyErr(Error(ErrorCode::errLogic, "Unknown item modify transaction mode"));
}

return nullptr;
Expand Down Expand Up @@ -662,7 +681,7 @@ static PyObject* Where(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->Where(index, CondType(condition), keys);

return pyErr(errOK);
return pyErr({});
}

static PyObject* WhereSubQuery(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -693,7 +712,7 @@ static PyObject* WhereSubQuery(PyObject* self, PyObject* args) {
auto subQuery = getWrapper<QueryWrapper>(subQueryWrapperAddr);
query->WhereSubQuery(*subQuery, CondType(cond), keys);

return pyErr(errOK);
return pyErr({});
}

static PyObject* WhereFieldSubQuery(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -739,7 +758,7 @@ static PyObject* WhereUUID(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->WhereUUID(index, CondType(condition), keys);

return pyErr(errOK);
return pyErr({});
}

static PyObject* WhereBetweenFields(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -837,7 +856,7 @@ static PyObject* AggregationSort(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->AggregationSort(field, (desc != 0));

return pyErr(errOK);
return pyErr({});
}

static PyObject* Aggregation(PyObject* self, PyObject* args) {
Expand All @@ -864,7 +883,7 @@ static PyObject* Aggregation(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->Aggregation(fields);

return pyErr(errOK);
return pyErr({});
}

static PyObject* Sort(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -893,7 +912,7 @@ static PyObject* Sort(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->Sort(index, (desc != 0), sortValues);

return pyErr(errOK);
return pyErr({});
}

namespace {
Expand Down Expand Up @@ -993,7 +1012,7 @@ static PyObject* executeQuery(PyObject* self, PyObject* args, ExecuteType type)
err = query->UpdateQuery(qresult);
break;
default:
return pyErr(reindexer::Error(ErrorCode::errLogic, "Unknown query execute mode"));
return pyErr(Error(ErrorCode::errLogic, "Unknown query execute mode"));
}

if (!err.ok()) {
Expand Down Expand Up @@ -1034,7 +1053,7 @@ static PyObject* SetObject(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->SetObject(field, values);

return pyErr(errOK);
return pyErr({});
}

static PyObject* Set(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -1062,7 +1081,7 @@ static PyObject* Set(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->Set(field, values, QueryWrapper::IsExpression::No);

return pyErr(errOK);
return pyErr({});
}

static PyObject* Drop(PyObject* self, PyObject* args) {
Expand Down Expand Up @@ -1160,7 +1179,7 @@ static PyObject* SelectFilter(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->SelectFilter(fields);

return pyErr(errOK);
return pyErr({});
}

static PyObject* AddFunctions(PyObject* self, PyObject* args) {
Expand All @@ -1187,7 +1206,7 @@ static PyObject* AddFunctions(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->AddFunctions(functions);

return pyErr(errOK);
return pyErr({});
}

static PyObject* AddEqualPosition(PyObject* self, PyObject* args) {
Expand All @@ -1214,7 +1233,7 @@ static PyObject* AddEqualPosition(PyObject* self, PyObject* args) {

getWrapper<QueryWrapper>(queryWrapperAddr)->AddEqualPosition(equalPoses);

return pyErr(errOK);
return pyErr({});
}

} // namespace pyreindexer
2 changes: 1 addition & 1 deletion pyreindexer/lib/src/rawpyreindexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ static PyObject* AddEqualPosition(PyObject* self, PyObject* args);

// clang-format off
static PyMethodDef module_methods[] = {
{"init", Init, METH_NOARGS, "init reindexer instance"},
{"init", Init, METH_VARARGS, "init reindexer instance"},
{"destroy", Destroy, METH_VARARGS, "destroy reindexer instance"},
{"connect", Connect, METH_VARARGS, "connect to reindexer database"},
{"select", Select, METH_VARARGS, "select query"},
Expand Down
37 changes: 35 additions & 2 deletions pyreindexer/lib/src/reindexerinterface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,44 @@ namespace {
const int QRESULTS_FLAGS = kResultsJson | kResultsWithJoined;
}

class ICommand {
public:
virtual Error Status() const = 0;
virtual void Execute() = 0;
virtual bool IsExecuted() const = 0;

virtual ~ICommand() = default;
};

class GenericCommand : public ICommand {
public:
using CallableT = std::function<Error()>;

GenericCommand(CallableT command) : command_(std::move(command)) {}

Error Status() const override final { return err_; }
void Execute() override final {
err_ = command_();
executed_.store(true, std::memory_order_release);
}
bool IsExecuted() const override final { return executed_.load(std::memory_order_acquire); }

private:
CallableT command_;
Error err_;
std::atomic_bool executed_{false};
};

template <>
ReindexerInterface<reindexer::Reindexer>::ReindexerInterface() {}
ReindexerInterface<reindexer::Reindexer>::ReindexerInterface(const ReindexerConfig& cfg)
: db_(reindexer::ReindexerConfig().WithUpdatesSize(cfg.maxReplUpdatesSize)
.WithAllocatorCacheLimits(cfg.allocatorCacheLimit, cfg.allocatorCachePart))
{ }

template <>
ReindexerInterface<reindexer::client::CoroReindexer>::ReindexerInterface() {
ReindexerInterface<reindexer::client::CoroReindexer>::ReindexerInterface(const ReindexerConfig& cfg)
: db_(reindexer::client::ReindexerConfig(4, 1, cfg.fetchAmount, 0, cfg.connectTimeout, cfg.requestTimeout,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вот у этого конфига, как я вижу, на v3 и v4 отличаются конструкторы. Для совместимости с обеими версиями, чтобы не ждать полного переезда на v4, можно сейчас сделать что-то типа такого:

static reindexer::client::ReindexerConfig makeClientConfig(const ReindexerConfig& cfg) {
  reindexer::client::ReindexerConfig cfg;
  cfg.FetchAmout = cfg.fetchAmount;
  // ... для остальных опций - аналогично
  return cfg;
}

И в конструкторе тогда инициализировать db_ вот так:

db_{makeClientConfig(cfg)}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно, но толку немного. Есть важный параметр в v4: milliseconds _NetTimeout = milliseconds(0), а в v3:

seconds _ConnectTimeout = seconds(0),
seconds _RequestTimeout = seconds(0),

И получится для совместимости без него\их нужно работать

cfg.enableCompression, cfg.requestDedicatedThread, cfg.appName)) {
std::atomic_bool running{false};
executionThr_ = std::thread([this, &running] {
cmdAsync_.set(loop_);
Expand Down
Loading
Loading