مشاركة عبر


عمليات معدل النقل (RU/s) مع Azure CLI لجدول Azure Cosmos DB للجدول

ينطبق على: جدول

ينشئ البرنامج النصي في هذه المقالة واجهة برمجة تطبيقات لجدول الجدول ثم يقوم بتحديث معدل النقل للجدول. ثم ينتقل البرنامج النصي من القياسي إلى معدل النقل التلقائي ثم يقرأ قيمة معدل النقل التلقائي بعد ترحيله.

إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

المتطلبات الأساسية

  • تتطلب هذه المقالة الإصدار 2.12.1 أو أحدث. قم بتشغيل az --version للعثور على الإصدار. إذا كنت بحاجة إلى التثبيت أو الترقية، فراجع تثبيت Azure CLI. إذا كنت تستخدم Azure Cloud Shell، يتم تثبيت أحدث إصدار بالفعل.

نموذج البرنامج النصي

إطلاق Azure Cloud Shell

Azure Cloud Shell هو shell تفاعلية مجانية التي يمكنك استخدامها لتشغيل الخطوات في هذه المقالة. يحتوي على أدوات Azure الشائعة المثبتة مسبقًا والمهيئة للاستخدام مع حسابك.

لفتح Cloud Shell، ما عليك سوى تحديد جربه من الزاوية اليمنى العليا من مجموعة التعليمات البرمجية. يمكنك أيضًا تشغيل Cloud Shell في علامة تبويب مستعرض منفصلة بالانتقال إلى https://shell.azure.com.

عند فتح Cloud Shell، تحقق من تحديد Bash لبيئتك. ستستخدم الجلسات اللاحقة Azure CLI في بيئة Bash، حدد نسخ لنسخ كتل التعليمات البرمجية، وألصقها في Cloud Shell، واضغط على Enter لتشغيلها.

تسجيل الدخول إلى Azure

يُصادق Cloud Shell تلقائياً بموجب الحساب الأولي الذي سُجل الدخول به. استخدم البرنامج النصي التالي لتسجيل الدخول باستخدام اشتراك مختلف، واستبدال subscriptionId بمعرف اشتراك Azure الخاص بك.

إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

subscription="subscriptionId" # Set Azure subscription ID here

az account set -s $subscription # ...or use 'az login'

لمزيد من المعلومات، راجع تعيين الاشتراك النشط أو تسجيل الدخول بشكل تفاعلي.

تشغيل البرنامج النصي

# Throughput operations for a Table API table

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="throughput-table-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
table="msdocs-table-cosmos-$randomIdentifier"
originalThroughput=400
updateThroughput=500

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for Table API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableTable

# Create a Table API Table with autoscale
echo "Create $table with $maxThroughput"
az cosmosdb table create --account-name $account --resource-group $resourceGroup --name $table --throughput $originalThroughput

# Throughput operations for Table API table
#   Read the current throughput
#   Read the minimum throughput
#   Make sure the updated throughput is not less than the minimum
#   Update the throughput
#   Migrate between standard (manual) and autoscale throughput
#   Read the autoscale max throughput

# Retrieve the current provisioned table throughput
az cosmosdb table throughput show --name $table --resource-group $resourceGroup --account-name $account --query resource.throughput -o tsv

# Retrieve the minimum allowable table throughput
minimumThroughput=$(az cosmosdb table throughput show --resource-group $resourceGroup --account-name $account --name $table --query resource.minimumThroughput -o tsv)
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
    updateThroughput=$minimumThroughput
fi

# Update table throughput
echo "Updating $table throughput to $updateThroughput"
az cosmosdb table throughput update --account-name $account --resource-group $resourceGroup --name $table --throughput $updateThroughput

# Migrate the table from standard (manual) throughput to autoscale throughput
az cosmosdb table throughput migrate --account-name $account --resource-group $resourceGroup --name $table --throughput-type 'autoscale'

# Retrieve current autoscale provisioned max table throughput
az cosmosdb table throughput show --account-name $account --resource-group $resourceGroup --name $table --query resource.autoscaleSettings.maxThroughput -o tsv

تنظيف الموارد

استخدم الأمر التالي لإزالة مجموعة الموارد وجميع الموارد المقترنة بها باستخدام الأمر az group delete - إلا إذا وُجدت حاجة مستمرة لهذه الموارد. قد يستغرق إنشاء بعض هذه الموارد بعض الوقت، وكذلك حذفها.

az group delete --name $resourceGroup

نموذج مرجع

يستخدم هذا البرنامج النصي الأوامر التالية. يرتبط كل أمر في الجدول بأمر وثائق معينة.

الأمر ملاحظات
az group create إنشاء مجموعة موارد يتم تخزين كل الموارد فيها.
إنشاء az cosmosdb ينشئ حساب Azure Cosmos DB.
az cosmosdb table create إنشاء جدول Azure Cosmos DB Table API.
az cosmosdb table throughput update تحديث معدل النقل لجدول Azure Cosmos DB Table API.
az cosmosdb table throughput migrate ترحيل معدل النقل لجدول Azure Cosmos DB Table API.
حذف مجموعة az يحذف مجموعة الموارد بما في ذلك جميع الموارد المتداخلة.

الخطوات التالية

لمزيد من المعلومات حول Azure Cosmos DB CLI، راجع وثائق Azure Cosmos DB CLI.