isapego commented on code in PR #7966:
URL: https://github.com/apache/ignite-3/pull/7966#discussion_r3078159084


##########
modules/platforms/cpp/ignite/client/detail/table/table_impl.cpp:
##########
@@ -472,4 +584,68 @@ std::shared_ptr<table_impl> table_impl::from_facade(table 
&tb) {
     return tb.m_impl;
 }
 
+void table_impl::update_partition_assignment() {
+    ignite_callback<std::shared_ptr<protocol::partition_assignment>> callback 
= [self=shared_from_this()](auto pa) {
+        if (pa.has_error()) {
+            self->m_connection->get_logger()->log_error("Error while updating 
partition assignment for table"
+            + self->get_name() + "error " + pa.error().what_str());
+
+            return;
+        }
+
+        std::lock_guard lock(self->m_partitions_mutex);
+        self->m_partition_assignment = std::move(pa).value();
+    };
+
+    load_partition_assignment_async(std::move(callback));
+}
+
+void 
table_impl::load_partition_assignment_async(ignite_callback<std::shared_ptr<protocol::partition_assignment>>
 callback) {
+    std::int64_t timestamp = m_connection->get_assignment_timestamp();
+
+    auto pa = get_partition_assignment();
+    if (pa && !pa->is_outdated(timestamp)) {
+        m_connection->get_logger()->log_debug("Partition assignment for table 
" + get_name() + " is up to date.");
+
+        callback(std::move(pa));
+        return;
+    }
+
+    auto writer_func = [id = m_id, timestamp](protocol::writer &writer, auto&) 
{
+        protocol::write_partition_assignment_request(writer, id, timestamp);
+    };
+
+    auto reader_func = [timestamp](protocol::reader &reader) -> 
std::shared_ptr<protocol::partition_assignment> {
+        return protocol::read_partition_assignment_response(reader, timestamp);
+    };
+
+    
m_connection->perform_request<std::shared_ptr<protocol::partition_assignment>>(
+        protocol::client_operation::PARTITION_ASSIGNMENT_GET,
+        nullptr,
+        writer_func,
+        std::move(reader_func),
+        std::move(callback));
+}
+
+std::optional<std::string> table_impl::get_preferred_node_name(const 
ignite_tuple &key_or_rec, const schema &sch) {
+    auto pa = get_partition_assignment();
+
+    if (!pa || pa->get_partitions().empty()) {
+        m_connection->get_logger()->log_debug("No partition distribution 
available, random node will called");
+        return {};
+    }
+
+    hash_calculator hc;
+    for (auto column : sch.collocated_columns) {
+        auto val = key_or_rec.get(column->key_index);

Review Comment:
   Agree, the collocated columns order is what matters here.



##########
modules/platforms/cpp/ignite/client/detail/table/table_impl.cpp:
##########
@@ -472,4 +584,68 @@ std::shared_ptr<table_impl> table_impl::from_facade(table 
&tb) {
     return tb.m_impl;
 }
 
+void table_impl::update_partition_assignment() {
+    ignite_callback<std::shared_ptr<protocol::partition_assignment>> callback 
= [self=shared_from_this()](auto pa) {
+        if (pa.has_error()) {
+            self->m_connection->get_logger()->log_error("Error while updating 
partition assignment for table"
+            + self->get_name() + "error " + pa.error().what_str());
+
+            return;
+        }
+
+        std::lock_guard lock(self->m_partitions_mutex);
+        self->m_partition_assignment = std::move(pa).value();
+    };
+
+    load_partition_assignment_async(std::move(callback));
+}
+
+void 
table_impl::load_partition_assignment_async(ignite_callback<std::shared_ptr<protocol::partition_assignment>>
 callback) {
+    std::int64_t timestamp = m_connection->get_assignment_timestamp();
+
+    auto pa = get_partition_assignment();
+    if (pa && !pa->is_outdated(timestamp)) {
+        m_connection->get_logger()->log_debug("Partition assignment for table 
" + get_name() + " is up to date.");
+
+        callback(std::move(pa));
+        return;
+    }
+
+    auto writer_func = [id = m_id, timestamp](protocol::writer &writer, auto&) 
{
+        protocol::write_partition_assignment_request(writer, id, timestamp);
+    };
+
+    auto reader_func = [timestamp](protocol::reader &reader) -> 
std::shared_ptr<protocol::partition_assignment> {
+        return protocol::read_partition_assignment_response(reader, timestamp);
+    };
+
+    
m_connection->perform_request<std::shared_ptr<protocol::partition_assignment>>(
+        protocol::client_operation::PARTITION_ASSIGNMENT_GET,
+        nullptr,
+        writer_func,
+        std::move(reader_func),
+        std::move(callback));
+}
+
+std::optional<std::string> table_impl::get_preferred_node_name(const 
ignite_tuple &key_or_rec, const schema &sch) {
+    auto pa = get_partition_assignment();
+
+    if (!pa || pa->get_partitions().empty()) {
+        m_connection->get_logger()->log_debug("No partition distribution 
available, random node will called");
+        return {};
+    }
+
+    hash_calculator hc;
+    for (auto column : sch.collocated_columns) {
+        auto val = key_or_rec.get(column->key_index);

Review Comment:
   Agreed, the collocated columns order is what matters here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to