• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 0189088e-cb42-44e0-b004-8c969087ff5b

29 Jun 2023 07:08PM UTC coverage: 57.262% (-0.005%) from 57.267%
0189088e-cb42-44e0-b004-8c969087ff5b

push

buildkite

web-flow
Create TTL in the UpdateWorkflowExecution cycles. (#5243)

* Adding TTL to the executions during the updateworkflow step

* Determining TTL duration

* Adding Dynamic Config to TTL

* Added DC and updated tests

* Added the Dynamic config to persistence tests

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Added updateworkflowTTL unit test

* Updated the tests with TODO and new checks

* Updated the tests with TODO and new checks

* Updated the tests with a new check

* Resolved nit comments

* Added TODO for flow change

* Moved the TTL from Update cycles to the workflow mutation:
- made minor changes in the calculation.
- removed the TODOs.
- Made the TTL calculation function reusable.

* Cleaned up the code and fixed minor bugs

* Resolved comments and updated unit test

* Resolved the code comments

* Added comment explaining the cron starttime

* Added new unit test for TTL

* Added new unit test for TTL

* Added new unit test for TTL

* Updated updateworkflow params

* New create and update info

* Add TTL info

* Add TTL check for get workflow

* fixing the primary key bug

* Added an insert to enable TTL for the primary keys

* Added close status check to state check

140 of 140 new or added lines in 7 files covered. (100.0%)

87148 of 152191 relevant lines covered (57.26%)

2510.23 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/common/persistence/sql/sqlplugin/mysql/db.go
1
// Copyright (c) 2017 Uber Technologies, Inc.
2
//
3
// Permission is hereby granted, free of charge, to any person obtaining a copy
4
// of this software and associated documentation files (the "Software"), to deal
5
// in the Software without restriction, including without limitation the rights
6
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
// copies of the Software, and to permit persons to whom the Software is
8
// furnished to do so, subject to the following conditions:
9
//
10
// The above copyright notice and this permission notice shall be included in
11
// all copies or substantial portions of the Software.
12
//
13
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
// THE SOFTWARE.
20

21
package mysql
22

23
import (
24
        "context"
25
        "database/sql"
26
        "time"
27

28
        "github.com/VividCortex/mysqlerr"
29
        "github.com/go-sql-driver/mysql"
30
        "github.com/jmoiron/sqlx"
31

32
        "github.com/uber/cadence/common/persistence/sql/sqldriver"
33
        "github.com/uber/cadence/common/persistence/sql/sqlplugin"
34
)
35

36
type (
37
        db struct {
38
                converter   DataConverter
39
                driver      sqldriver.Driver
40
                originalDBs []*sqlx.DB
41
                numDBShards int
42
        }
43
)
44

45
func (mdb *db) GetTotalNumDBShards() int {
31,223✔
46
        return mdb.numDBShards
31,223✔
47
}
31,223✔
48

49
var _ sqlplugin.AdminDB = (*db)(nil)
50
var _ sqlplugin.DB = (*db)(nil)
51
var _ sqlplugin.Tx = (*db)(nil)
52

53
func (mdb *db) IsDupEntryError(err error) bool {
10✔
54
        sqlErr, ok := err.(*mysql.MySQLError)
10✔
55
        // ErrDupEntry MySQL Error 1062 indicates a duplicate primary key i.e. the row already exists,
10✔
56
        // so we don't do the insert and return a ConditionalUpdate error.
10✔
57
        return ok && sqlErr.Number == mysqlerr.ER_DUP_ENTRY
10✔
58
}
10✔
59

60
func (mdb *db) IsNotFoundError(err error) bool {
855✔
61
        return err == sql.ErrNoRows
855✔
62
}
855✔
63

64
func (mdb *db) IsTimeoutError(err error) bool {
811✔
65
        if err == context.DeadlineExceeded {
811✔
66
                return true
×
67
        }
×
68
        sqlErr, ok := err.(*mysql.MySQLError)
811✔
69
        if ok {
853✔
70
                if sqlErr.Number == mysqlerr.ER_NET_READ_INTERRUPTED ||
42✔
71
                        sqlErr.Number == mysqlerr.ER_NET_WRITE_INTERRUPTED ||
42✔
72
                        sqlErr.Number == mysqlerr.ER_LOCK_WAIT_TIMEOUT ||
42✔
73
                        sqlErr.Number == mysqlerr.ER_XA_RBTIMEOUT ||
42✔
74
                        sqlErr.Number == mysqlerr.ER_QUERY_TIMEOUT ||
42✔
75
                        sqlErr.Number == mysqlerr.ER_LOCKING_SERVICE_TIMEOUT ||
42✔
76
                        sqlErr.Number == mysqlerr.ER_REGEXP_TIME_OUT {
42✔
77
                        return true
×
78
                }
×
79
        }
80
        return false
811✔
81
}
82

83
func (mdb *db) IsThrottlingError(err error) bool {
811✔
84
        sqlErr, ok := err.(*mysql.MySQLError)
811✔
85
        if ok {
853✔
86
                if sqlErr.Number == mysqlerr.ER_CON_COUNT_ERROR ||
42✔
87
                        sqlErr.Number == mysqlerr.ER_TOO_MANY_USER_CONNECTIONS ||
42✔
88
                        sqlErr.Number == mysqlerr.ER_TOO_MANY_CONCURRENT_TRXS ||
42✔
89
                        sqlErr.Number == mysqlerr.ER_CLONE_TOO_MANY_CONCURRENT_CLONES {
42✔
90
                        return true
×
91
                }
×
92
        }
93
        return false
811✔
94
}
95

96
// newDB returns an instance of DB, which is a logical
97
// connection to the underlying mysql database
98
// dbShardID is needed when tx is not nil
99
func newDB(xdbs []*sqlx.DB, tx *sqlx.Tx, dbShardID int, numDBShards int) (*db, error) {
6,333✔
100
        driver, err := sqldriver.NewDriver(xdbs, tx, dbShardID)
6,333✔
101
        if err != nil {
6,333✔
102
                return nil, err
×
103
        }
×
104

105
        db := &db{
6,333✔
106
                converter:   &converter{},
6,333✔
107
                originalDBs: xdbs, // this is kept because newDB will be called again when starting a transaction
6,333✔
108
                driver:      driver,
6,333✔
109
                numDBShards: numDBShards,
6,333✔
110
        }
6,333✔
111

6,333✔
112
        return db, nil
6,333✔
113
}
114

115
// BeginTx starts a new transaction and returns a reference to the Tx object
116
func (mdb *db) BeginTx(ctx context.Context, dbShardID int) (sqlplugin.Tx, error) {
6,252✔
117
        xtx, err := mdb.driver.BeginTxx(ctx, dbShardID, nil)
6,252✔
118
        if err != nil {
6,252✔
119
                return nil, err
×
120
        }
×
121
        return newDB(mdb.originalDBs, xtx, dbShardID, mdb.numDBShards)
6,252✔
122
}
123

124
// Commit commits a previously started transaction
125
func (mdb *db) Commit() error {
6,108✔
126
        return mdb.driver.Commit()
6,108✔
127
}
6,108✔
128

129
// Rollback triggers rollback of a previously started transaction
130
func (mdb *db) Rollback() error {
145✔
131
        return mdb.driver.Rollback()
145✔
132
}
145✔
133

134
// Close closes the connection to the mysql db
135
func (mdb *db) Close() error {
82✔
136
        return mdb.driver.Close()
82✔
137
}
82✔
138

139
// PluginName returns the name of the mysql plugin
140
func (mdb *db) PluginName() string {
1,962✔
141
        return PluginName
1,962✔
142
}
1,962✔
143

144
// SupportsTTL returns weather MySQL supports TTL
145
func (mdb *db) SupportsTTL() bool {
3,700✔
146
        return false
3,700✔
147
}
3,700✔
148

149
// MaxAllowedTTL returns the max allowed ttl MySQL supports
150
func (mdb *db) MaxAllowedTTL() (*time.Duration, error) {
×
151
        return nil, sqlplugin.ErrTTLNotSupported
×
152
}
×
153

154
// SupportsTTL returns weather MySQL supports Asynchronous transaction
155
func (mdb *db) SupportsAsyncTransaction() bool {
1,553✔
156
        return false
1,553✔
157
}
1,553✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc