From 43c5eeb877435b991fb038dd3e3d1847ed0a20c9 Mon Sep 17 00:00:00 2001 From: Tim Vaillancourt Date: Tue, 17 Dec 2024 03:54:14 +0100 Subject: [PATCH] fix ci Signed-off-by: Tim Vaillancourt --- go/vt/vtorc/inst/analysis_dao_test.go | 4 +-- go/vt/vtorc/inst/keyspace_dao.go | 40 ++++++++++++++++----------- go/vt/vtorc/inst/shard_dao.go | 7 ++--- go/vt/vtorc/inst/shard_dao_test.go | 12 ++++---- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/go/vt/vtorc/inst/analysis_dao_test.go b/go/vt/vtorc/inst/analysis_dao_test.go index c061d54ebb3..00ed4d4e9df 100644 --- a/go/vt/vtorc/inst/analysis_dao_test.go +++ b/go/vt/vtorc/inst/analysis_dao_test.go @@ -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');`, } ) diff --git a/go/vt/vtorc/inst/keyspace_dao.go b/go/vt/vtorc/inst/keyspace_dao.go index d764e3fc56a..ce2d075d38b 100644 --- a/go/vt/vtorc/inst/keyspace_dao.go +++ b/go/vt/vtorc/inst/keyspace_dao.go @@ -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" @@ -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{}, @@ -64,14 +63,12 @@ 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(), @@ -79,6 +76,17 @@ func SaveKeyspace(keyspace *topo.KeyspaceInfo) error { 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) diff --git a/go/vt/vtorc/inst/shard_dao.go b/go/vt/vtorc/inst/shard_dao.go index 89a9652bf71..c1c23dc135a 100644 --- a/go/vt/vtorc/inst/shard_dao.go +++ b/go/vt/vtorc/inst/shard_dao.go @@ -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 diff --git a/go/vt/vtorc/inst/shard_dao_test.go b/go/vt/vtorc/inst/shard_dao_test.go index cc6734e30e9..2d96b042d2d 100644 --- a/go/vt/vtorc/inst/shard_dao_test.go +++ b/go/vt/vtorc/inst/shard_dao_test.go @@ -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() @@ -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) }