Megosztás a következőn keresztül:


Átviteli sebesség (RU/s) műveletek az Azure CLI-vel az Azure Cosmos DB kulcsteréhez vagy tábláihoz – API a Cassandra-hoz

A KÖVETKEZŐKRE VONATKOZIK: Cassandra

A cikkben szereplő szkript létrehoz egy Megosztott átviteli sebességgel rendelkező Cassandra-kulcsteret és egy dedikált átviteli sebességet tartalmazó Cassandra-táblát, majd frissíti a kulcstér és a tábla átviteli sebességét. A szkript ezután a standardról az automatikus skálázási átviteli sebességre migrál, majd beolvassa az automatikus skálázási átviteli sebesség értékét a migrálás után.

Ha nem rendelkezik Azure-előfizetéssel, első lépésként hozzon létre egy ingyenes Azure-fiókot.

Előfeltételek

  • Ez a cikk az Azure CLI 2.12.1-es vagy újabb verzióját igényli. A verzió azonosításához futtassa a következőt: az --version. Ha telepíteni vagy frissíteni szeretne: Az Azure CLI telepítése. Az Azure Cloud Shell használata esetén a legújabb verzió már telepítve van.

Példaszkript

Az Azure Cloud Shell elindítása

Az Azure Cloud Shell egy olyan ingyenes interaktív kezelőfelület, amelyet a jelen cikkben található lépések futtatására használhat. A fiókjával való használat érdekében a gyakran használt Azure-eszközök már előre telepítve és konfigurálva vannak rajta.

A Cloud Shell megnyitásához válassza a Kipróbálás lehetőséget egy kódblokk jobb felső sarkában. A Cloud Shellt egy külön böngészőlapon is elindíthatja a https://shell.azure.com cím megnyitásával.

Amikor megnyílik a Cloud Shell, ellenőrizze, hogy a Bash ki van-e jelölve a környezetében. A következő munkamenetek az Azure CLI-t használják Bash-környezetben, a Másolás lehetőséget választva másolja ki a kódblokkokat, illessze be a Cloud Shellbe, és nyomja le az Enter billentyűt a futtatáshoz.

Bejelentkezés az Azure-ba

A Cloud Shell automatikusan hitelesítve lesz a kezdeti fiókkal, amellyel bejelentkezett. A következő szkripttel egy másik előfizetéssel jelentkezhet be, lecserélve <Subscription ID> az Azure-előfizetés azonosítóját. Ha nem rendelkezik Azure-előfizetéssel, első lépésként hozzon létre egy ingyenes Azure-fiókot.

subscription="<subscriptionId>" # add subscription here

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

További információ: Aktív előfizetés beállítása vagy interaktív bejelentkezés

A szkript futtatása

# 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 erőforrások eltávolítása

Az alábbi paranccsal eltávolíthatja az erőforráscsoportot és a hozzá társított összes erőforrást az az csoporttörlés paranccsal – kivéve, ha folyamatosan szüksége van ezekre az erőforrásokra. Ezen erőforrások némelyikének létrehozása és törlése eltarthat egy ideig.

az group delete --name $resourceGroup

Mintahivatkozás

A szkript a következő parancsokat használja. A táblázatban lévő összes parancs a hozzá tartozó dokumentációra hivatkozik.

Parancs Jegyzetek
az group create Létrehoz egy erőforráscsoportot, amely az összes erőforrást tárolja.
az cosmosdb create Létrehoz egy Azure Cosmos DB-fiókot.
az cosmosdb cassandra keyspace create Létrehoz egy Azure Cosmos DB Cassandra-kulcsteret.
az cosmosdb cassandra table create Létrehoz egy Azure Cosmos DB Cassandra-táblát.
az cosmosdb cassandra keyspace throughput update Frissítse az RU/s-t egy Azure Cosmos DB Cassandra-kulcstérhez.
az cosmosdb cassandra table throughput update Azure Cosmos DB Cassandra-tábla ru/s frissítése.
az cosmosdb cassandra keyspace throughput migrate Azure Cosmos DB Cassandra-kulcstér átviteli sebességének migrálása.
az cosmosdb cassandra table throughput migrate Azure Cosmos DB Cassandra-tábla átviteli sebességének migrálása.
az group delete Töröl egy erőforráscsoportot az összes beágyazott erőforrással együtt.

Következő lépések

Az Azure Cosmos DB CLI-vel kapcsolatos további információkért tekintse meg az Azure Cosmos DB CLI dokumentációját.