Skip to content

Commit 60249bc

Browse files
authored
Merge pull request #539 from ydb-platform/fix-index-type
Fix index type
2 parents 6c8b38d + 12074a2 commit 60249bc

File tree

6 files changed

+195
-46
lines changed

6 files changed

+195
-46
lines changed

CHANGELOG.md

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
* Fixed `sugar.IsTableExists` with recursive check directory exists
22
* Added `sugar.IsDirectoryExists`
3+
* Changed type of `table/options.IndexType` for type checks
4+
* Added constants `table/options.IndexTypeGlobal` and `table/options.IndexTypeGlobalAsync`
5+
* Added `table/options.IndexDescription.Type` field with `table/options.IndexType` type
36

47
## v3.42.6
58
* Implemented `driver.RowsColumnTypeDatabaseTypeName` interface in `internal/xsql.rows` struct
@@ -9,7 +12,7 @@
912
* Added checks for nil option to all opts range loops
1013
* Moved content of package `internal/ctxlabels` into `internal/xcontext`
1114
* Implemented `GRPCStatus` method in `internal/xerrors/transportError`
12-
* Added different implementations of stacktrace error for grpc errors and other
15+
* Added different implementations of stacktrace error for grpc errors and other
1316
* Dropped `internal/xnet` package as useless
1417
* Fixed default grpc dial options
1518
* Replaced single connection for discovery repeater into connection which creates each time for discovery request
@@ -28,7 +31,7 @@
2831

2932
## v3.42.3
3033
* Added `credentials.NewStaticCredentials()` static credentials constructor
31-
* Changed `internal/credentials.NewStaticCredentials()` signature and behaviour for create grpc connection on each call to auth service
34+
* Changed `internal/credentials.NewStaticCredentials()` signature and behaviour for create grpc connection on each call to auth service
3235
* Downgrade `google.golang.org/grpc` to `v1.49.0`
3336

3437
## v3.42.2
@@ -78,7 +81,7 @@
7881
* Added `types.TupleItem(types.Value)`, `types.StructFields(types.Value)` and `types.DictValues(types.Value)` funcs (extractors of internal fields of tuple, struct and dict values)
7982
* Added `types.Value.Yql()` func for getting values string representation as `YQL` literal
8083
* Added `types.Type.Yql()` func for getting `YQL` representation of type
81-
* Marked `table/types.WriteTypeStringTo` as deprecated
84+
* Marked `table/types.WriteTypeStringTo` as deprecated
8285
* Added `table/options.WithDataColumns` for supporting covering indexes
8386
* Supported `balancer` query string parameter in `DSN`
8487
* Fixed bug with scanning `YSON` value from result set
@@ -105,7 +108,7 @@
105108
* Allowed writing zero messages to topic writer
106109

107110
## v3.38.1
108-
* Fixed deadlock with implicit usage of `internal.table.Client.internalPoolAsyncCloseSession`
111+
* Fixed deadlock with implicit usage of `internal.table.Client.internalPoolAsyncCloseSession`
109112

110113
## v3.38.0
111114
* Fixed commit errors for experimental topic reader
@@ -126,10 +129,10 @@
126129
* Changed type of truncated result error from `StreamExecuteScanQuery` to retryable error
127130
* Added closing sessions if node removed from discovery results
128131
* Moved session status type from `table/options` package to `table`
129-
* Changed session status source type from `uint32` to `string` alias
132+
* Changed session status source type from `uint32` to `string` alias
130133

131134
## v3.37.6
132-
* Added to balancer notifying mechanism for listening in table client event about removing some nodes and closing sessions on them
135+
* Added to balancer notifying mechanism for listening in table client event about removing some nodes and closing sessions on them
133136
* Removed from public client interfaces `closer.Closer` (for exclude undefined behaviour on client-side)
134137

135138
## v3.37.5
@@ -139,7 +142,7 @@
139142
* Revert the marking of context errors as required to delete session
140143

141144
## v3.37.3
142-
* Fixed alter topic request - stop send empty setSupportedCodecs if customer not set them
145+
* Fixed alter topic request - stop send empty setSupportedCodecs if customer not set them
143146
* Marked the context errors as required to delete session
144147
* Added log topic api reader for internal logger
145148

@@ -185,7 +188,7 @@
185188
* Moved implementation `sugar.GenerateDeclareSection` to `internal/table`
186189
* Added transaction trace callbacks and internal logging with them
187190
* Stored context from `BeginTx` to `internal/xsql` transaction
188-
* Added automatically generated declare section to query text in `database/sql` usage
191+
* Added automatically generated declare section to query text in `database/sql` usage
189192
* Removed supports `sql.LevelSerializable`
190193
* Added `retry.Do` helper for retry custom lambda with `database/sql` without transactions
191194
* Removed `retry.WithTxOptions` option (only default isolation supports)
@@ -195,21 +198,21 @@
195198
* Added metadata to `trace.Driver.OnInvoke` and `trace.Driver.OnNewStream` done events
196199

197200
## v3.34.0
198-
* Improved the `xsql` errors mapping to `driver.ErrBadConn`
201+
* Improved the `xsql` errors mapping to `driver.ErrBadConn`
199202
* Extended `retry.DoTx` test for to achieve equivalence with `retry.Retry` behaviour
200203
* Added `database/sql` events for tracing `database/sql` driver events
201204
* Added internal logging for `database/sql` events
202205
* Supports `YDB_LOG_DETAILS` environment variable for specify scope of log messages
203206
* Removed support of `YDB_LOG_NO_COLOR` environment variable
204207
* Changed default behaviour of internal logger to without coloring
205208
* Fixed coloring (to true) with environment variable `YDB_LOG_SEVERITY_LEVEL`
206-
* Added `ydb.WithStaticCredentials(user, password)` option for make static credentials
209+
* Added `ydb.WithStaticCredentials(user, password)` option for make static credentials
207210
* Supports static credentials as part of connection string (dsn - data source name)
208211
* Changed minimal supported version of go from 1.14 to 1.16 (required for jwt library)
209212

210213

211214
## v3.33.0
212-
* Added `retry.DoTx` helper for retrying `database/sql` transactions
215+
* Added `retry.DoTx` helper for retrying `database/sql` transactions
213216
* Implemented `database/sql` driver over `ydb-go-sdk`
214217
* Marked as deprecated `trace.Table.OnPoolSessionNew` and `trace.Table.OnPoolSessionClose` events
215218
* Added `trace.Table.OnPoolSessionAdd` and `trace.Table.OnPoolSessionRemove` events
@@ -223,7 +226,7 @@
223226

224227
## v3.32.0
225228
* Refactored `trace.Topic` (experimental) handlers
226-
* Fixed signature and names of helpers in `topic/topicsugar` package
229+
* Fixed signature and names of helpers in `topic/topicsugar` package
227230
* Allowed parallel reading and committing topic messages
228231

229232
## v3.31.0
@@ -244,10 +247,10 @@
244247
* Added touching of last updated timestamp in existing conns on stage of applying new endpoint list
245248

246249
## v3.29.3
247-
* Reverted `xerrors.IsTransportError(err)` behaviour for raw grpc errors to false
250+
* Reverted `xerrors.IsTransportError(err)` behaviour for raw grpc errors to false
248251

249252
## v3.29.2
250-
* Enabled server-side session balancing for sessions created from internal session pool
253+
* Enabled server-side session balancing for sessions created from internal session pool
251254
* Removed unused public `meta.Meta` methods
252255
* Renamed `meta.Meta.Meta(ctx)` public method to `meta.Meta.Context(ctx)`
253256
* Reverted default balancer to `balancers.RandomChoice()`
@@ -267,12 +270,12 @@
267270

268271
## v3.28.1
269272
* Marked dial errors as retryable
270-
* Supported node pessimization on dialing errors
273+
* Supported node pessimization on dialing errors
271274
* Marked error from `Invoke` and `NewStream` as retryable if request not sended to server
272275

273276
## v3.28.0
274277
* Added `sugar.GenerateDeclareSection()` helper for make declare section in `YQL`
275-
* Added check when parameter name not started from `$` and automatically prepends it to name
278+
* Added check when parameter name not started from `$` and automatically prepends it to name
276279
* Refactored connection closing
277280

278281
## v3.27.0

internal/table/session.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ func (s *session) CreateTable(
294294
}
295295
}
296296
_, err = s.tableService.CreateTable(ctx, &request)
297-
return xerrors.WithStackTrace(err)
297+
if err != nil {
298+
return xerrors.WithStackTrace(err)
299+
}
300+
return nil
298301
}
299302

300303
// DescribeTable describes table at given path.
@@ -410,11 +413,19 @@ func (s *session) DescribeTable(
410413

411414
indexes := make([]options.IndexDescription, len(result.Indexes))
412415
for i, idx := range result.GetIndexes() {
416+
var typ options.IndexType
417+
switch idx.Type.(type) {
418+
case *Ydb_Table.TableIndexDescription_GlobalAsyncIndex:
419+
typ = options.IndexTypeGlobalAsync
420+
case *Ydb_Table.TableIndexDescription_GlobalIndex:
421+
typ = options.IndexTypeGlobal
422+
}
413423
indexes[i] = options.IndexDescription{
414424
Name: idx.GetName(),
415425
IndexColumns: idx.GetIndexColumns(),
416426
DataColumns: idx.GetDataColumns(),
417427
Status: idx.GetStatus(),
428+
Type: typ,
418429
}
419430
}
420431

table/example_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func Example_alterTable() {
166166
options.WithAddIndex("idx_series_series_id",
167167
options.WithIndexColumns("series_id"),
168168
options.WithDataColumns("title"),
169-
options.WithIndexType(options.GlobalAsyncIndex()),
169+
options.WithIndexType(options.GlobalIndex()),
170170
),
171171
options.WithDropIndex("idx_series_title"),
172172
options.WithAlterAttribute("hello", "world"),

table/options/models.go

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type IndexDescription struct {
4040
IndexColumns []string
4141
DataColumns []string
4242
Status Ydb_Table.TableIndexDescription_Status
43+
Type IndexType
4344
}
4445

4546
//nolint:unused
@@ -270,32 +271,34 @@ func NewPartitioningSettings(ps *Ydb_Table.PartitioningSettings) PartitioningSet
270271
}
271272
}
272273

273-
type IndexType interface {
274-
setup(*indexDesc)
275-
}
276-
277-
type globalIndex struct{}
274+
type (
275+
IndexType uint8
276+
)
278277

279-
func GlobalIndex() IndexType {
280-
return globalIndex{}
281-
}
278+
const (
279+
IndexTypeGlobal = IndexType(iota)
280+
IndexTypeGlobalAsync
281+
)
282282

283-
func (globalIndex) setup(d *indexDesc) {
284-
d.Type = &Ydb_Table.TableIndex_GlobalIndex{
285-
GlobalIndex: new(Ydb_Table.GlobalIndex),
283+
func (t IndexType) ApplyIndexOption(d *indexDesc) {
284+
switch t {
285+
case IndexTypeGlobal:
286+
d.Type = &Ydb_Table.TableIndex_GlobalIndex{
287+
GlobalIndex: &Ydb_Table.GlobalIndex{},
288+
}
289+
case IndexTypeGlobalAsync:
290+
d.Type = &Ydb_Table.TableIndex_GlobalAsyncIndex{
291+
GlobalAsyncIndex: &Ydb_Table.GlobalAsyncIndex{},
292+
}
286293
}
287294
}
288295

289-
type globalAsyncIndex struct{}
290-
291-
func GlobalAsyncIndex() IndexType {
292-
return globalAsyncIndex{}
296+
func GlobalIndex() IndexType {
297+
return IndexTypeGlobal
293298
}
294299

295-
func (globalAsyncIndex) setup(d *indexDesc) {
296-
d.Type = &Ydb_Table.TableIndex_GlobalAsyncIndex{
297-
GlobalAsyncIndex: new(Ydb_Table.GlobalAsyncIndex),
298-
}
300+
func GlobalAsyncIndex() IndexType {
301+
return IndexTypeGlobalAsync
299302
}
300303

301304
type PartitioningMode byte

table/options/options.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -219,16 +219,8 @@ func WithDataColumns(columns ...string) IndexOption {
219219
return dataColumns(columns)
220220
}
221221

222-
type indexType struct {
223-
t IndexType
224-
}
225-
226-
func (i indexType) ApplyIndexOption(d *indexDesc) {
227-
i.t.setup(d)
228-
}
229-
230222
func WithIndexType(t IndexType) IndexOption {
231-
return indexType{t: t}
223+
return t
232224
}
233225

234226
type columnFamilies []ColumnFamily

0 commit comments

Comments
 (0)