亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

AWS DMS 使用具有大結果集的 DatabaseMigrationService.Client.

AWS DMS 使用具有大結果集的 DatabaseMigrationService.Client.

蝴蝶不菲 2021-12-21 10:42:41
我正在使用 describe_table_statistics 來檢索給定 DMS 任務中的表列表,并有條件地循環使用響應 ['Marker'] 的 describe_table_statistics。當我不使用過濾器時,我得到了正確的記錄數,13k+。當我使用結果集少于 MaxRecords 的過濾器或過濾器組合時,我得到正確的記錄數。但是,當我傳入一個過濾器時,它會獲得比 MaxRecords 更大的記錄集,我得到的記錄比我應該得到的要少得多。這是我檢索表集的函數:def get_dms_task_tables(account, region, task_name, schema_name=None, table_state=None):   tables=[]   max_records=500   filters=[]   if schema_name:      filters.append({'Name':'schema-name', 'Values':[schema_name]})   if table_state:      filters.append({'Name':'table-state', 'Values':[table_state]})   task_arn = get_dms_task_arn(account, region, task_name)   session = boto3.Session(profile_name=account, region_name=region)   client = session.client('dms')   response = client.describe_table_statistics(      ReplicationTaskArn=task_arn      ,Filters=filters      ,MaxRecords=max_records)   tables += response['TableStatistics']   while len(response['TableStatistics']) == max_records:      response = client.describe_table_statistics(         ReplicationTaskArn=task_arn         ,Filters=filters         ,MaxRecords=max_records         ,Marker=response['Marker'])      tables += response['TableStatistics']   return tables為了排除故障,我循環遍歷表格,每張表格打印一行:        print(', '.join((            t['SchemaName']            ,t['TableName']            ,t['TableState'])))當我沒有為“表已完成”的表狀態傳遞過濾器和 grep 時,我通過控制臺獲得了 12k+ 條記錄,這是正確的計數至少從表面上看,響應循環是有效的。當我傳入架構名稱和表狀態過濾條件時,我得到了正確的計數,正如控制臺所確認的那樣,但此計數小于 MaxRecords。當我剛剛傳入“表已完成”的表狀態過濾器時,我只得到 949 條記錄,所以我缺少 11k 條記錄。我嘗試從循環內的 describe_table_statistics 中省略 Filter 參數,但在所有情況下我都得到相同的結果。我懷疑我對循環內的 describe_table_statistics 的調用有問題,但我一直無法在亞馬遜的文檔中找到這樣的例子來確認這一點。
查看完整描述

1 回答

?
長風秋雁

TA貢獻1757條經驗 獲得超7個贊

應用過濾器時,describe_table_statistics 不遵守 MaxRecords 限制。


事實上,它似乎所做的是檢索(2 x MaxRecords),應用過濾器,然后返回該集合?;蛘咚赡軝z索 MaxRecords,應用過濾器,并繼續直到結果集大于 MaxRecords。無論哪種方式,我的 while 條件都是問題所在。


我換了


while len(response['TableStatistics']) == max_records:


while 'Marker' in response:

現在該函數返回正確的記錄數。


順便說一句,我的第一次嘗試是


while len(response['TableStatistics']) >= 1:

但在循環的最后一次迭代時,它拋出了這個錯誤:


KeyError: 'Marker'

完成的工作功能現在看起來是這樣的:


def get_dms_task_tables(account, region, task_name, schema_name=None, table_state=None):

   tables=[]

   max_records=500


   filters=[]

   if schema_name:

      filters.append({'Name':'schema-name', 'Values':[schema_name]})

   if table_state:

      filters.append({'Name':'table-state', 'Values':[table_state]})


   task_arn = get_dms_task_arn(account, region, task_name)


   session = boto3.Session(profile_name=account, region_name=region)

   client = session.client('dms')


   response = client.describe_table_statistics(

      ReplicationTaskArn=task_arn

      ,Filters=filters

      ,MaxRecords=max_records)


   tables += response['TableStatistics']


   while 'Marker' in response:

      response = client.describe_table_statistics(

         ReplicationTaskArn=task_arn

         ,Filters=filters

         ,MaxRecords=max_records

         ,Marker=response['Marker'])


      tables += response['TableStatistics']


   return tables


查看完整回答
反對 回復 2021-12-21
  • 1 回答
  • 0 關注
  • 197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號