Skip to content

Commit

Permalink
add min throughput (Azure-Samples#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
markjbrown authored Feb 7, 2020
1 parent 232b2a7 commit 92e3e50
Show file tree
Hide file tree
Showing 5 changed files with 319 additions and 117 deletions.
107 changes: 75 additions & 32 deletions cosmosdb/cassandra/throughput.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!/bin/bash

# Update throughput for Cassandra keyspace and table
# Throughput operations for a Cassandra keyspace and table

# Generate a unique 10 character alphanumeric string to ensure unique resource names
uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1)
Expand All @@ -11,62 +11,105 @@ location='westus2'
accountName="cosmos-$uniqueId" #needs to be lower case
keySpaceName='keyspace1'
tableName='table1'
originalThroughput=400
updateThroughput=500

# Create a resource group
# Create a resource group, Cosmos account, keyspace and table
az group create -n $resourceGroupName -l $location
az cosmosdb create -n $accountName -g $resourceGroupName --capabilities EnableCassandra
az cosmosdb cassandra keyspace create -a $accountName -g $resourceGroupName -n $keySpaceName --throughput $originalThroughput

# Create a new Cosmos account for Cassandra API
az cosmosdb create \
-n $accountName \
-g $resourceGroupName \
--capabilities EnableCassandra

# Create a new Cassandra Keyspace with shared throughput
az cosmosdb cassandra keyspace create \
-a $accountName \
-g $resourceGroupName \
-n $keySpaceName \
--throughput 400

# Define the schema for the Table
# Define the schema for the table and create the table
schema=$(cat << EOF
{
"columns": [
{"name": "columnA","type": "uuid"},
{"name": "columnB","type": "text"}
],
"partitionKeys": [{"name": "columnA"}]
}
EOF
)
# Persist schema to json file
}
EOF )
echo "$schema" > "schema-$uniqueId.json"
az cosmosdb cassandra table create -a $accountName -g $resourceGroupName -k $keySpaceName -n $tableName --throughput $originalThroughput --schema @schema-$uniqueId.json
rm -f "schema-$uniqueId.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

read -p 'Press any key to get current provisioned Keyspace throughput'

# Create a Cassandra table with dedicated throughput
az cosmosdb cassandra table create \
az cosmosdb cassandra keyspace throughput show \
-a $accountName \
-g $resourceGroupName \
-k $keySpaceName \
-n $tableName \
--throughput 400 \
--schema @schema-$uniqueId.json
-n $keySpaceName \
--query resource.throughput \
-o tsv

# Delete schema file
rm -f "schema-$uniqueId.json"
read -p 'Press any key to get minimum allowable Keyspace throughput'

minimumThroughput=$(az cosmosdb cassandra keyspace throughput show \
-a $accountName \
-g $resourceGroupName \
-n $keySpaceName \
--query resource.minimumThroughput \
-o tsv)

read -p 'Press any key to increase Keyspace throughput to 500'
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
updateThroughput=$minimumThroughput
fi

read -p 'Press any key to update Keyspace throughput'

az cosmosdb cassandra keyspace throughput update \
-a $accountName \
-g $resourceGroupName \
-n $keySpaceName \
--throughput 500
--throughput $updateThroughput

# 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

read -p 'Press any key to get current provisioned Table throughput'

az cosmosdb cassandra table throughput show \
-a $accountName \
-g $resourceGroupName \
-k $keySpaceName \
-n $tableName \
--query resource.throughput \
-o tsv

read -p 'Press any key to get minimum allowable Table throughput'

minimumThroughput=$(az cosmosdb cassandra table throughput show \
-a $accountName \
-g $resourceGroupName \
-k $keySpaceName \
-n $tableName \
--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

read -p 'Press any key to increase Table throughput to 500'
read -p 'Press any key to update Table throughput'

az cosmosdb cassandra table throughput update \
-a $accountName \
-g $resourceGroupName \
-k $keySpaceName \
-n $tableName \
--throughput 500
--throughput $updateThroughput
90 changes: 68 additions & 22 deletions cosmosdb/gremlin/throughput.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!/bin/bash

# Update the throughput for a Gremlin database and graph
# Throughput operations for a SQL API database and container

# Generate a unique 10 character alphanumeric string to ensure unique resource names
uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1)
Expand All @@ -11,45 +11,91 @@ location='westus2'
accountName="cosmos-$uniqueId" #needs to be lower case
databaseName='database1'
graphName='graph1'
originalThroughput=400
updateThroughput=500

# Create a resource group
# Create a resource group, Cosmos account, database with throughput and graph with throughput
az group create -n $resourceGroupName -l $location
az cosmosdb create -n $accountName -g $resourceGroupName --capabilities EnableGremlin
az cosmosdb gremlin database create -a $accountName -g $resourceGroupName -n $databaseName --throughput $originalThroughput
az cosmosdb gremlin graph create -a $accountName -g $resourceGroupName -d $databaseName -n $graphName -p '/zipcode' --throughput $originalThroughput

# Create a Cosmos account for Gremlin API
az cosmosdb create \
-n $accountName \
-g $resourceGroupName \
--capabilities EnableGremlin

# Create a Gremlin database with shared throughput
az cosmosdb gremlin database create \
# Throughput operations for Gremlin API database
# Read the current throughput
# Read the minimum throughput
# Make sure the updated throughput is not less than the minimum
# Update the throughput

read -p 'Press any key to read current provisioned throughput on database'

az cosmosdb gremlin database throughput show \
-g $resourceGroupName \
-a $accountName \
-n $databaseName \
--query resource.throughput \
-o tsv

read -p 'Press any key to read minimum throughput on database'

minimumThroughput=$(az cosmosdb gremlin database throughput show \
-g $resourceGroupName \
-a $accountName \
-n $databaseName \
--throughput 400
--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

read -p 'Press any key to update database throughput'

# Create a Gremlin graph with dedicated throughput
az cosmosdb gremlin graph create \
az cosmosdb gremlin database throughput update \
-a $accountName \
-g $resourceGroupName \
-n $databaseName \
--throughput $updateThroughput

# Throughput operations for Gremlin API graph
# Read the current throughput
# Read the minimum throughput
# Make sure the updated throughput is not less than the minimum
# Update the throughput

read -p 'Press any key to read current provisioned throughput on a graph'

az cosmosdb gremlin graph throughput show \
-g $resourceGroupName \
-a $accountName \
-d $databaseName \
-n $graphName \
-p '/zipcode' \
--throughput 400
--query resource.throughput \
-o tsv

read -p 'Press any key to increase Database throughput to 500'
read -p 'Press any key to read minimum throughput on graph'

az cosmosdb gremlin database throughput update \
-a $accountName \
minimumThroughput=$(az cosmosdb gremlin graph throughput show \
-g $resourceGroupName \
-n $databaseName \
--throughput 500
-a $accountName \
-d $databaseName \
-n $graphName \
--query resource.minimumThroughput \
-o tsv)

read -p 'Press any key to increase Graph throughput to 500'
echo $minimumThroughput

# Make sure the updated throughput is not less than the minimum allowed throughput
if [ $updateThroughput -lt $minimumThroughput ]; then
updateThroughput=$minimumThroughput
fi

az cosmosdb gremlin graph throughput update \
-a $accountName \
-g $resourceGroupName \
-a $accountName \
-d $databaseName \
-n $graphName \
--throughput 500
--throughput $updateThroughput
Loading

0 comments on commit 92e3e50

Please sign in to comment.