Jackie-Jiang commented on code in PR #11574:
URL: https://github.com/apache/pinot/pull/11574#discussion_r1353669798


##########
pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java:
##########
@@ -79,6 +80,26 @@ public static void 
setTableConfig(ZkHelixPropertyStore<ZNRecord> propertyStore,
         AccessOption.PERSISTENT);
   }
 
+  /**
+   * Update table config with an expected version. This is to avoid race 
condition for table config update issued by
+   * multiple clients, especially when update configs in a programmatic way.
+   * The typical usage is to read table config, apply some changes, then 
update it.
+   *
+   * @return true if update is successful.
+   */
+  public static boolean setTableConfig(ZkHelixPropertyStore<ZNRecord> 
propertyStore, String tableNameWithType,
+      TableConfig tableConfig, int expectVersion) {
+    ZNRecord tableConfigZNRecord;
+    try {
+      tableConfigZNRecord = TableConfigUtils.toZNRecord(tableConfig);
+      return 
propertyStore.set(constructPropertyStorePathForResourceConfig(tableNameWithType),
 tableConfigZNRecord,
+          expectVersion, AccessOption.PERSISTENT);

Review Comment:
   This part should be outside of the try-catch



##########
pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java:
##########
@@ -79,6 +80,26 @@ public static void 
setTableConfig(ZkHelixPropertyStore<ZNRecord> propertyStore,
         AccessOption.PERSISTENT);
   }
 
+  /**
+   * Update table config with an expected version. This is to avoid race 
condition for table config update issued by
+   * multiple clients, especially when update configs in a programmatic way.
+   * The typical usage is to read table config, apply some changes, then 
update it.
+   *
+   * @return true if update is successful.
+   */
+  public static boolean setTableConfig(ZkHelixPropertyStore<ZNRecord> 
propertyStore, String tableNameWithType,

Review Comment:
   (minor) `tableNameWithType` is not needed



##########
pinot-common/src/main/java/org/apache/pinot/common/metadata/ZKMetadataProvider.java:
##########
@@ -317,6 +338,18 @@ public static TableConfig 
getTableConfig(ZkHelixPropertyStore<ZNRecord> property
         AccessOption.PERSISTENT));
   }
 
+  /**
+   * @return a pair of table config and current version from znRecord.
+   */
+  public static ImmutablePair<TableConfig, Integer> getTableConfigWithVersion(
+      ZkHelixPropertyStore<ZNRecord> propertyStore, String tableNameWithType) {
+    Stat tableConfigStat = new Stat();
+    TableConfig tableConfig = toTableConfig(
+        
propertyStore.get(constructPropertyStorePathForResourceConfig(tableNameWithType),
 tableConfigStat,
+            AccessOption.PERSISTENT));
+    return ImmutablePair.of(tableConfig, tableConfigStat.getVersion());

Review Comment:
   When `tableConfig` is null, we should probably directly return `null` 
instead of a pair. Also annotate the return as `@Nullable`



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