Share via


Operazioni di velocità effettiva (UR/s) con l'interfaccia della riga di comando di Azure per un keyspace o una tabella per Azure Cosmos DB - API per Cassandra

SI APPLICA A: Cassandra

Lo script di questo articolo crea un keyspace Cassandra con velocità effettiva condivisa e una tabella Cassandra con velocità effettiva dedicata, quindi aggiorna la velocità effettiva per il keyspace e la tabella. Lo script esegue quindi la migrazione dalla velocità effettiva standard alla velocità effettiva con scalabilità automatica e, al termine della migrazione, legge il valore della velocità effettiva con scalabilità automatica.

Se non si ha una sottoscrizione di Azure, creare un account Azure gratuito prima di iniziare.

Prerequisiti

  • Questo articolo richiede l'interfaccia della riga di comando di Azure 2.12.1 o versioni successive. Eseguire az --version per trovare la versione. Se è necessario eseguire l'installazione o l'aggiornamento, vedere Installare l'interfaccia della riga di comando di Azure. Se si usa Azure Cloud Shell, la versione più recente è già installata.

Script di esempio

Avviare Azure Cloud Shell

Azure Cloud Shell è una shell interattiva gratuita che può essere usata per eseguire la procedura di questo articolo. Include strumenti comuni di Azure preinstallati e configurati per l'uso con l'account.

Per aprire Cloud Shell, basta selezionare Prova nell'angolo superiore destro di un blocco di codice. È anche possibile avviare Cloud Shell in una scheda separata del browser visitando https://shell.azure.com.

Quando si apre Cloud Shell, verificare che sia selezionato Bash per l'ambiente. Le sessioni successive useranno l'interfaccia della riga di comando di Azure in un ambiente Bash. Selezionare Copia per copiare i blocchi di codice, incollarli in Cloud Shell e premere Invio per eseguirli.

Accedere ad Azure

Cloud Shell viene autenticato automaticamente con l'account iniziale con cui è stato eseguito l'accesso. Usare lo script seguente per accedere usando una sottoscrizione diversa, sostituendo <Subscription ID> con l'ID sottoscrizione di Azure. Se non si ha una sottoscrizione di Azure, creare un account Azure gratuito prima di iniziare.

subscription="<subscriptionId>" # add subscription here

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

Per altre informazioni, vedere Impostare la sottoscrizione attiva oppure Accedere in modo interattivo

Eseguire lo script

# 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

Pulire le risorse

Usare il comando seguente per rimuovere il gruppo di risorse e tutte le risorse associate usando il comando az group delete, a meno che queste risorse non siano ancora necessarie. La creazione e l'eliminazione di alcune di queste risorse può richiedere tempo.

az group delete --name $resourceGroup

Informazioni di riferimento per l'esempio

Questo script usa i comandi seguenti. Ogni comando della tabella include collegamenti alla documentazione specifica del comando.

Comando Note
az group create Consente di creare un gruppo di risorse in cui sono archiviate tutte le risorse.
az cosmosdb create Crea un account Azure Cosmos DB.
az cosmosdb cassandra keyspace create Crea un keyspace Cassandra di Azure Cosmos DB.
az cosmosdb cassandra table create Crea una tabella Cassandra di Azure Cosmos DB.
az cosmosdb cassandra keyspace throughput update Aggiorna il valore di UR/s per un keyspace Cassandra di Azure Cosmos DB.
az cosmosdb cassandra table throughput update Aggiorna il valore di UR/s per una tabella Cassandra di Azure Cosmos DB.
az cosmosdb cassandra keyspace throughput migrate Esegue la migrazione della velocità effettiva per un keyspace Cassandra di Azure Cosmos DB.
az cosmosdb cassandra table throughput migrate Esegue la migrazione della velocità effettiva per una tabella Cassandra di Azure Cosmos DB.
az group delete Consente di eliminare un gruppo di risorse incluse tutte le risorse annidate.

Passaggi successivi

Per altre informazioni sull'interfaccia della riga di comando di Azure Cosmos DB, vedere la relativa documentazione.