in aios/sql/python/local_search_starter.py [0:0]
def _genTargetInfos(self, zoneNames, replica, inQrs=False):
tabletInfos = {}
if self.tabletInfos:
tabletInfos = json.loads(self.tabletInfos)
targetInfos = []
for zoneName in zoneNames:
tableGroup = {
"id": {
"tgName": zoneName,
"dbName": zoneName
},
"meta": {
"shardCount": 1,
"replicaCount": 0
},
"tables": []
}
tableGroupTables = {}
atables = []
if self.atableList.has_key(zoneName):
atables = self.atableList[zoneName].split(",")
atables.append(zoneName)
zoneGid = None
partitions = None
has_offline_index = True
has_realtime = False
if tabletInfos.has_key(zoneName):
has_offline_index = tabletInfos[zoneName]['has_offline_index']
has_realtime = True
if has_offline_index:
zoneGid = self._getMaxGenerationId(self.indexPath, zoneName)
partitions = self._getPartitions(self.indexPath, zoneName, zoneGid)
else:
zoneGid = tabletInfos[zoneName]["generationId"]
partitions = tabletInfos[zoneName]["partitions"]
fullPartition = "0_65535"
partCnt = len(partitions)
if self.enableMultiPartition:
partCnt = 1
maxPartCnt = len(partitions)
tableGroup["meta"]["shard_count"] = partCnt
for replicaId, partId in product(range(replica), range(partCnt)):
tableInfos = {}
for tableName in atables:
if not tableName:
continue
tablePartition = []
curTableGid = None
curTablePartitions = None
has_offline_index = True
has_realtime = False
if tabletInfos.has_key(tableName):
has_offline_index = tabletInfos[tableName]['has_offline_index']
has_realtime = True
if has_offline_index:
curTableGid = self._getMaxGenerationId(self.indexPath, tableName)
curTablePartitions = self._getPartitions(self.indexPath, tableName, curTableGid)
else:
curTableGid = tabletInfos[tableName]["generationId"]
curTablePartitions = tabletInfos[tableName]["partitions"]
if not self.enableMultiPartition:
curTablePartitionCnt = len(curTablePartitions)
if curTablePartitionCnt == 1:
tablePartition.append(fullPartition)
elif curTablePartitionCnt == maxPartCnt:
tablePartition.append(partitions[partId])
else:
raise Exception(
"table %s : len(curTablePartitions)(%d) != maxPartCnt(%d)" %
(tableName, curTablePartitionCnt, maxPartCnt))
else:
tablePartition = curTablePartitions
tableGid = curTableGid
zoneDirName = self.genRoleName((zoneName, partId, replicaId))
if inQrs:
zoneDirName = "qrs"
tableMode = 0 if not has_realtime else 1 # TM_READ_WRITE
tableType = 3 if not has_realtime else 2 # SPT_TABLET
tmp = {
tableGid: {
"table_mode": tableMode,
"table_type": tableType,
"index_root": self.createRuntimedirLink(zoneDirName),
"config_path": self.createConfigLink(
zoneDirName,
'table',
tableName,
self.offlineConfigPath),
"total_partition_count": len(curTablePartitions),
"partitions": {}}}
for partition in tablePartition:
incVersion = -1
if has_offline_index:
incVersion = self._getMaxIndexVersion(self.indexPath, tableName, tableGid, partition)
tmp[tableGid]["partitions"][partition] = {
"inc_version": incVersion
}
tableInfos[tableName] = tmp
tableGroupTables[tableName] = self._genCatalogTable(
zoneName, zoneName, tableName, tableMode, tableGid)
bizs = os.listdir(self.onlineConfigPath)
bizInfo = {}
if self.enableMultiBiz:
for biz in bizs:
onlineConfig = self.genOnlineConfigPath(self.onlineConfigPath, biz)
bizInfo[biz] = {
"config_path": self.createConfigLink(zoneDirName, 'biz', biz, onlineConfig)
}
if biz in self.modelBiz:
bizInfo[biz]["custom_biz_info"] = {
"biz_type": "model_biz"
}
else:
onlineConfig = self.genOnlineConfigPath(self.onlineConfigPath, bizs[0])
bizInfo['default'] = {
"config_path": self.createConfigLink(zoneDirName, 'biz', 'default', onlineConfig)
}
targetInfo = {
"table_info": tableInfos,
"service_info": {
"part_count": partCnt,
"part_id": partId,
"zone_name": zoneName,
"version": zoneGid
},
"biz_info": bizInfo,
"clean_disk": False
}
targetInfos.append((zoneName, partId, replicaId, targetInfo))
database = {
"dbName": zoneName,
"description": "",
"tableGroups": [],
"udxfs": {},
"tvfs": {}
}
for tableName, catalogTable in tableGroupTables.items():
tableGroup["tables"].append(catalogTable)
database["tableGroups"].append(tableGroup)
return targetInfos