lxy-9602 commented on code in PR #199:
URL: https://github.com/apache/paimon-cpp/pull/199#discussion_r3780894939


##########
src/paimon/core/realtime/realtime_context.cpp:
##########
@@ -105,6 +127,79 @@ class RealtimeContext::Impl {
         return result;
     }
 
+    Result<std::string> PinReadView(const RealtimePartitionBucketView& view, 
int64_t ttl_millis) {
+        if (!view.indexer || !view.read_view) {
+            return Status::Invalid("cannot pin an incomplete real-time read 
view");
+        }
+        if (ttl_millis <= 0) {
+            return Status::Invalid("real-time read-view TTL must be greater 
than zero");
+        }
+        const auto now = std::chrono::steady_clock::now();
+        const auto ttl = std::chrono::milliseconds(ttl_millis);
+        if (ttl > std::chrono::duration_cast<std::chrono::milliseconds>(
+                      std::chrono::steady_clock::time_point::max() - now)) {
+            return Status::Invalid("real-time read-view TTL is too large");
+        }
+
+        while (true) {
+            std::string opaque_ticket;
+            if (!UUID::Generate(&opaque_ticket)) {
+                return Status::IOError("failed to generate a real-time 
read-view ticket");
+            }
+            {
+                std::lock_guard<std::mutex> lock(read_views_mutex_);
+                bool inserted =
+                    pinned_read_views_.emplace(opaque_ticket, 
PinnedReadView{view, now + ttl})
+                        .second;
+                if (!inserted) {
+                    continue;
+                }
+            }
+            read_views_cv_.notify_all();
+            return opaque_ticket;
+        }
+    }
+
+    Result<RealtimePartitionBucketView> ResolveReadView(const std::string& 
opaque_ticket) {
+        bool expired = false;
+        {
+            std::lock_guard<std::mutex> lock(read_views_mutex_);
+            auto iter = pinned_read_views_.find(opaque_ticket);
+            if (iter == pinned_read_views_.end()) {
+                return Status::Invalid("real-time read-view ticket does not 
exist or has expired");
+            }
+            if (iter->second.expire_at <= std::chrono::steady_clock::now()) {
+                
read_view_release_queue_.push_back(std::move(iter->second.view));
+                pinned_read_views_.erase(iter);
+                expired = true;
+            } else {
+                return iter->second.view;

Review Comment:
   Added comments.



-- 
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