pabloem commented on code in PR #24390:
URL: https://github.com/apache/beam/pull/24390#discussion_r1036334262


##########
sdks/java/io/google-cloud-platform/src/main/java/org/apache/beam/sdk/io/gcp/spanner/changestreams/NameGenerator.java:
##########
@@ -25,23 +25,28 @@
  */
 public class NameGenerator {
 
-  private static final String PARTITION_METADATA_TABLE_NAME_FORMAT =
-      "CDC_Partitions_Metadata_%s_%s";
+  private static final String PARTITION_METADATA_TABLE_NAME_FORMAT = 
"Metadata_%s_%s";
+  private static final int MAX_TABLE_NAME_LENGTH = 63;
 
   /**
    * Generates an unique name for the partition metadata table in the form of 
{@code
-   * "CDC_Partitions_Metadata_<databaseId>_<uuid>"}.
+   * "Metadata_<databaseId>_<uuid>"}.
    *
    * @param databaseId The database id where the table will be created
    * @return the unique generated name of the partition metadata table
    */
   public static String generatePartitionMetadataTableName(String databaseId) {
-    // Maximum Spanner table name length is 128 characters.
-    // There are 25 characters in the name format.
+    // There are 11 characters in the name format.
     // Maximum Spanner database ID length is 30 characters.
     // UUID always generates a String with 36 characters.
-    // 128 - (25 + 30 + 36) = 37 characters short of the limit
-    return String.format(PARTITION_METADATA_TABLE_NAME_FORMAT, databaseId, 
UUID.randomUUID())
-        .replaceAll("-", "_");
+    // Since the Postgres table name length is 63, we may need to truncate the 
table name depending
+    // on the database length.
+    String fullString =
+        String.format(PARTITION_METADATA_TABLE_NAME_FORMAT, databaseId, 
UUID.randomUUID())
+            .replaceAll("-", "_");
+    if (fullString.length() < MAX_TABLE_NAME_LENGTH) {
+      return fullString;
+    }
+    return fullString.substring(0, MAX_TABLE_NAME_LENGTH);

Review Comment:
   I am guessing this is not necessarily a problem, since we have very few 
instances of metadata tables being created, but cutting UUID can cause issues 
sooner 
(https://stackoverflow.com/questions/4564112/is-it-safe-to-turn-a-uuid-into-a-short-code-only-use-first-8-chars)
 



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