Skip to content

Commit 417edc4

Browse files
committed
Tweaks from manual testing:
- fast start the table manage ticker - minimum write throughput is 1, not 0 - simplify the calculateExpectedTables functions, using int64 seconds (instead of time.Time) everywhere
1 parent 9f5d43a commit 417edc4

File tree

2 files changed

+52
-32
lines changed

2 files changed

+52
-32
lines changed

chunk/dynamo_table_manager.go

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919
)
2020

2121
const (
22-
readLabel = "read"
23-
writeLabel = "write"
22+
readLabel = "read"
23+
writeLabel = "write"
24+
minWriteCapacity = 1
2425
)
2526

2627
var (
@@ -119,6 +120,12 @@ func (m *DynamoTableManager) loop() {
119120
ticker := time.NewTicker(m.cfg.DynamoDBPollInterval)
120121
defer ticker.Stop()
121122

123+
if err := instrument.TimeRequestHistogram(context.Background(), "DynamoTableManager.syncTables", syncTableDuration, func(ctx context.Context) error {
124+
return m.syncTables(ctx)
125+
}); err != nil {
126+
log.Errorf("Error syncing tables: %v", err)
127+
}
128+
122129
for {
123130
select {
124131
case <-ticker.C:
@@ -161,43 +168,55 @@ func (a byName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
161168
func (a byName) Less(i, j int) bool { return a[i].name < a[j].name }
162169

163170
func (m *DynamoTableManager) calculateExpectedTables(_ context.Context) []tableDescription {
171+
if !m.cfg.UsePeriodicTables {
172+
return []tableDescription{
173+
{
174+
name: m.tableName,
175+
provisionedRead: m.cfg.ProvisionedReadThroughput,
176+
provisionedWrite: m.cfg.ProvisionedWriteThroughput,
177+
},
178+
}
179+
}
180+
164181
result := []tableDescription{}
165182

183+
var (
184+
tablePeriodSecs = int64(m.cfg.TablePeriod / time.Second)
185+
gracePeriodSecs = int64(m.cfg.CreationGracePeriod / time.Second)
186+
maxChunkAgeSecs = int64(m.cfg.MaxChunkAge / time.Second)
187+
firstTable = m.cfg.PeriodicTableStartAt.Unix() / tablePeriodSecs
188+
lastTable = (mtime.Now().Unix() + gracePeriodSecs) / tablePeriodSecs
189+
now = mtime.Now().Unix()
190+
)
191+
166192
// Add the legacy table
167193
{
168194
legacyTable := tableDescription{
169-
name: m.tableName,
170-
provisionedRead: m.cfg.ProvisionedReadThroughput,
195+
name: m.tableName,
196+
provisionedRead: m.cfg.ProvisionedReadThroughput,
197+
provisionedWrite: minWriteCapacity,
171198
}
172199

173200
// if we are before the switch to periodic table, we need to give this table write throughput
174-
if !m.cfg.UsePeriodicTables || mtime.Now().Before(m.cfg.PeriodicTableStartAt.Add(m.cfg.CreationGracePeriod).Add(m.cfg.MaxChunkAge)) {
201+
if now < (firstTable*tablePeriodSecs)+gracePeriodSecs+maxChunkAgeSecs {
175202
legacyTable.provisionedWrite = m.cfg.ProvisionedWriteThroughput
176203
}
177204
result = append(result, legacyTable)
178205
}
179206

180-
if m.cfg.UsePeriodicTables {
181-
tablePeriodSecs := int64(m.cfg.TablePeriod / time.Second)
182-
gracePeriodSecs := int64(m.cfg.CreationGracePeriod / time.Second)
183-
maxChunkAgeSecs := int64(m.cfg.MaxChunkAge / time.Second)
184-
firstTable := m.cfg.PeriodicTableStartAt.Unix() / tablePeriodSecs
185-
lastTable := (mtime.Now().Unix() + gracePeriodSecs) / tablePeriodSecs
186-
187-
for i := firstTable; i <= lastTable; i++ {
188-
table := tableDescription{
189-
// Name construction needs to be consistent with chunk_store.bigBuckets
190-
name: m.cfg.TablePrefix + strconv.Itoa(int(i)),
191-
provisionedRead: m.cfg.ProvisionedReadThroughput,
192-
}
207+
for i := firstTable; i <= lastTable; i++ {
208+
table := tableDescription{
209+
// Name construction needs to be consistent with chunk_store.bigBuckets
210+
name: m.cfg.TablePrefix + strconv.Itoa(int(i)),
211+
provisionedRead: m.cfg.ProvisionedReadThroughput,
212+
provisionedWrite: minWriteCapacity,
213+
}
193214

194-
// if now is within table [start - grace, end + grace), then we need some write throughput
195-
now := mtime.Now().Unix()
196-
if (i*tablePeriodSecs)-gracePeriodSecs <= now && now < (i*tablePeriodSecs)+tablePeriodSecs+gracePeriodSecs+maxChunkAgeSecs {
197-
table.provisionedWrite = m.cfg.ProvisionedWriteThroughput
198-
}
199-
result = append(result, table)
215+
// if now is within table [start - grace, end + grace), then we need some write throughput
216+
if (i*tablePeriodSecs)-gracePeriodSecs <= now && now < (i*tablePeriodSecs)+tablePeriodSecs+gracePeriodSecs+maxChunkAgeSecs {
217+
table.provisionedWrite = m.cfg.ProvisionedWriteThroughput
200218
}
219+
result = append(result, table)
201220
}
202221

203222
sort.Sort(byName(result))
@@ -306,10 +325,11 @@ func (m *DynamoTableManager) updateTables(ctx context.Context, descriptions []ta
306325
tableCapacity.WithLabelValues(writeLabel, desc.name).Set(float64(*out.Table.ProvisionedThroughput.WriteCapacityUnits))
307326

308327
if *out.Table.ProvisionedThroughput.ReadCapacityUnits == desc.provisionedRead && *out.Table.ProvisionedThroughput.WriteCapacityUnits == desc.provisionedWrite {
328+
log.Infof(" Provisioned throughput: read = %d, write = %d, skipping.", *out.Table.ProvisionedThroughput.ReadCapacityUnits, *out.Table.ProvisionedThroughput.WriteCapacityUnits)
309329
continue
310330
}
311331

312-
log.Infof("Updating provisioned throughput on table %s", desc.name)
332+
log.Infof(" Updating provisioned throughput on table %s to read = %d, write = %d", desc.name, desc.provisionedRead, desc.provisionedWrite)
313333
if err := instrument.TimeRequestHistogram(ctx, "DynamoDB.DescribeTable", dynamoRequestDuration, func(_ context.Context) error {
314334
_, err := m.dynamodb.UpdateTable(&dynamodb.UpdateTableInput{
315335
TableName: aws.String(desc.name),

chunk/dynamo_table_manager_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func TestDynamoTableManager(t *testing.T) {
8585
"Move forward by max chunk age + grace period",
8686
time.Unix(0, 0).Add(maxChunkAge).Add(gracePeriod),
8787
[]tableDescription{
88-
{name: "", provisionedRead: read, provisionedWrite: 0},
88+
{name: "", provisionedRead: read, provisionedWrite: minWriteCapacity},
8989
{name: tablePrefix + "0", provisionedRead: read, provisionedWrite: write},
9090
},
9191
)
@@ -95,7 +95,7 @@ func TestDynamoTableManager(t *testing.T) {
9595
"Move forward by table period - grace period",
9696
time.Unix(0, 0).Add(tablePeriod).Add(-gracePeriod),
9797
[]tableDescription{
98-
{name: "", provisionedRead: read, provisionedWrite: 0},
98+
{name: "", provisionedRead: read, provisionedWrite: minWriteCapacity},
9999
{name: tablePrefix + "0", provisionedRead: read, provisionedWrite: write},
100100
{name: tablePrefix + "1", provisionedRead: read, provisionedWrite: write},
101101
},
@@ -106,7 +106,7 @@ func TestDynamoTableManager(t *testing.T) {
106106
"Move forward by table period + grace period",
107107
time.Unix(0, 0).Add(tablePeriod).Add(gracePeriod),
108108
[]tableDescription{
109-
{name: "", provisionedRead: read, provisionedWrite: 0},
109+
{name: "", provisionedRead: read, provisionedWrite: minWriteCapacity},
110110
{name: tablePrefix + "0", provisionedRead: read, provisionedWrite: write},
111111
{name: tablePrefix + "1", provisionedRead: read, provisionedWrite: write},
112112
},
@@ -117,8 +117,8 @@ func TestDynamoTableManager(t *testing.T) {
117117
"Move forward by table period + max chunk age + grace period",
118118
time.Unix(0, 0).Add(tablePeriod).Add(maxChunkAge).Add(gracePeriod),
119119
[]tableDescription{
120-
{name: "", provisionedRead: read, provisionedWrite: 0},
121-
{name: tablePrefix + "0", provisionedRead: read, provisionedWrite: 0},
120+
{name: "", provisionedRead: read, provisionedWrite: minWriteCapacity},
121+
{name: tablePrefix + "0", provisionedRead: read, provisionedWrite: minWriteCapacity},
122122
{name: tablePrefix + "1", provisionedRead: read, provisionedWrite: write},
123123
},
124124
)
@@ -128,8 +128,8 @@ func TestDynamoTableManager(t *testing.T) {
128128
"Nothing changed",
129129
time.Unix(0, 0).Add(tablePeriod).Add(maxChunkAge).Add(gracePeriod),
130130
[]tableDescription{
131-
{name: "", provisionedRead: read, provisionedWrite: 0},
132-
{name: tablePrefix + "0", provisionedRead: read, provisionedWrite: 0},
131+
{name: "", provisionedRead: read, provisionedWrite: minWriteCapacity},
132+
{name: tablePrefix + "0", provisionedRead: read, provisionedWrite: minWriteCapacity},
133133
{name: tablePrefix + "1", provisionedRead: read, provisionedWrite: write},
134134
},
135135
)

0 commit comments

Comments
 (0)