Operace propustnosti (RU/s) pomocí Azure CLI pro prostor klíčů nebo tabulku pro službu Azure Cosmos DB – ROZHRANÍ API pro Cassandra

PLATÍ PRO: Cassandra

Skript v tomto článku vytvoří prostor klíčů Cassandra se sdílenou propustností a tabulkou Cassandra s vyhrazenou propustností a pak aktualizuje propustnost pro prostor klíčů i tabulku. Skript se pak migruje ze standardu na propustnost automatického škálování a potom načte hodnotu propustnosti automatického škálování po migraci.

Pokud ještě nemáte předplatné Azure, vytvořte si bezplatný účet Azure před tím, než začnete.

Předpoklady

  • Tento článek vyžaduje Azure CLI verze 2.12.1 nebo novější. Verzi zjistíte spuštěním příkazu az --version. Pokud potřebujete instalaci nebo upgrade, přečtěte si téma Instalace Azure CLI. Pokud používáte Azure Cloud Shell, je už nainstalovaná nejnovější verze.

Ukázkový skript

Spuštění služby Azure Cloud Shell

Azure Cloud Shell je bezplatné interaktivní prostředí, které můžete použít k provedení kroků v tomto článku. Má předinstalované obecné nástroje Azure, které jsou nakonfigurované pro použití s vaším účtem.

Pokud chcete otevřít Cloud Shell, vyberte položku Vyzkoušet v pravém horním rohu bloku kódu. Cloud Shell můžete spustit také na samostatné kartě prohlížeče na adrese https://shell.azure.com.

Po otevření Cloud Shellu ověřte, že je pro vaše prostředí vybraný Bash . Následující relace budou používat Azure CLI v prostředí Bash, výběrem možnosti Kopírovat zkopírujte bloky kódu, vložte ho do Cloud Shellu a stisknutím klávesy Enter ho spusťte.

Přihlášení k Azure

Cloud Shell se automaticky ověřuje pod počátečním přihlášeným účtem. Pomocí následujícího skriptu se přihlaste pomocí jiného předplatného a nahraďte <Subscription ID> ID předplatného Azure. Pokud ještě nemáte předplatné Azure, vytvořte si bezplatný účet Azure před tím, než začnete.

subscription="<subscriptionId>" # add subscription here

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

Další informace najdete v tématu Nastavení aktivního předplatného nebo interaktivního přihlášení.

Spuštění skriptu

# 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

Vyčištění prostředků

Pomocí následujícího příkazu odeberte skupinu prostředků a všechny prostředky přidružené k ní pomocí příkazu az group delete – pokud tyto prostředky nepotřebujete. Vytvoření některých z těchto prostředků a odstranění může chvíli trvat.

az group delete --name $resourceGroup

Ukázkový odkaz

Tento skript používá následující příkazy. Každý příkaz v tabulce odkazuje na příslušnou část dokumentace.

Příkaz Notes
az group create Vytvoří skupinu prostředků, ve které se ukládají všechny prostředky.
az cosmosdb create Vytvoří účet služby Azure Cosmos DB.
az cosmosdb cassandra keyspace create Vytvoří prostor klíčů Cassandra služby Azure Cosmos DB.
az cosmosdb cassandra table create Vytvoří tabulku Cassandra služby Azure Cosmos DB.
az cosmosdb cassandra keyspace update Aktualizujte RU/s pro prostor klíčů Cassandra služby Azure Cosmos DB.
az cosmosdb cassandra table throughput update Aktualizujte RU/s pro tabulku Cassandra služby Azure Cosmos DB.
az cosmosdb cassandra keyspace throughput migrate Migrace propustnosti pro prostor klíčů Cassandra služby Azure Cosmos DB
az cosmosdb cassandra table throughput migrate Migrace propustnosti pro tabulku Cassandra služby Azure Cosmos DB
az group delete Odstraní skupinu prostředků včetně všech vnořených prostředků.

Další kroky

Další informace o rozhraní příkazového řádku služby Azure Cosmos DB najdete v dokumentaci k rozhraní příkazového řádku služby Azure Cosmos DB.