Skip to content

Commit cff6e66

Browse files
authored
Merge pull request #454 from ydb-platform/ttl
Moved `types.NewTimeToLiveSettings` to internal/table/session.go
2 parents b053d31 + 3037e9f commit cff6e66

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Added `NestedCall` field to retry trace start infos for alarm on nested calls
88
* Added `topicoptions.WithWriterTrace` option for attach tracer into separated writer
99
* Added `sugar.IsTableExists()` helper for check existence of table
10+
* Added `types.AlterTable` options FIXME
1011

1112
## v3.39.0
1213
* Removed message level partitioning from experimental topic API. It is unavailable on server side yet.

internal/table/client_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package table
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"math/rand"
78
"path"
@@ -1006,17 +1007,35 @@ func TestDeadlockOnInternalPoolGCTick(t *testing.T) {
10061007
_ = c.Close(ctx)
10071008
}()
10081009
s1, err := c.Get(ctx)
1010+
if err != nil && errors.Is(err, context.DeadlineExceeded) {
1011+
return
1012+
}
10091013
require.NoError(t, err)
10101014
s2, err := c.Get(ctx)
1015+
if err != nil && errors.Is(err, context.DeadlineExceeded) {
1016+
return
1017+
}
10111018
require.NoError(t, err)
10121019
s3, err := c.Get(ctx)
1020+
if err != nil && errors.Is(err, context.DeadlineExceeded) {
1021+
return
1022+
}
10131023
require.NoError(t, err)
10141024
require.Equal(t, 3, len(nodes))
10151025
err = c.Put(ctx, s1)
1026+
if err != nil && errors.Is(err, context.DeadlineExceeded) {
1027+
return
1028+
}
10161029
require.NoError(t, err)
10171030
err = c.Put(ctx, s2)
1031+
if err != nil && errors.Is(err, context.DeadlineExceeded) {
1032+
return
1033+
}
10181034
require.NoError(t, err)
10191035
err = c.Put(ctx, s3)
1036+
if err != nil && errors.Is(err, context.DeadlineExceeded) {
1037+
return
1038+
}
10201039
require.NoError(t, err)
10211040
c.internalPoolGCTick(ctx, 0)
10221041
}, xtest.StopAfter(12*time.Second))

table/example_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,13 @@ func Example_createTable() {
7171
options.WithColumn("title", types.Optional(types.TypeText)),
7272
options.WithColumn("series_info", types.Optional(types.TypeText)),
7373
options.WithColumn("release_date", types.Optional(types.TypeDate)),
74+
options.WithColumn("expire_at", types.Optional(types.TypeDate)),
7475
options.WithColumn("comment", types.Optional(types.TypeText)),
7576
options.WithPrimaryKeyColumn("series_id"),
77+
options.WithTimeToLiveSettings(options.TimeToLiveSettings{
78+
ColumnName: "expire_at",
79+
ExpireAfterSeconds: uint32(time.Hour.Seconds()),
80+
}),
7681
options.WithIndex("idx_series_title",
7782
options.WithIndexColumns("title"),
7883
options.WithIndexType(options.GlobalAsyncIndex()),
@@ -154,13 +159,17 @@ func Example_alterTable() {
154159
return s.AlterTable(ctx, path.Join(db.Name(), "series"),
155160
options.WithAddColumn("series_id", types.Optional(types.TypeUint64)),
156161
options.WithAddColumn("title", types.Optional(types.TypeText)),
157-
options.WithAlterAttribute("hello", "world"),
162+
options.WithSetTimeToLiveSettings(options.TimeToLiveSettings{
163+
ColumnName: "expire_at",
164+
ExpireAfterSeconds: uint32(time.Hour.Seconds()),
165+
}),
158166
options.WithAddIndex("idx_series_series_id",
159167
options.WithIndexColumns("series_id"),
160168
options.WithDataColumns("title"),
161169
options.WithIndexType(options.GlobalAsyncIndex()),
162170
),
163171
options.WithDropIndex("idx_series_title"),
172+
options.WithAlterAttribute("hello", "world"),
164173
options.WithAddAttribute("foo", "bar"),
165174
options.WithDropAttribute("baz"),
166175
)

table/options/options.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ func (settings timeToLiveSettings) ApplyCreateTableOption(d *CreateTableDesc, a
112112
d.TtlSettings = (*TimeToLiveSettings)(&settings).ToYDB()
113113
}
114114

115+
// WithTimeToLiveSettings defines TTL settings in CreateTable request
115116
func WithTimeToLiveSettings(settings TimeToLiveSettings) CreateTableOption {
116117
return timeToLiveSettings(settings)
117118
}
@@ -635,27 +636,31 @@ type (
635636
}
636637
)
637638

639+
// WithAddColumn adds column in AlterTable request
638640
func WithAddColumn(name string, typ types.Type) AlterTableOption {
639641
return column{
640642
name: name,
641643
typ: typ,
642644
}
643645
}
644646

647+
// WithAlterAttribute changes attribute in AlterTable request
645648
func WithAlterAttribute(key, value string) AlterTableOption {
646649
return attribute{
647650
key: key,
648651
value: value,
649652
}
650653
}
651654

655+
// WithAddAttribute adds attribute to table in AlterTable request
652656
func WithAddAttribute(key, value string) AlterTableOption {
653657
return attribute{
654658
key: key,
655659
value: value,
656660
}
657661
}
658662

663+
// WithDropAttribute drops attribute from table in AlterTable request
659664
func WithDropAttribute(key string) AlterTableOption {
660665
return attribute{
661666
key: key,
@@ -700,6 +705,7 @@ func WithAlterPartitionSettingsObject(ps PartitioningSettings) AlterTableOption
700705
return partitioningSettingsObject(ps)
701706
}
702707

708+
// WithSetTimeToLiveSettings appends TTL settings in AlterTable request
703709
func WithSetTimeToLiveSettings(settings TimeToLiveSettings) AlterTableOption {
704710
return timeToLiveSettings(settings)
705711
}
@@ -710,6 +716,7 @@ func (dropTimeToLive) ApplyAlterTableOption(d *AlterTableDesc, a *allocator.Allo
710716
d.TtlAction = &Ydb_Table.AlterTableRequest_DropTtlSettings{}
711717
}
712718

719+
// WithDropTimeToLive drops TTL settings in AlterTable request
713720
func WithDropTimeToLive() AlterTableOption {
714721
return dropTimeToLive{}
715722
}

0 commit comments

Comments
 (0)