Share via


Azure Cosmos DB için anahtar alanı veya tablo için Azure CLI ile aktarım hızı (RU/sn) işlemleri - Cassandra için API

ŞUNLAR IÇIN GEÇERLIDIR: Cassandra

Bu makaledeki betik, paylaşılan aktarım hızına sahip bir Cassandra anahtar alanı ve ayrılmış aktarım hızına sahip bir Cassandra tablosu oluşturur, ardından hem anahtar alanı hem de tablo için aktarım hızını güncelleştirir. Betik daha sonra standarttan otomatik ölçeklendirme aktarım hızına geçirildikten sonra otomatik ölçeklendirme aktarım hızının değerini okur.

Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.

Ön koşullar

  • Azure Cloud Shell'de Bash ortamını kullanın. Daha fazla bilgi için bkz . Azure Cloud Shell'de Bash için hızlı başlangıç.

  • CLI başvuru komutlarını yerel olarak çalıştırmayı tercih ediyorsanız Azure CLI'yı yükleyin . Windows veya macOS üzerinde çalışıyorsanız Azure CLI’yi bir Docker kapsayıcısında çalıştırmayı değerlendirin. Daha fazla bilgi için bkz . Docker kapsayıcısında Azure CLI'yi çalıştırma.

    • Yerel yükleme kullanıyorsanız az login komutunu kullanarak Azure CLI ile oturum açın. Kimlik doğrulama işlemini tamamlamak için terminalinizde görüntülenen adımları izleyin. Diğer oturum açma seçenekleri için bkz . Azure CLI ile oturum açma.

    • İstendiğinde, ilk kullanımda Azure CLI uzantısını yükleyin. Uzantılar hakkında daha fazla bilgi için bkz. Azure CLI ile uzantıları kullanma.

    • Yüklü sürümü ve bağımlı kitaplıkları bulmak için az version komutunu çalıştırın. En son sürüme yükseltmek için az upgrade komutunu çalıştırın.

  • Bu makale, Azure CLI sürüm 2.12.1 veya üzerini gerektirir. Sürümü bulmak için az --version komutunu çalıştırın. Yüklemeniz veya yükseltmeniz gerekirse, bkz. Azure CLI yükleme. Azure Cloud Shell kullanılıyorsa en son sürüm zaten yüklüdür.

Örnek betik

Azure Cloud Shell'i başlatma

Azure Cloud Shell, bu makaledeki adımları çalıştırmak için kullanabileceğiniz ücretsiz bir etkileşimli kabuktur. Yaygın Azure araçları, kabuğa önceden yüklenmiştir ve kabuk, hesabınızla birlikte kullanılacak şekilde yapılandırılmıştır.

Cloud Shell'i açmak için kod bloğunun sağ üst köşesinden Deneyin'i seçmeniz yeterlidir. İsterseniz https://shell.azure.com adresine giderek Cloud Shell'i ayrı bir tarayıcı sekmesinde de başlatabilirsiniz.

Cloud Shell açıldığında ortamınız için Bash'in seçili olduğunu doğrulayın. Sonraki oturumlarda Bash ortamında Azure CLI kullanılır, kod bloklarını kopyalamak için Kopyala'yı seçin, Cloud Shell'e yapıştırın ve çalıştırmak için Enter tuşuna basın.

Azure'da oturum açma

Cloud Shell'de oturum açılan ilk hesapta otomatik olarak kimlik doğrulaması yapılır. Farklı bir abonelik kullanarak oturum açmak için aşağıdaki betiği kullanın ve yerine <Subscription ID> Azure Abonelik Kimliğiniz yazın. Azure aboneliğiniz yoksa başlamadan önce birücretsiz Azure hesabı oluşturun.

subscription="<subscriptionId>" # add subscription here

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

Daha fazla bilgi için bkz . Etkin aboneliği ayarlama veya etkileşimli olarak oturum açma

Betiği çalıştırın

# 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

Kaynakları temizleme

Bu kaynaklara sürekli ihtiyaç duymadığınız sürece az group delete komutunu kullanarak kaynak grubunu ve onunla ilişkili tüm kaynakları kaldırmak için aşağıdaki komutu kullanın. Bu kaynaklardan bazılarının oluşturulması ve silinmesi biraz zaman alabilir.

az group delete --name $resourceGroup

Örnek başvuru

Bu betik aşağıdaki komutları kullanır. Tablodaki her komut, komuta özgü belgelere yönlendirir.

Command Notlar
az group create Tüm kaynakların depolandığı bir kaynak grubu oluşturur.
az cosmosdb create Azure Cosmos DB hesabı oluşturur.
az cosmosdb cassandra keyspace create Azure Cosmos DB Cassandra anahtar alanı oluşturur.
az cosmosdb cassandra table create Azure Cosmos DB Cassandra tablosu oluşturur.
az cosmosdb cassandra keyspace aktarım hızı güncelleştirmesi Azure Cosmos DB Cassandra anahtar alanı için RU/sn'yi güncelleştirin.
az cosmosdb cassandra table throughput update Azure Cosmos DB Cassandra tablosu için RU/sn'yi güncelleştirin.
az cosmosdb cassandra keyspace aktarım hızı geçişi Azure Cosmos DB Cassandra anahtar alanı için aktarım hızını geçirme.
az cosmosdb cassandra table throughput migrate Azure Cosmos DB Cassandra tablosu için aktarım hızını geçirme.
az group delete Bir kaynak grubunu tüm iç içe geçmiş kaynaklar dahil siler.

Sonraki adımlar

Azure Cosmos DB CLI hakkında daha fazla bilgi için bkz . Azure Cosmos DB CLI belgeleri.