abhishekbafna commented on code in PR #15515:
URL: https://github.com/apache/pinot/pull/15515#discussion_r2059683390


##########
pinot-common/src/main/java/org/apache/pinot/common/config/provider/TableCache.java:
##########
@@ -390,6 +423,78 @@ private List<Schema> getSchemas() {
     return schemas;
   }
 
+  private void addLogicalTables(List<String> paths) {
+    // Subscribe data changes before reading the data to avoid missing changes
+    for (String path : paths) {
+      _propertyStore.subscribeDataChanges(path, _zkLogicalTableChangeListener);
+    }
+    List<ZNRecord> znRecords = _propertyStore.get(paths, null, 
AccessOption.PERSISTENT);
+    for (ZNRecord znRecord : znRecords) {
+      if (znRecord != null) {
+        try {
+          putLogicalTable(znRecord);
+        } catch (Exception e) {
+          LOGGER.error("Caught exception while adding logical table for 
ZNRecord: {}", znRecord.getId(), e);
+        }
+      }
+    }
+  }
+
+  private void putLogicalTable(ZNRecord znRecord)
+      throws IOException {
+    LogicalTable logicalTable = LogicalTableUtils.fromZNRecord(znRecord);
+    String logicalTableName = logicalTable.getTableName();
+    _logicalTableNameMap.put(logicalTableName, logicalTable);
+  }
+
+  private void removeLogicalTable(String path) {
+    _propertyStore.unsubscribeDataChanges(path, _zkLogicalTableChangeListener);
+    String logicalTableName = 
path.substring(LOGICAL_TABLE_PATH_PREFIX.length());
+    _logicalTableNameMap.remove(logicalTableName);
+  }
+
+  private void notifyLogicalTableChangeListeners() {
+    if (!_logicalTableChangeListeners.isEmpty()) {
+      List<LogicalTable> logicalTables = new 
ArrayList<>(_logicalTableNameMap.values());
+      for (LogicalTableChangeListener listener : _logicalTableChangeListeners) 
{
+        listener.onChange(logicalTables);
+      }
+    }
+  }
+
+  @Nullable
+  public LogicalTable getLogicalTable(String logicalTableName) {
+    return _logicalTableNameMap.get(logicalTableName);
+  }
+
+  public boolean isLogicalTable(String logicalTableName) {
+    return _logicalTableNameMap.containsKey(logicalTableName);
+  }
+
+  public List<LogicalTable> getLogicalTables() {
+    return new ArrayList<>(_logicalTableNameMap.values());
+  }
+
+  public Schema getLogicalTableSchema(String logicalTableName) {

Review Comment:
   okay. I will not include the schema in this PR and we can add it after the 
discussion is concluded.



-- 
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: commits-unsubscr...@pinot.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to