Skip to content

Commit

Permalink
Handled ineffectual errors
Browse files Browse the repository at this point in the history
Signed-off-by: akilan <[email protected]>
  • Loading branch information
Akilan1999 committed Jun 23, 2020
1 parent f15be48 commit 5aa4709
Show file tree
Hide file tree
Showing 24 changed files with 271 additions and 93 deletions.
7 changes: 6 additions & 1 deletion go/cmd/zkctld/zkctld.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ func main() {
log.Infof("server shut down on its own")
case <-sig:
log.Infof("signal received, shutting down server")
zkd.Shutdown()

// Action to perform if there is an error
if err := zkd.Shutdown(); err != nil {
log.Errorf("error during shutdown:%v", err)
exit.Return(1)
}
}
}
13 changes: 11 additions & 2 deletions go/mysql/fakesqldb/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import (
"testing"
"time"

"vitess.io/vitess/go/vt/log"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/sqltypes"

Expand Down Expand Up @@ -347,15 +349,22 @@ func (db *DB) HandleQuery(c *mysql.Conn, query string, callback func(*sqltypes.R
// Check if we should close the connection and provoke errno 2013.
if db.shouldClose {
c.Close()
callback(&sqltypes.Result{})

//log error
if err := callback(&sqltypes.Result{}); err != nil {
log.Errorf("callback failed : %v", err)
}
return nil
}

// Using special handling for 'SET NAMES utf8'. The driver
// may send this at connection time, and we don't want it to
// interfere.
if key == "set names utf8" {
callback(&sqltypes.Result{})
//log error
if err := callback(&sqltypes.Result{}); err != nil {
log.Errorf("callback failed : %v", err)
}
return nil
}

Expand Down
93 changes: 54 additions & 39 deletions go/mysql/replication_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,54 +152,69 @@ const (
// These constants describe the event types.
// See: http://dev.mysql.com/doc/internals/en/binlog-event-type.html
const (
eUnknownEvent = 0
eStartEventV3 = 1
eQueryEvent = 2
eStopEvent = 3
eRotateEvent = 4
eIntVarEvent = 5
eLoadEvent = 6
eSlaveEvent = 7
eCreateFileEvent = 8
eAppendBlockEvent = 9
eExecLoadEvent = 10
eDeleteFileEvent = 11
eNewLoadEvent = 12
eRandEvent = 13
eUserVarEvent = 14
//eUnknownEvent = 0
// Unused
//eStartEventV3 = 1
eQueryEvent = 2
//eStopEvent = 3
eRotateEvent = 4
eIntVarEvent = 5
// Unused
//eLoadEvent = 6
// Unused
//eSlaveEvent = 7
// Unused
//eCreateFileEvent = 8
// Unused
//eAppendBlockEvent = 9
//eExecLoadEvent = 10
// Unused
//eDeleteFileEvent = 11
// Unused
//eNewLoadEvent = 12
eRandEvent = 13
// Unused
//eUserVarEvent = 14
eFormatDescriptionEvent = 15
eXIDEvent = 16
eBeginLoadQueryEvent = 17
eExecuteLoadQueryEvent = 18
eTableMapEvent = 19
eWriteRowsEventV0 = 20
eUpdateRowsEventV0 = 21
eDeleteRowsEventV0 = 22
eWriteRowsEventV1 = 23
eUpdateRowsEventV1 = 24
eDeleteRowsEventV1 = 25
eIncidentEvent = 26
eHeartbeatEvent = 27
eIgnorableEvent = 28
eRowsQueryEvent = 29
eWriteRowsEventV2 = 30
eUpdateRowsEventV2 = 31
eDeleteRowsEventV2 = 32
eGTIDEvent = 33
eAnonymousGTIDEvent = 34
ePreviousGTIDsEvent = 35
//Unused
//eBeginLoadQueryEvent = 17
//Unused
//eExecuteLoadQueryEvent = 18
eTableMapEvent = 19
eWriteRowsEventV0 = 20
eUpdateRowsEventV0 = 21
eDeleteRowsEventV0 = 22
eWriteRowsEventV1 = 23
eUpdateRowsEventV1 = 24
eDeleteRowsEventV1 = 25
// Unused
//eIncidentEvent = 26
//eHeartbeatEvent = 27
// Unused
//eIgnorableEvent = 28
// Unused
//eRowsQueryEvent = 29
eWriteRowsEventV2 = 30
eUpdateRowsEventV2 = 31
eDeleteRowsEventV2 = 32
eGTIDEvent = 33
eAnonymousGTIDEvent = 34
ePreviousGTIDsEvent = 35

// MySQL 5.7 events. Unused.
//eTransactionContextEvent = 36
//eViewChangeEvent = 37
//eXAPrepareLogEvent = 38

// MariaDB specific values. They start at 160.
eMariaAnnotateRowsEvent = 160
eMariaBinlogCheckpointEvent = 161
eMariaGTIDEvent = 162
eMariaGTIDListEvent = 163
eMariaStartEncryptionEvent = 164
eMariaAnnotateRowsEvent = 160
// Unused
//eMariaBinlogCheckpointEvent = 161
eMariaGTIDEvent = 162
eMariaGTIDListEvent = 163
// Unused
//eMariaStartEncryptionEvent = 164
)

// These constants describe the type of status variables in q Query packet.
Expand Down
6 changes: 3 additions & 3 deletions go/test/endtoend/keyspace/keyspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ var (
"column": "keyspace_id",
"name": "hash_index"
}
]
]
}
}
}`
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestDeleteKeyspace(t *testing.T) {

// TODO: Fix this test, not running in CI
// tells that in zone2 after deleting shard, there is no shard #264 and in zone1 there is only 1 #269
func RemoveKeyspaceCell(t *testing.T) {
/*func RemoveKeyspaceCell(t *testing.T) {
_ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateKeyspace", "test_delete_keyspace_removekscell")
_ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateShard", "test_delete_keyspace_removekscell/0")
_ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("CreateShard", "test_delete_keyspace_removekscell/1")
Expand Down Expand Up @@ -314,7 +314,7 @@ func RemoveKeyspaceCell(t *testing.T) {
// Clean up
_ = clusterForKSTest.VtctlclientProcess.ExecuteCommand("DeleteKeyspace", "-recursive", "test_delete_keyspace_removekscell")
}
} */

func TestShardCountForAllKeyspaces(t *testing.T) {
defer cluster.PanicHandler(t)
Expand Down
41 changes: 31 additions & 10 deletions go/test/endtoend/vtgate/buffer/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ func updateExecute(c *threadParams, conn *mysql.Conn) error {
attempt := c.i
// Value used in next UPDATE query. Increased after every query.
c.i++
conn.ExecuteFetch("begin", 1000, true)

if _, err := conn.ExecuteFetch("begin", 1000, true); err != nil {
log.Errorf("begin failed:%v", err)
}

result, err := conn.ExecuteFetch(fmt.Sprintf("UPDATE buffer SET msg='update %d' WHERE id = %d", attempt, updateRowID), 1000, true)

Expand Down Expand Up @@ -269,9 +272,11 @@ func testBufferBase(t *testing.T, isExternalParent bool) {
externalReparenting(ctx, t, clusterInstance)
} else {
//reparent call
clusterInstance.VtctlclientProcess.ExecuteCommand("PlannedReparentShard", "-keyspace_shard",
if err := clusterInstance.VtctlclientProcess.ExecuteCommand("PlannedReparentShard", "-keyspace_shard",
fmt.Sprintf("%s/%s", keyspaceUnshardedName, "0"),
"-new_master", clusterInstance.Keyspaces[0].Shards[0].Vttablets[1].Alias)
"-new_master", clusterInstance.Keyspaces[0].Shards[0].Vttablets[1].Alias); err != nil {
log.Errorf("clusterInstance.VtctlclientProcess.ExecuteCommand(\"PlannedRepare... caused an error : %v", err)
}
}

<-readThreadInstance.waitForNotification
Expand Down Expand Up @@ -354,7 +359,12 @@ func externalReparenting(ctx context.Context, t *testing.T, clusterInstance *clu
newMaster := replica
master.VttabletProcess.QueryTablet(demoteMasterQuery, keyspaceUnshardedName, true)
if master.VttabletProcess.EnableSemiSync {
master.VttabletProcess.QueryTablet(disableSemiSyncMasterQuery, keyspaceUnshardedName, true)

//log error
if _, err := master.VttabletProcess.QueryTablet(disableSemiSyncMasterQuery, keyspaceUnshardedName, true); err != nil {
log.Errorf("master.VttabletProcess.QueryTablet(disableSemi... caused an error : %v", err)
}

}

// Wait for replica to catch up to master.
Expand All @@ -368,11 +378,16 @@ func externalReparenting(ctx context.Context, t *testing.T, clusterInstance *clu
time.Sleep(time.Duration(w) * time.Second)
}

// Promote replica to new master.
replica.VttabletProcess.QueryTablet(promoteSlaveQuery, keyspaceUnshardedName, true)
//Promote replica to new master and log error
if _, err := replica.VttabletProcess.QueryTablet(promoteSlaveQuery, keyspaceUnshardedName, true); err != nil {
log.Errorf("replica.VttabletProcess.QueryTablet(promoteSlaveQuery... caused an error : %v", err)
}

if replica.VttabletProcess.EnableSemiSync {
replica.VttabletProcess.QueryTablet(enableSemiSyncMasterQuery, keyspaceUnshardedName, true)
//Log error
if _, err := replica.VttabletProcess.QueryTablet(enableSemiSyncMasterQuery, keyspaceUnshardedName, true); err != nil {
log.Errorf("replica.VttabletProcess.QueryTablet caused an error : %v", err)
}
}

// Configure old master to replicate from new master.
Expand All @@ -382,8 +397,14 @@ func externalReparenting(ctx context.Context, t *testing.T, clusterInstance *clu
// Use 'localhost' as hostname because Travis CI worker hostnames
// are too long for MySQL replication.
changeMasterCommands := fmt.Sprintf("RESET SLAVE;SET GLOBAL gtid_slave_pos = '%s';CHANGE MASTER TO MASTER_HOST='%s', MASTER_PORT=%d ,MASTER_USER='vt_repl', MASTER_USE_GTID = slave_pos;START SLAVE;", gtID, "localhost", newMaster.MySQLPort)
oldMaster.VttabletProcess.QueryTablet(changeMasterCommands, keyspaceUnshardedName, true)

// Notify the new vttablet master about the reparent.
clusterInstance.VtctlclientProcess.ExecuteCommand("TabletExternallyReparented", newMaster.Alias)
//Log error
if _, err := oldMaster.VttabletProcess.QueryTablet(changeMasterCommands, keyspaceUnshardedName, true); err != nil {
log.Errorf("oldMaster.VttabletProcess.QueryTablet caused an error : %v", err)
}

//Notify the new vttablet master about the reparent and Log error
if err := clusterInstance.VtctlclientProcess.ExecuteCommand("TabletExternallyReparented", newMaster.Alias); err != nil {
log.Errorf("clusterInstance.VtctlclientProcess.ExecuteCommand caused an error : %v", err)
}
}
8 changes: 7 additions & 1 deletion go/vt/binlog/binlogplayer/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"reflect"
"testing"

"vitess.io/vitess/go/vt/log"

"github.com/golang/protobuf/proto"
"golang.org/x/net/context"

Expand Down Expand Up @@ -116,5 +118,9 @@ var globalFBC *fakeBinlogClient

func init() {
RegisterClientFactory("test", func() Client { return globalFBC })
flag.Set("binlog_player_protocol", "test")

//log error
if err := flag.Set("binlog_player_protocol", "test"); err != nil {
log.Errorf("failed to set flag \"binlog_player_protocol\" to \"test\":%v", err)
}
}
12 changes: 10 additions & 2 deletions go/vt/discovery/healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,21 @@ func (hc *HealthCheckImpl) ServeHTTP(w http.ResponseWriter, _ *http.Request) {
status := hc.CacheStatus()
b, err := json.MarshalIndent(status, "", " ")
if err != nil {
w.Write([]byte(err.Error()))
//Error logged
if _, err := w.Write([]byte(err.Error())); err != nil {
log.Errorf("write to buffer error failed: %v", err)
}

return
}

buf := bytes.NewBuffer(nil)
json.HTMLEscape(buf, b)
w.Write(buf.Bytes())

//Error logged
if _, err := w.Write(buf.Bytes()); err != nil {
log.Errorf("write to buffer bytes failed: %v", err)
}
}

// servingConnStats returns the number of serving tablets per keyspace/shard/tablet type.
Expand Down
14 changes: 12 additions & 2 deletions go/vt/discovery/healthcheck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"testing"
"time"

"vitess.io/vitess/go/vt/log"

"vitess.io/vitess/go/test/utils"
"vitess.io/vitess/go/vt/vttablet/queryservice/fakes"

Expand All @@ -48,7 +50,11 @@ import (

func init() {
tabletconn.RegisterDialer("fake_gateway", tabletDialer)
flag.Set("tablet_protocol", "fake_gateway")

//log error
if err := flag.Set("tablet_protocol", "fake_gateway"); err != nil {
log.Errorf("failed to set flag \"tablet_protocol\" to \"fake_gateway\":%v", err)
}
}

func TestHealthCheck(t *testing.T) {
Expand Down Expand Up @@ -730,7 +736,11 @@ func TestTemplate(t *testing.T) {
}

func TestDebugURLFormatting(t *testing.T) {
flag.Set("tablet_url_template", "https://{{.GetHostNameLevel 0}}.bastion.{{.Tablet.Alias.Cell}}.corp")

//log error
if err2 := flag.Set("tablet_url_template", "https://{{.GetHostNameLevel 0}}.bastion.{{.Tablet.Alias.Cell}}.corp"); err2 != nil {
log.Errorf("flag.Set(\"tablet_url_template\", \"https://{{.GetHostNameLevel 0}}.bastion.{{.Tablet.Alias.Cell}}.corp\") failed : %v", err2)
}
ParseTabletURLTemplateFromFlag()

tablet := topo.NewTablet(0, "cell", "host.dc.domain")
Expand Down
6 changes: 5 additions & 1 deletion go/vt/discovery/legacy_healthcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ func (e LegacyTabletStats) NamedStatusURL() string {
// {{.NamedStatusURL}} -> test-0000000001/debug/status
func (e LegacyTabletStats) getTabletDebugURL() string {
var buffer bytes.Buffer
tabletURLTemplate.Execute(&buffer, e)

//Error logged
if err := tabletURLTemplate.Execute(&buffer, e); err != nil {
log.Errorf("tabletURLTemplate.Execute(&buffer, e) failed: %v", err)
}
return buffer.String()
}

Expand Down
8 changes: 7 additions & 1 deletion go/vt/discovery/legacy_healthcheck_flaky_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import (
"testing"
"time"

"vitess.io/vitess/go/vt/log"

"golang.org/x/net/context"
"vitess.io/vitess/go/vt/grpcclient"
"vitess.io/vitess/go/vt/status"
Expand All @@ -42,7 +44,11 @@ var connMap map[string]*fakeConn

func init() {
tabletconn.RegisterDialer("fake_discovery", discoveryDialer)
flag.Set("tablet_protocol", "fake_discovery")

//log error
if err := flag.Set("tablet_protocol", "fake_discovery"); err != nil {
log.Errorf("flag.Set(\"tablet_protocol\", \"fake_discovery\") failed : %v", err)
}
connMap = make(map[string]*fakeConn)
}

Expand Down
Loading

0 comments on commit 5aa4709

Please sign in to comment.