Esempio n. 1
0
        public static async void GetTablesDetails()
        {
            List <string> tables = await GetTablesList();

            using (IAmazonDynamoDB client = GetDynamoDbClient())
            {
                foreach (string table in tables)
                {
                    DescribeTableRequest  describeTableRequest  = new DescribeTableRequest(table);
                    DescribeTableResponse describeTableResponse = await client.DescribeTableAsync(describeTableRequest);

                    TableDescription tableDescription = describeTableResponse.Table;
                    Debug.WriteLine(string.Format("Printing information about table {0}:", tableDescription.TableName));
                    Debug.WriteLine(string.Format("Created at: {0}", tableDescription.CreationDateTime));
                    List <KeySchemaElement> keySchemaElements = tableDescription.KeySchema;
                    foreach (KeySchemaElement schema in keySchemaElements)
                    {
                        Debug.WriteLine(string.Format("Key name: {0}, key type: {1}", schema.AttributeName, schema.KeyType));
                    }
                    Debug.WriteLine(string.Format("Item count: {0}", tableDescription.ItemCount));
                    ProvisionedThroughputDescription throughput = tableDescription.ProvisionedThroughput;
                    Debug.WriteLine(string.Format("Read capacity: {0}", throughput.ReadCapacityUnits));
                    Debug.WriteLine(string.Format("Write capacity: {0}", throughput.WriteCapacityUnits));
                    List <AttributeDefinition> tableAttributes = tableDescription.AttributeDefinitions;
                    foreach (AttributeDefinition attDefinition in tableAttributes)
                    {
                        Debug.WriteLine(string.Format("Table attribute name: {0}", attDefinition.AttributeName));
                        Debug.WriteLine(string.Format("Table attribute type: {0}", attDefinition.AttributeType));
                    }
                    Debug.WriteLine(string.Format("Table size: {0}b", tableDescription.TableSizeBytes));
                    Debug.WriteLine(string.Format("Table status: {0}", tableDescription.TableStatus));
                    Debug.WriteLine("====================================================");
                }
            }
        }
Esempio n. 2
0
 public GlobalSecondaryIndexDescription(string indexArn, string indexName, long indexSizeBytes, long itemCount,
                                        IReadOnlyList <KeySchemaElement> keySchema, Projection projection, bool backfilling, IndexStatus indexStatus,
                                        ProvisionedThroughputDescription provisionedThroughput) : base(indexArn, indexName, indexSizeBytes, itemCount, keySchema, projection)
 {
     Backfilling           = backfilling;
     IndexStatus           = indexStatus;
     ProvisionedThroughput = provisionedThroughput;
 }
 public ModifiedThroughput(string table_name, string index_name, ProvisionedThroughputDescription current_provisioned_throughput)
 {
     this.table_name = table_name;
     this.index_name = index_name;
     this.current_provisioned_throughput  = current_provisioned_throughput;
     this.new_provisioned_throughput      = null;
     this.throughput_modification_results = new List <ThroughputModificationResult>();
 }
Esempio n. 4
0
        protected override bool IsBlockedOut(ProvisionedThroughputDescription current_provisioned_throughput)
        {
            bool is_blocked_out = false;

            DateTime utc_now = DateTime.UtcNow;

            is_blocked_out = this.blockout_time_frames.Any(blockout_time_frame => utc_now >= blockout_time_frame.Item1 && utc_now < blockout_time_frame.Item2);

            return(is_blocked_out);
        }
Esempio n. 5
0
        public IncreaseDecreaseResult GetNewDecreaseCombinationModifierCapacityUnits(ProvisionedThroughputDescription current_provisioned_throughput)
        {
            IncreaseDecreaseResult decrease_combination_modifier_result = null;

            if (decrease != null && (decrease_combination_modifier.measurement_units > 0 || decrease_combination_modifier.measurement_percentage > 0))
            {
                Decrease combination_decrease = new Decrease(decrease, decrease_combination_modifier);
                decrease_combination_modifier_result = combination_decrease.ApplyRule(consumed_capacity_units, current_capacity_units, current_provisioned_throughput);
            }

            return(decrease_combination_modifier_result);
        }
        public ThroughputModificationResult ApplyRule(string table_name, string index_name, long?new_read_capacity_units, long?new_write_capacity_units, ProvisionedThroughputDescription current_provisioned_throughput)
        {
            ThroughputModificationResult throughput_modification_result = new ThroughputModificationResult(index_id);

            long current_read_capacity_units  = current_provisioned_throughput.ReadCapacityUnits;
            long current_write_capacity_units = current_provisioned_throughput.WriteCapacityUnits;

            // if no new read capacity units has been determined and the current rule is set up with a read section, try to apply read rule
            if (!new_read_capacity_units.HasValue && read != null)
            {
                throughput_modification_result.read_result = read.ApplyRule(table_name, index_name, look_back_minutes, current_provisioned_throughput);
                new_read_capacity_units = throughput_modification_result.read_result.new_capacity_units;
            }

            // if no new write capacity units has been determined and the current rule is set up with a write section, try to apply write rule
            if (!new_write_capacity_units.HasValue && write != null)
            {
                throughput_modification_result.write_result = write.ApplyRule(table_name, index_name, look_back_minutes, current_provisioned_throughput);
                new_write_capacity_units = throughput_modification_result.write_result.new_capacity_units;
            }

            // look for decrease combination modifier eligibility
            if (
                (new_write_capacity_units.HasValue && new_write_capacity_units.Value < current_write_capacity_units && !new_read_capacity_units.HasValue && read != null) ||
                (new_read_capacity_units.HasValue && new_read_capacity_units.Value < current_read_capacity_units && !new_write_capacity_units.HasValue && write != null)
                )
            {
                if (new_write_capacity_units.HasValue && new_write_capacity_units.Value < current_write_capacity_units && !new_read_capacity_units.HasValue && read != null)
                {
                    throughput_modification_result.read_result.decrease_combination_modifier_result = read.GetNewDecreaseCombinationModifierCapacityUnits(current_provisioned_throughput);
                    if (throughput_modification_result.read_result.decrease_combination_modifier_result != null)
                    {
                        new_read_capacity_units = throughput_modification_result.read_result.decrease_combination_modifier_result.new_capacity_units;
                        throughput_modification_result.read_result.new_capacity_units = new_read_capacity_units;
                    }
                }
                else                 // if (new_read_capacity_units.HasValue && new_read_capacity_units.Value < current_read_capacity_units && !new_write_capacity_units.HasValue && write != null)
                {
                    throughput_modification_result.write_result.decrease_combination_modifier_result = write.GetNewDecreaseCombinationModifierCapacityUnits(current_provisioned_throughput);
                    if (throughput_modification_result.write_result.decrease_combination_modifier_result != null)
                    {
                        new_write_capacity_units = throughput_modification_result.write_result.decrease_combination_modifier_result.new_capacity_units;
                        throughput_modification_result.write_result.new_capacity_units = new_write_capacity_units;
                    }
                }
            }

            // apply minimum/maximum throughput configured in the rule
            if (throughput_modification_result.read_result != null)
            {
                throughput_modification_result.read_result.ApplyAdjustmentConstraints(read.minimum_throughput, read.maximum_throughput);
            }
            if (throughput_modification_result.write_result != null)
            {
                throughput_modification_result.write_result.ApplyAdjustmentConstraints(write.minimum_throughput, write.maximum_throughput);
            }

            return(throughput_modification_result);
        }
Esempio n. 7
0
        protected override bool IsBlockedOut(ProvisionedThroughputDescription current_provisioned_throughput)
        {
            bool     is_blocked_out = false;
            DateTime utc_now        = DateTime.UtcNow;

            is_blocked_out = current_provisioned_throughput.NumberOfDecreasesToday == max_number_of_decreases;
            if (!is_blocked_out)
            {
                is_blocked_out = this.blockout_time_frames.Any(blockout_time_frame => utc_now >= blockout_time_frame.Item1 && utc_now < blockout_time_frame.Item2);
            }
            if (!is_blocked_out)
            {
                DateTime utc_today = utc_now.Date;
                DateTime last_decrease_date_time = current_provisioned_throughput.LastDecreaseDateTime;
                if (last_decrease_date_time < utc_today)
                {
                    last_decrease_date_time = utc_today;
                }

                if (decrease_frequency == DecreaseFrequencies.EvenSpread)
                {
                    DateTime utc_tomorrow            = utc_today.AddDays(1);
                    double   total_remaining_minutes = (utc_tomorrow - last_decrease_date_time).TotalMinutes;
                    List <Tuple <DateTime, DateTime> > remaining_blockout_time_frames = this.blockout_time_frames.Where(blockout_time_frame => last_decrease_date_time < blockout_time_frame.Item2).ToList();
                    double total_blocked_out_minutes = remaining_blockout_time_frames.Sum(remaining_blockout_time_frame =>
                    {
                        if (last_decrease_date_time >= remaining_blockout_time_frame.Item1)
                        {
                            return((remaining_blockout_time_frame.Item2 - last_decrease_date_time).TotalMinutes);
                        }
                        else                         // if (last_decrease_date_time < blockout_time_frame.Item1)
                        {
                            return((remaining_blockout_time_frame.Item2 - remaining_blockout_time_frame.Item1).TotalMinutes);
                        }
                    });
                    double remaining_minutes = total_remaining_minutes - total_blocked_out_minutes;
                    double next_eligible_run_time_minutes = remaining_minutes / ((max_number_of_decreases - current_provisioned_throughput.NumberOfDecreasesToday) + 1);

                    DateTime next_eligible_run_time = last_decrease_date_time;
                    for (int index = 0; index < remaining_blockout_time_frames.Count && next_eligible_run_time_minutes > 0; index++)
                    {
                        Tuple <DateTime, DateTime> remaining_blockout_time_frame = remaining_blockout_time_frames.ElementAt(index);
                        DateTime current_start = remaining_blockout_time_frame.Item1;
                        DateTime current_end   = remaining_blockout_time_frame.Item2;

                        if (next_eligible_run_time >= current_start)                         // if last decrease date is within a blockout timeframe, then move it to the end of blockout timeframe in question
                        {
                            next_eligible_run_time = current_end;
                        }
                        else                         // if (next_eligible_run_time < current_start)
                        {
                            // calculates the minutes available until the next blockout timeframe
                            double minutes_until_blockout_time_frame = (current_start - next_eligible_run_time).TotalMinutes;

                            if (next_eligible_run_time_minutes < minutes_until_blockout_time_frame)                             // if next blockout timeframe is later than minutes until next eligible run time
                            {
                                next_eligible_run_time         = next_eligible_run_time.AddMinutes(next_eligible_run_time_minutes);
                                next_eligible_run_time_minutes = 0;
                            }
                            else if (next_eligible_run_time_minutes > minutes_until_blockout_time_frame)
                            {
                                next_eligible_run_time          = current_end;
                                next_eligible_run_time_minutes -= minutes_until_blockout_time_frame;
                            }
                            else                             // if (next_eligible_run_time_minutes == minutes_until_blockout_time_frame)
                            {
                                next_eligible_run_time         = current_end;
                                next_eligible_run_time_minutes = 0;
                            }
                        }
                    }
                    if (next_eligible_run_time_minutes > 0)
                    {
                        next_eligible_run_time = next_eligible_run_time.AddMinutes(next_eligible_run_time_minutes);
                    }

                    is_blocked_out = utc_now < next_eligible_run_time;
                }
                else if (decrease_frequency == DecreaseFrequencies.Custom)
                {
                    DateTime next_eligible_run_time = last_decrease_date_time.AddMinutes(decrease_frequency_custom_minutes);
                    is_blocked_out = utc_now < next_eligible_run_time;
                }
                //else if (decrease_frequency == DecreaseFrequencies.Immediate)
                //	skipped
            }

            return(is_blocked_out);
        }
Esempio n. 8
0
        public ReadWriteResult ApplyRule(string table_name, string index_name, int look_back_minutes, ProvisionedThroughputDescription current_provisioned_throughput)
        {
            ReadWriteResult read_write_result = new ReadWriteResult();

            consumed_capacity_units = GetConsumedCapacityUnits(table_name, index_name, look_back_minutes);
            current_capacity_units  = GetCurrentCapacityUnits(current_provisioned_throughput);

            read_write_result.consumed_capacity_units = consumed_capacity_units;
            read_write_result.look_back_minutes       = look_back_minutes;

            // when provided poorly set up rules, favor increase over decrease for safety
            if (increase != null)
            {
                read_write_result.increase_result    = this.increase.ApplyRule(consumed_capacity_units, current_capacity_units, current_provisioned_throughput);
                read_write_result.new_capacity_units = read_write_result.increase_result.new_capacity_units;
            }
            if (!read_write_result.new_capacity_units.HasValue && decrease != null)
            {
                read_write_result.decrease_result    = this.decrease.ApplyRule(consumed_capacity_units, current_capacity_units, current_provisioned_throughput);
                read_write_result.new_capacity_units = read_write_result.decrease_result.new_capacity_units;
            }

            return(read_write_result);
        }
Esempio n. 9
0
 abstract protected long GetCurrentCapacityUnits(ProvisionedThroughputDescription current_provisioned_throughput);
Esempio n. 10
0
 protected override long GetCurrentCapacityUnits(ProvisionedThroughputDescription current_provisioned_throughput)
 {
     return(current_provisioned_throughput.WriteCapacityUnits);
 }
 abstract protected bool IsBlockedOut(ProvisionedThroughputDescription current_provisioned_throughput);
        public IncreaseDecreaseResult ApplyRule(long consumed_capacity_units, long current_capacity_units, ProvisionedThroughputDescription current_provisioned_throughput)
        {
            bool threshold_met      = false;
            bool blocked_out        = false;
            long?new_capacity_units = null;

            threshold_met = ThresholdMet(consumed_capacity_units, current_capacity_units);
            if (threshold_met)
            {
                blocked_out = IsBlockedOut(current_provisioned_throughput);
                if (!blocked_out)
                {
                    new_capacity_units = GetNewCapacityUnits(current_capacity_units);
                }
            }

            IncreaseDecreaseResult increase_decrease_result = new IncreaseDecreaseResult(threshold, amount, threshold_met, blocked_out, new_capacity_units);

            return(increase_decrease_result);
        }
Esempio n. 13
0
        private static ModifiedThroughput BuildModifiedThroughput(string table_name, string index_name, ProvisionedThroughputDescription current_provisioned_throughput, List <ThroughputModification> throughput_modifications)
        {
            ModifiedThroughput modified_throughput = new ModifiedThroughput(table_name, index_name, current_provisioned_throughput);
            long?new_read_capacity_units           = null;
            long?new_write_capacity_units          = null;

            for (int index = 0;
                 index < throughput_modifications.Count && (!new_read_capacity_units.HasValue || !new_write_capacity_units.HasValue);
                 index++)
            {
                ThroughputModification       throughput_modification        = throughput_modifications.ElementAt(index);
                ThroughputModificationResult throughput_modification_result = throughput_modification.ApplyRule(table_name, index_name, new_read_capacity_units, new_write_capacity_units, current_provisioned_throughput);
                modified_throughput.throughput_modification_results.Add(throughput_modification_result);

                if (throughput_modification_result.read_result != null)
                {
                    new_read_capacity_units = throughput_modification_result.read_result.new_capacity_units;
                }
                if (throughput_modification_result.write_result != null)
                {
                    new_write_capacity_units = throughput_modification_result.write_result.new_capacity_units;
                }
            }

            new_read_capacity_units  = new_read_capacity_units ?? current_provisioned_throughput.ReadCapacityUnits;
            new_write_capacity_units = new_write_capacity_units ?? current_provisioned_throughput.WriteCapacityUnits;
            if (new_read_capacity_units != current_provisioned_throughput.ReadCapacityUnits || new_write_capacity_units != current_provisioned_throughput.WriteCapacityUnits)
            {
                modified_throughput.new_provisioned_throughput = new ProvisionedThroughput
                {
                    ReadCapacityUnits  = new_read_capacity_units.Value,
                    WriteCapacityUnits = new_write_capacity_units.Value
                };
            }

            return(modified_throughput);
        }