Delen via


Doorvoerbewerkingen (RU/s) met Azure CLI voor een keyspace of tabel voor Azure Cosmos DB - API voor Cassandra

VAN TOEPASSING OP: Cassandra

Met het script in dit artikel maakt u een Cassandra-keyspace met gedeelde doorvoer en een Cassandra-tabel met toegewezen doorvoer, waarna de doorvoer voor zowel de keyspace als de tabel wordt bijgewerkt. Met het script wordt de migratie van standaarddoorvoer naar doorvoer met automatische schaalaanpassing uitgevoerd en de waarde van doorvoer met automatische schaalaanpassing gelezen nadat de migratie is voltooid.

Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.

Vereisten

  • Voor dit artikel is Azure CLI versie 2.12.1 of hoger vereist. Voer az --version uit om de versie te bekijken. Als u Azure CLI 2.0 wilt installeren of upgraden, raadpleegt u Azure CLI 2.0 installeren. Als u Azure Cloud Shell gebruikt, is de nieuwste versie al geïnstalleerd.

Voorbeeldscript

Azure Cloud Shell starten

Azure Cloud Shell is een gratis interactieve shell waarmee u de stappen in dit artikel kunt uitvoeren. In deze shell zijn algemene Azure-hulpprogramma's vooraf geïnstalleerd en geconfigureerd voor gebruik met uw account.

Als u Cloud Shell wilt openen, selecteert u Proberen in de rechterbovenhoek van een codeblok. U kunt Cloud Shell ook openen in een afzonderlijk browsertabblad door naar https://shell.azure.com te gaan.

Wanneer Cloud Shell wordt geopend, controleert u of Bash is geselecteerd voor uw omgeving. Volgende sessies gebruiken Azure CLI in een Bash-omgeving, selecteer Kopiëren om de codeblokken te kopiëren, plak deze in Cloud Shell en druk op Enter om deze uit te voeren.

Aanmelden bij Azure

Cloud Shell wordt automatisch geverifieerd onder het eerste account waarmee is aangemeld. Gebruik het volgende script om u aan te melden met een ander abonnement, waarbij u <Subscription ID> uw Azure-abonnements-id vervangt. Als u geen Azure-abonnement hebt, kunt u een gratis Azure-account maken voordat u begint.

subscription="<subscriptionId>" # add subscription here

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

Zie Voor meer informatie het instellen van een actief abonnement of het interactief aanmelden

Het script uitvoeren

# 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

Resources opschonen

Gebruik de volgende opdracht om de resourcegroep en alle bijbehorende resources te verwijderen met behulp van de opdracht az group delete - tenzij u deze resources voortdurend nodig hebt. Het kan even duren voordat sommige van deze resources zijn gemaakt en dat deze kunnen worden verwijderd.

az group delete --name $resourceGroup

Voorbeeldverwijzing

In dit script worden de volgende opdrachten gebruikt. Elke opdracht in de tabel is een koppeling naar specifieke documentatie over de opdracht.

Opdracht Opmerkingen
az group create Hiermee wordt een resourcegroep gemaakt waarin alle resources worden opgeslagen.
az cosmosdb create Hiermee wordt een Azure Cosmos DB-account gemaakt.
az cosmosdb cassandra keyspace create Hiermee maakt u een Azure Cosmos DB Cassandra-keyspace.
az cosmosdb cassandra table create Hiermee maakt u een Azure Cosmos DB Cassandra-tabel.
az cosmosdb cassandra keyspace throughput update RU/s bijwerken voor een Azure Cosmos DB Cassandra-keyspace.
az cosmosdb cassandra table throughput update RU/s bijwerken voor een Azure Cosmos DB Cassandra-tabel.
az cosmosdb cassandra keyspace throughput migrate Doorvoer migreren voor een Azure Cosmos DB Cassandra-keyspace.
az cosmosdb cassandra table throughput migrate Doorvoer migreren voor een Azure Cosmos DB Cassandra-tabel.
az group delete Hiermee verwijdert u een resourcegroep met inbegrip van alle ingesloten resources.

Volgende stappen

Raadpleeg de documentatie van Azure Cosmos DB CLI voor meer informatie over de Azure Cosmos DB CLI.