wirybeaver commented on code in PR #17235:
URL: https://github.com/apache/pinot/pull/17235#discussion_r2629465487


##########
pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java:
##########
@@ -283,6 +289,109 @@ public ConfigSuccessResponse addTable(String 
tableConfigStr,
     }
   }
 
+  @POST
+  @Path("/tables/{tableName}/copy")
+  @Authorize(targetType = TargetType.TABLE, action = 
Actions.Table.CREATE_TABLE)
+  @Produces(MediaType.APPLICATION_JSON)
+  @ApiOperation(value = "Copy a table's schema and config from another 
cluster", notes = "Non upsert table only")
+  public CopyTableResponse copyTable(
+      @ApiParam(value = "Name of the table", required = true) 
@PathParam("tableName") String tableName, String payload,
+      @Context HttpHeaders headers) {
+    try {
+      LOGGER.info("[copyTable] received request for table: {}, payload: {}", 
tableName, payload);
+      tableName = DatabaseUtils.translateTableName(tableName, headers);
+      CopyTablePayload copyTablePayload = JsonUtils.stringToObject(payload, 
CopyTablePayload.class);
+      String sourceControllerUri = copyTablePayload.getSourceClusterUri();
+      Map<String, String> requestHeaders = copyTablePayload.getHeaders();
+      String brokerTenant = copyTablePayload.getBrokerTenant();
+      String serverTenant = copyTablePayload.getServerTenant();
+      Map<String, String> tagReplacementMap = 
copyTablePayload.getTagPoolReplacementMap();
+
+      LOGGER.info("[copyTable] Start copying table: {} from source: {}", 
tableName, sourceControllerUri);
+
+      // Fetch and add schema
+      URI schemaUri = new URI(sourceControllerUri + "/tables/" + tableName + 
"/schema");
+      SimpleHttpResponse schemaResponse = HttpClient.wrapAndThrowHttpException(
+          HttpClient.getInstance().sendGetRequest(schemaUri, requestHeaders));
+      String schemaJson = schemaResponse.getResponse();
+      Schema schema = Schema.fromString(schemaJson);
+      _pinotHelixResourceManager.addSchema(schema, true, false);
+      LOGGER.info("[copyTable] Successfully added schema for table: {}, 
schema: {}", tableName, schema);
+
+      // Fetch and add table configs
+      URI tableConfigUri = new URI(sourceControllerUri + "/tables/" + 
tableName);
+      SimpleHttpResponse tableConfigResponse = 
HttpClient.wrapAndThrowHttpException(
+          HttpClient.getInstance().sendGetRequest(tableConfigUri, 
requestHeaders));
+      String tableConfigJson = tableConfigResponse.getResponse();
+      LOGGER.info("[copyTable] Fetched table config for table: {}, 
tableConfig: {}", tableName, tableConfigJson);
+      JsonNode tableConfigNode = JsonUtils.stringToJsonNode(tableConfigJson);
+
+      if (tableConfigNode.has(TableType.REALTIME.name())) {

Review Comment:
   Yeah, for upsert and pauseless table, we should throw the exception.
   
   For offline table or offline part of the hybrid table, we can log as a 
warning? The hunch is that, the use can write their own internal workflow to 
backfill the offline table. For hybrid table, the user need to copy realtime 
part.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to