Skip to content

Commit

Permalink
fix ci
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Dec 17, 2024
1 parent bc13488 commit 43c5eeb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
4 changes: 2 additions & 2 deletions go/vt/vtorc/inst/analysis_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ var (
`INSERT INTO vitess_tablet VALUES('zone1-0000000101','localhost',6714,'ks','0','zone1',1,'2022-12-28 07:23:25.129898+00:00',X'616c6961733a7b63656c6c3a227a6f6e653122207569643a3130317d20686f73746e616d653a226c6f63616c686f73742220706f72745f6d61703a7b6b65793a2267727063222076616c75653a363731337d20706f72745f6d61703a7b6b65793a227674222076616c75653a363731327d206b657973706163653a226b73222073686172643a22302220747970653a5052494d415259206d7973716c5f686f73746e616d653a226c6f63616c686f737422206d7973716c5f706f72743a36373134207072696d6172795f7465726d5f73746172745f74696d653a7b7365636f6e64733a31363732323132323035206e616e6f7365636f6e64733a3132393839383030307d2064625f7365727665725f76657273696f6e3a22382e302e3331222064656661756c745f636f6e6e5f636f6c6c6174696f6e3a3435');`,
`INSERT INTO vitess_tablet VALUES('zone1-0000000112','localhost',6747,'ks','0','zone1',3,'0001-01-01 00:00:00+00:00',X'616c6961733a7b63656c6c3a227a6f6e653122207569643a3131327d20686f73746e616d653a226c6f63616c686f73742220706f72745f6d61703a7b6b65793a2267727063222076616c75653a363734367d20706f72745f6d61703a7b6b65793a227674222076616c75653a363734357d206b657973706163653a226b73222073686172643a22302220747970653a52444f4e4c59206d7973716c5f686f73746e616d653a226c6f63616c686f737422206d7973716c5f706f72743a363734372064625f7365727665725f76657273696f6e3a22382e302e3331222064656661756c745f636f6e6e5f636f6c6c6174696f6e3a3435');`,
`INSERT INTO vitess_tablet VALUES('zone2-0000000200','localhost',6756,'ks','0','zone2',2,'0001-01-01 00:00:00+00:00',X'616c6961733a7b63656c6c3a227a6f6e653222207569643a3230307d20686f73746e616d653a226c6f63616c686f73742220706f72745f6d61703a7b6b65793a2267727063222076616c75653a363735357d20706f72745f6d61703a7b6b65793a227674222076616c75653a363735347d206b657973706163653a226b73222073686172643a22302220747970653a5245504c494341206d7973716c5f686f73746e616d653a226c6f63616c686f737422206d7973716c5f706f72743a363735362064625f7365727665725f76657273696f6e3a22382e302e3331222064656661756c745f636f6e6e5f636f6c6c6174696f6e3a3435');`,
`INSERT INTO vitess_shard VALUES('ks','0','zone1-0000000101','2022-12-28 07:23:25.129898+00:00');`,
`INSERT INTO vitess_keyspace VALUES('ks',0,'semi_sync');`,
`INSERT INTO vitess_shard VALUES('ks','0','zone1-0000000101','2022-12-28 07:23:25.129898+00:00','2022-12-28 07:23:25.129898+00:00');`,
`INSERT INTO vitess_keyspace VALUES('ks',0,'semi_sync','2022-12-28 07:23:25.129898+00:00');`,
}
)

Expand Down
40 changes: 24 additions & 16 deletions go/vt/vtorc/inst/keyspace_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package inst

import (
"errors"
"time"

"vitess.io/vitess/go/vt/external/golib/sqlutils"
topodatapb "vitess.io/vitess/go/vt/proto/topodata"
Expand All @@ -35,14 +36,12 @@ func ReadKeyspace(keyspaceName string) (*topo.KeyspaceInfo, error) {
return nil, err
}

query := `
select
keyspace_type,
durability_policy
from
vitess_keyspace
where keyspace=?
`
query := `SELECT
keyspace_type,
durability_policy
FROM
vitess_keyspace
WHERE keyspace = ?`
args := sqlutils.Args(keyspaceName)
keyspace := &topo.KeyspaceInfo{
Keyspace: &topodatapb.Keyspace{},
Expand All @@ -64,21 +63,30 @@ func ReadKeyspace(keyspaceName string) (*topo.KeyspaceInfo, error) {

// SaveKeyspace saves the keyspace record against the keyspace name.
func SaveKeyspace(keyspace *topo.KeyspaceInfo) error {
_, err := db.ExecVTOrc(`
replace
into vitess_keyspace (
keyspace, keyspace_type, durability_policy
) values (
?, ?, ?
)
`,
_, err := db.ExecVTOrc(`REPLACE
INTO vitess_keyspace (
keyspace, keyspace_type, durability_policy, updated_timestamp
) VALUES (
?, ?, ?, DATETIME('now')
)`,
keyspace.KeyspaceName(),
int(keyspace.KeyspaceType),
keyspace.GetDurabilityPolicy(),
)
return err
}

// DeleteStaleKeyspaces deletes keyspace records that have not been updated since a provided time.
func DeleteStaleKeyspaces(staleTime time.Time) error {
_, err := db.ExecVTOrc(`DELETE FROM vitess_keyspace
WHERE
updated_timestamp <= DATETIME(?, 'unixepoch')
`,
staleTime.Unix(),
)
return err
}

// GetDurabilityPolicy gets the durability policy for the given keyspace.
func GetDurabilityPolicy(keyspace string) (reparentutil.Durabler, error) {
ki, err := ReadKeyspace(keyspace)
Expand Down
7 changes: 2 additions & 5 deletions go/vt/vtorc/inst/shard_dao.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,12 @@ func SaveShard(shard *topo.ShardInfo) error {
return err
}

// DeleteStaleKeyspaceShards deletes shard records that have not been updated since a provided time.
func DeleteStaleKeyspaceShards(keyspaceName string, staleTime time.Time) error {
// DeleteStaleShards deletes shard records that have not been updated since a provided time.
func DeleteStaleShards(staleTime time.Time) error {
_, err := db.ExecVTOrc(`DELETE FROM vitess_shard
WHERE
keyspace = ?
AND
updated_timestamp <= DATETIME(?, 'unixepoch')
`,
keyspaceName,
staleTime.Unix(),
)
return err
Expand Down
12 changes: 6 additions & 6 deletions go/vt/vtorc/inst/shard_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func TestGetKeyspaceShardNames(t *testing.T) {
require.Equal(t, []string{"-80", "80-"}, shardNames)
}

func TestDeleteStaleKeyspaceShards(t *testing.T) {
func TestDeleteStaleShards(t *testing.T) {
// Clear the database after the test. The easiest way to do that is to run all the initialization commands again.
defer func() {
db.ClearVTOrcDatabase()
Expand All @@ -148,19 +148,19 @@ func TestDeleteStaleKeyspaceShards(t *testing.T) {
shardInfo := topo.NewShardInfo("ks1", "-80", &topodatapb.Shard{}, nil)
err := SaveShard(shardInfo)
require.NoError(t, err)
shards, err := GetKeyspaceShardNames("ks1")
shards, err := GetAllShardNames()
require.NoError(t, err)
require.Len(t, shards, 1)

// test a staletime before save causes no delete
require.NoError(t, DeleteStaleKeyspaceShards("ks1", time.Now().Add(-time.Hour)))
shards, err = GetKeyspaceShardNames("ks1")
require.NoError(t, DeleteStaleShards(time.Now().Add(-time.Hour)))
shards, err = GetAllShardNames()
require.NoError(t, err)
require.Len(t, shards, 1)

// test statetime of now deletes everything
require.NoError(t, DeleteStaleKeyspaceShards("ks1", time.Now()))
shards, err = GetKeyspaceShardNames("ks1")
require.NoError(t, DeleteStaleShards(time.Now()))
shards, err = GetAllShardNames()
require.NoError(t, err)
require.Len(t, shards, 0)
}

0 comments on commit 43c5eeb

Please sign in to comment.