Compartilhar via


Operações de taxa de transferência (RU/s) com o PowerShell para um keyspace ou uma tabela do Azure Cosmos DB – API for Cassandra

APLICA-SE AO: Cassandra

Observação

Recomendamos que você use o módulo Az PowerShell do Azure para interagir com o Azure. Para começar, consulte Instalar o Azure PowerShell. Para saber como migrar para o módulo Az PowerShell, confira Migrar o Azure PowerShell do AzureRM para o Az.

Este exemplo exige o Azure PowerShell Az 5.4.0 ou posterior. Execute Get-Module -ListAvailable Az para ver quais versões estão instaladas. Se é preciso instalar, consulte Instalar o módulo do Azure PowerShell.

Execute Connect-AzAccount para entrar no Azure.

Obter taxa de transferência

# 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

Atualizar a taxa de transferência

# 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
}

Migrar a taxa de transferência

# 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

Limpar a implantação

Após a execução do script de exemplo, o comando a seguir pode ser usado para remover o grupo de recursos e todos os recursos associados a ele.

Remove-AzResourceGroup -ResourceGroupName "myResourceGroup"

Explicação sobre o script

Este script usa os comandos a seguir. Cada comando da tabela é vinculado à documentação específica do comando.

Comando Observações
Azure Cosmos DB
Get-AzCosmosDBCassandraKeyspaceThroughput Obtém o valor de taxa de transferência do keyspace da API for Cassandra.
Get-AzCosmosDBCassandraTableThroughput Obtém o valor de taxa de transferência da tabela da API for Cassandra.
Update-AzCosmosDBCassandraKeyspaceThroughput Atualiza o valor de taxa de transferência do keyspace da API for Cassandra.
Update-AzCosmosDBCassandraTableThroughput Atualiza o valor de taxa de transferência da tabela da API for Cassandra.
Invoke-AzCosmosDBCassandraKeyspaceThroughputMigration Migra a taxa de transferência para um keyspace da API for Cassandra.
Invoke-AzCosmosDBCassandraTableThroughputMigration Migra a taxa de transferência para uma tabela da API for Cassandra.
Grupos de recursos do Azure
Remove-AzResourceGroup Exclui um grupo de recursos, incluindo todos os recursos aninhados.

Próximas etapas

Para obter mais informações sobre o Azure PowerShell, confira a Documentação do Azure PowerShell.