Skip to content

Commit

Permalink
[PLAT-14539][xCluster] need_bootstrap API does not work for old unive…
Browse files Browse the repository at this point in the history
…rses

Summary:
To improve the performance, YBA creates the main table to its index tables map using the indexed_table_id field that is part of the ListTables RPC. However, this field is only available for the universes with YBDB version after `2.21.1.0-b167`.

This diff makes changes to use the old method for old YBDB universes.

Test Plan:
- Create a universe at version `2.19.3.0-b122` and ensured the index table map is created properly.
- Create a universe at version `2.23.0.0-b490` and ensured the index table map is created properly and the more efficient method is used.

Reviewers: #yba-api-review!, vbansal, cwang, jmak, sanketh

Reviewed By: vbansal, cwang

Subscribers: yugaware

Differential Revision: https://phorge.dev.yugabyte.com/D36349
  • Loading branch information
shahrooz1997 committed Jul 15, 2024
1 parent 39c6228 commit d7cf125
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1335,8 +1335,26 @@ public static Map<String, GetTableSchemaResponse> getTableSchemas(
return tableSchemaMap;
}

/**
* It returns a map from main table id to a list of index table ids associated with the main table
* in the universe. `getIndexedTableId` was added to YBDB 2.21.1.0-b168.
*
* @param tableInfoList The list of table info in the universe
* @return A map from main table id to a list of index table ids
*/
public static Map<String, List<String>> getMainTableIndexTablesMap(
Universe universe,
Collection<MasterDdlOuterClass.ListTablesResponsePB.TableInfo> tableInfoList) {
// Ensure it is not called for a universe older than 2.21.1.0-b168. For older version use the
// other getMainTableIndexTablesMap method that uses an RPC available in older universes.
if (Util.compareYbVersions(
"2.21.1.0-b168",
universe.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion,
true)
> 0) {
throw new IllegalStateException(
"This method is only supported for universes newer than or equal to 2.21.1.0-b168");
}
Map<String, List<String>> mainTableIndexTablesMap = new HashMap<>();
tableInfoList.forEach(
tableInfo -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,28 @@ public Result needBootstrapTable(
namespaceIdToTableInfoListMap =
XClusterConfigTaskBase.groupByNamespaceId(sourceTableInfoList);
log.debug("namespaceIdToTableInfoListMap is {}", namespaceIdToTableInfoListMap);
Map<String, List<String>> sourceUniverseMainTableIndexTablesMap =
XClusterConfigTaskBase.getMainTableIndexTablesMap(sourceTableInfoList);
Map<String, List<String>> sourceUniverseMainTableIndexTablesMap;
// For universes newer than or equal to 2.21.1.0-b168, we use the following method to improve
// performance.
if (Util.compareYbVersions(
"2.21.1.0-b168",
sourceUniverse.getUniverseDetails().getPrimaryCluster().userIntent.ybSoftwareVersion,
true)
<= 0) {
sourceUniverseMainTableIndexTablesMap =
XClusterConfigTaskBase.getMainTableIndexTablesMap(sourceUniverse, sourceTableInfoList);
} else {
log.warn(
"Universe {} does not support indexed_table_id in the ListTable RPC, the response may"
+ " take time to be generated. Please consider upgrading the universe to a newer"
+ " version.",
sourceUniverseUuid);
sourceUniverseMainTableIndexTablesMap =
XClusterConfigTaskBase.getMainTableIndexTablesMap(
this.ybService,
sourceUniverse,
XClusterConfigTaskBase.getTableIds(sourceTableInfoList));
}
log.debug("sourceUniverseMainTableIndexTablesMap is {}", sourceUniverseMainTableIndexTablesMap);

Set<String> allTableIds = new HashSet<>(needBootstrapFormData.tables);
Expand Down

0 comments on commit d7cf125

Please sign in to comment.