airajena commented on code in PR #102:
URL: 
https://github.com/apache/fineract-business-intelligence/pull/102#discussion_r4318455926


##########
ingestion/ingestion-core/src/main/java/org/apache/fineract/bi/ingestion/routing/OwnershipSnapshot.java:
##########
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.fineract.bi.ingestion.routing;
+
+import java.util.Map;
+
+public final class OwnershipSnapshot {
+
+    public static final String ENGINE = "KAFKA";
+
+    public record Entry(String engine, String shadowEngine, String state, long 
epoch) {
+    }
+
+    public record SourceMeta(String tenantId, int generation) {
+    }
+
+    private final Map<String, Entry> entries;
+    private final Map<String, SourceMeta> sources;
+    private final long loadedAtMillis;
+
+    public OwnershipSnapshot(Map<String, Entry> entries, Map<String, 
SourceMeta> sources, long loadedAtMillis) {
+        this.entries = Map.copyOf(entries);
+        this.sources = Map.copyOf(sources);
+        this.loadedAtMillis = loadedAtMillis;
+    }
+
+    public static OwnershipSnapshot empty() {
+        return new OwnershipSnapshot(Map.of(), Map.of(), 0L);
+    }
+
+    public static String key(String sourceId, String table) {
+        return sourceId + '\u0000' + table;
+    }
+
+    public long loadedAtMillis() {
+        return loadedAtMillis;
+    }
+
+    public int size() {
+        return entries.size();
+    }
+
+    public int sourceCount() {
+        return sources.size();
+    }
+
+    public Route route(String sourceId, String table) {
+        SourceMeta meta = sources.get(sourceId);
+        if (meta == null) {
+            return new Route(Route.Target.UNKNOWN_SOURCE, 0, null, 0, "source 
not registered");
+        }
+        Entry e = entries.get(key(sourceId, table));
+        if (e == null) {
+            return new Route(Route.Target.SKIP, 0, meta.tenantId(), 
meta.generation(), "not owned by KAFKA");

Review Comment:
   Fixed. Before the offset moves past skipped records, their epochs are 
verified against the database in the same transaction as the offset upsert. A 
stale skip is retried with a refreshed ownership view instead of being 
committed. Tests cover this against a real PostgreSQL.



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