Skip to content

Commit b10ce96

Browse files
authored
State stores: expose TTL as a feature (#2987)
Signed-off-by: ItalyPaleAle <[email protected]>
1 parent 5d98897 commit b10ce96

File tree

24 files changed

+104
-32
lines changed

24 files changed

+104
-32
lines changed

.github/infrastructure/terraform/conformance/state/aws/dynamodb/dynamodb.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ resource "aws_dynamodb_table" "conformance_test_basic_table" {
3434
billing_mode = "PROVISIONED"
3535
read_capacity = "10"
3636
write_capacity = "10"
37+
ttl {
38+
attribute_name = "expiresAt"
39+
enabled = true
40+
}
3741
attribute {
3842
name = "key"
3943
type = "S"

internal/component/postgresql/postgresql.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ func (p *PostgreSQL) Init(ctx context.Context, metadata state.Metadata) error {
7272

7373
// Features returns the features available in this state store.
7474
func (p *PostgreSQL) Features() []state.Feature {
75-
return []state.Feature{state.FeatureETag, state.FeatureTransactional, state.FeatureQueryAPI}
75+
return []state.Feature{
76+
state.FeatureETag,
77+
state.FeatureTransactional,
78+
state.FeatureQueryAPI,
79+
state.FeatureTTL,
80+
}
7681
}
7782

7883
// Delete removes an entity from the store.

state/aws/dynamodb/dynamodb.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,19 @@ func (d *StateStore) Init(_ context.Context, metadata state.Metadata) error {
9494

9595
// Features returns the features available in this state store.
9696
func (d *StateStore) Features() []state.Feature {
97-
return []state.Feature{state.FeatureETag, state.FeatureTransactional}
97+
// TTLs are enabled only if ttlAttributeName is set
98+
if d.ttlAttributeName == "" {
99+
return []state.Feature{
100+
state.FeatureETag,
101+
state.FeatureTransactional,
102+
}
103+
}
104+
105+
return []state.Feature{
106+
state.FeatureETag,
107+
state.FeatureTransactional,
108+
state.FeatureTTL,
109+
}
98110
}
99111

100112
// Get retrieves a dynamoDB item.

state/azure/cosmosdb/cosmosdb.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ func (c *StateStore) Features() []state.Feature {
204204
state.FeatureETag,
205205
state.FeatureTransactional,
206206
state.FeatureQueryAPI,
207+
state.FeatureTTL,
207208
}
208209
}
209210

state/cassandra/cassandra.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ func (c *Cassandra) Init(_ context.Context, metadata state.Metadata) error {
117117

118118
// Features returns the features available in this state store.
119119
func (c *Cassandra) Features() []state.Feature {
120-
return nil
120+
return []state.Feature{
121+
state.FeatureTTL,
122+
}
121123
}
122124

123125
func (c *Cassandra) tryCreateKeyspace(keyspace string, replicationFactor int) error {

state/cloudflare/workerskv/workerskv.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ func (q *CFWorkersKV) GetComponentMetadata() (metadataInfo metadata.MetadataMap)
9090

9191
// Features returns the features supported by this state store.
9292
func (q CFWorkersKV) Features() []state.Feature {
93-
return []state.Feature{}
93+
return []state.Feature{
94+
state.FeatureTTL,
95+
}
9496
}
9597

9698
func (q *CFWorkersKV) Delete(parentCtx context.Context, stateReq *state.DeleteRequest) error {

state/couchbase/couchbase.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ type couchbaseMetadata struct {
6666
// NewCouchbaseStateStore returns a new couchbase state store.
6767
func NewCouchbaseStateStore(logger logger.Logger) state.Store {
6868
s := &Couchbase{
69-
json: jsoniter.ConfigFastest,
70-
features: []state.Feature{state.FeatureETag},
71-
logger: logger,
69+
json: jsoniter.ConfigFastest,
70+
features: []state.Feature{
71+
state.FeatureETag,
72+
},
73+
logger: logger,
7274
}
7375
s.BulkStore = state.NewDefaultBulkStore(s)
7476
return s

state/etcd/etcd.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,13 @@ func NewEtcdStateStoreV2(logger logger.Logger) state.Store {
6767

6868
func newETCD(logger logger.Logger, schema schemaMarshaller) state.Store {
6969
s := &Etcd{
70-
schema: schema,
71-
logger: logger,
72-
features: []state.Feature{state.FeatureETag, state.FeatureTransactional},
70+
schema: schema,
71+
logger: logger,
72+
features: []state.Feature{
73+
state.FeatureETag,
74+
state.FeatureTransactional,
75+
state.FeatureTTL,
76+
},
7377
}
7478
s.BulkStore = state.NewDefaultBulkStore(s)
7579
return s

state/feature.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ const (
2424
FeatureTransactional Feature = "TRANSACTIONAL"
2525
// FeatureQueryAPI is the feature that performs query operations.
2626
FeatureQueryAPI Feature = "QUERY_API"
27+
// FeatureTTL is the feature that supports TTLs.
28+
FeatureTTL Feature = "TTL"
2729
)
2830

29-
// Feature names a feature that can be implemented by PubSub components.
31+
// Feature names a feature that can be implemented by state store components.
3032
type Feature string
3133

3234
// IsPresent checks if a given feature is present in the list.

state/in-memory/in_memory.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ func (store *inMemoryStore) Features() []state.Feature {
9191
return []state.Feature{
9292
state.FeatureETag,
9393
state.FeatureTransactional,
94+
state.FeatureTTL,
9495
}
9596
}
9697

0 commit comments

Comments
 (0)