Dataflödesåtgärder (RU/s) med PowerShell för ett nyckelområde eller en tabell för Azure Cosmos DB – API för Cassandra
GÄLLER FÖR: Kassandra
Kommentar
Vi rekommenderar att du använder Azure Az PowerShell-modulen för att interagera med Azure. Se Installera Azure PowerShell för att komma igång. Information om hur du migrerar till Az PowerShell-modulen finns i artikeln om att migrera Azure PowerShell från AzureRM till Az.
Det här exemplet kräver Azure PowerShell Az 5.4.0 eller senare. Kör Get-Module -ListAvailable Az
för att se vilka versioner som är installerade.
Om du behöver installera kan du läsa Installera Azure PowerShell-modulen.
Kör Connect-AzAccount för att logga in på Azure.
Beräkna dataflöde
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Get keyspace or table throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$keyspaceName = "mykeyspace" # Keyspace with shared throughput
$tableName = "mytable" # Table with dedicated throughput
# --------------------------------------------------
Write-Host "Get keyspace shared throughput"
Get-AzCosmosDBCassandraKeyspaceThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $keyspaceName
Write-Host "Get table dedicated throughput"
Get-AzCosmosDBCassandraTableThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -KeyspaceName $keyspaceName `
-Name $tableName
Uppdatera dataflöde
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Update table throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$keyspaceName = "mykeyspace"
$tableName = "mytable"
$newRUs = 500
# --------------------------------------------------
$throughput = Get-AzCosmosDBCassandraTableThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -KeyspaceName $keyspaceName -Name $tableName
$currentRUs = $throughput.Throughput
$minimumRUs = $throughput.MinimumThroughput
Write-Host "Current throughput is $currentRUs. Minimum allowed throughput is $minimumRUs."
if ([int]$newRUs -lt [int]$minimumRUs) {
Write-Host "Requested new throughput of $newRUs is less than minimum allowed throughput of $minimumRUs."
Write-Host "Using minimum allowed throughput of $minimumRUs instead."
$newRUs = $minimumRUs
}
if ([int]$newRUs -eq [int]$currentRUs) {
Write-Host "New throughput is the same as current throughput. No change needed."
}
else {
Write-Host "Updating throughput to $newRUs."
Update-AzCosmosDBCassandraTableThroughput -ResourceGroupName $resourceGroupName `
-AccountName $accountName -KeyspaceName $keyspaceName `
-Name $tableName -Throughput $newRUs
}
Migrera dataflöde
# Reference: Az.CosmosDB | https://docs.microsoft.com/powershell/module/az.cosmosdb
# --------------------------------------------------
# Purpose
# Migrate a keyspace or table to autoscale or standard (manual) throughput
# --------------------------------------------------
# Variables - ***** SUBSTITUTE YOUR VALUES *****
$resourceGroupName = "myResourceGroup" # Resource Group must already exist
$accountName = "myaccount" # Must be all lower case
$keyspaceName = "myKeyspace"
$tableName = "myTable"
# --------------------------------------------------
Write-Host "Migrate keyspace with standard throughput to autoscale throughput."
Invoke-AzCosmosDBCassandraKeyspaceThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $keyspaceName -ThroughputType Autoscale
Write-Host "Migrate keyspace with autoscale throughput to standard throughput."
Invoke-AzCosmosDBCassandraKeyspaceThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -Name $keyspaceName -ThroughputType Manual
Write-Host "Migrate table with standard throughput to autoscale throughput."
Invoke-AzCosmosDBCassandraTableThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -KeyspaceName $keyspaceName -Name $tableName -ThroughputType Autoscale
Write-Host "Migrate table with autoscale throughput to standard throughput."
Invoke-AzCosmosDBCassandraTableThroughputMigration -ResourceGroupName $resourceGroupName `
-AccountName $accountName -KeyspaceName $keyspaceName -Name $tableName -ThroughputType Manual
Rensa distribution
När skriptexemplet har körts kan följande kommando användas för att ta bort resursgruppen och alla resurser som är kopplade till den.
Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"
Förklaring av skript
Det här skriptet använder följande kommandon. Varje kommando i tabellen länkar till kommandospecifik dokumentation.
Command | Kommentar |
---|---|
Azure Cosmos DB | |
Get-AzCosmosDBCassandraKeyspaceThroughput | Hämtar dataflödesvärdet för API:et för Cassandra Keyspace. |
Get-AzCosmosDBCassandraTableThroughput | Hämtar dataflödesvärdet för API:et för Cassandra-tabellen. |
Update-AzCosmosDBCassandraKeyspaceThroughput | Uppdaterar dataflödesvärdet för API:et för Cassandra Keyspace. |
Update-AzCosmosDBCassandraTableThroughput | Uppdaterar dataflödesvärdet för API:et för Cassandra-tabellen. |
Invoke-AzCosmosDBCassandraKeyspaceThroughputMigration | Migrera dataflöde för ett API för Cassandra Keyspace. |
Invoke-AzCosmosDBCassandraTableThroughputMigration | Migrera dataflöde för ett API för Cassandra Table. |
Azure-resursgrupper | |
Remove-AzResourceGroup | Tar bort en resursgrupp, inklusive alla kapslade resurser. |
Nästa steg
Mer information om Azure PowerShell finns i Azure PowerShell-dokumentationen.