عمليات معدل النقل (RU/s) باستخدام Azure CLI لمساحة مفاتيح أو جدول ل Azure Cosmos DB - API ل Cassandra

ينطبق على: كاساندرا

يقوم البرنامج النصي في هذه المقالة بإنشاء مساحة مفاتيح Cassandra مع معدل نقل مشترك وجدول Cassandra مع معدل نقل مخصص، ثم يقوم بتحديث معدل النقل لمساحة المفاتيح والجدول على حدٍ سواء. ثم ينتقل البرنامج النصي من القياسي إلى معدل النقل التلقائي ثم يقرأ قيمة معدل النقل التلقائي بعد ترحيله.

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

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

  • تتطلب هذه المقالة إصدار Azure CLI 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 تلقائياً بموجب الحساب الأولي الذي سُجل الدخول به. استخدم البرنامج النصي التالي لتسجيل الدخول باستخدام اشتراك مختلف، واستبدل <Subscription ID> بمعرّف اشتراك Azure الخاص بك. إذا لم يكن لديك اشتراك في Azure، فأنشئ حساب Azure مجاني قبل أن تبدأ.

subscription="<subscriptionId>" # add subscription here

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

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

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

# Throughput operations for a Cassandra keyspace and table

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

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

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

# Create Cassandra keyspace
echo "Creating $keySpace with $originalThroughput"
az cosmosdb cassandra keyspace create --account-name $account --resource-group $resourceGroup --name $keySpace --throughput $originalThroughput

# Define the schema for the table
printf ' 
{
    "columns": [
        {"name": "columnA","type": "uuid"}, 
        {"name": "columnB","type": "text"}
    ],
    "partitionKeys": [{"name": "columnA"}]
}' > "schema-$randomIdentifier.json"

# Create the Cassandra table
echo "Creating $table with $originalThroughput"
az cosmosdb cassandra table create --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --throughput $originalThroughput --schema @schema-$randomIdentifier.json

# Clean up temporary schema file
rm -f "schema-$randomIdentifier.json"

# Throughput operations for Cassandra API keyspace
#   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 keyspace throughput
az cosmosdb cassandra keyspace throughput show --account-name $account --resource-group $resourceGroup --name $keySpace --query resource.throughput -o tsv

# Retrieve the minimum allowable keyspace throughput
minimumThroughput=$(az cosmosdb cassandra keyspace throughput show --account-name $account --resource-group $resourceGroup --name $keySpace --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 keyspace throughput
echo "Updating $keyspace throughput to $updateThroughput"
az cosmosdb cassandra keyspace throughput update --account-name $account --resource-group $resourceGroup --name $keySpace --throughput $updateThroughput

# Migrate the keyspace from standard (manual) throughput to autoscale throughput
az cosmosdb cassandra keyspace throughput migrate --account-name $account --resource-group $resourceGroup --name $keySpace --throughput-type "autoscale"

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

# Throughput operations for Cassandra 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 cassandra table throughput show --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --query resource.throughput -o tsv

# Retrieve the minimum allowable table throughput
minimumThroughput=$(az cosmosdb cassandra table throughput show --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --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 cassandra table throughput update --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --name $table --throughput $updateThroughput

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

# Retrieve the current autoscale provisioned max table throughput
az cosmosdb cassandra table throughput show --account-name $account --resource-group $resourceGroup --keyspace-name $keySpace --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 cassandra إنشاء مساحة مفتاح Azure Cosmos DB Cassandra.
إنشاء جدول az cosmosdb cassandra إنشاء جدول Azure Cosmos DB Cassandra.
تحديث معدل نقل مساحة مفاتيح az cosmosdb cassandra تحديث RU/s لمساحة مفاتيح Azure Cosmos DB Cassandra.
تحديث معدل نقل جدول az cosmosdb cassandra تحديث RU/s لجدول Azure Cosmos DB Cassandra.
ترحيل معدل نقل مساحة مفاتيح az cosmosdb cassandra ترحيل معدل النقل لمساحة مفاتيح Azure Cosmos DB Cassandra.
ترحيل معدل نقل مساحة مفاتيح az cosmosdb cassandra ترحيل معدل النقل لجدول Azure Cosmos DB Cassandra.
حذف مجموعة az يحذف مجموعة الموارد بما في ذلك جميع الموارد المتداخلة.

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

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