Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions pkg/atomic2/atomic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package atomic2

import (
"sync/atomic"
"unsafe"
)

// AtomicError implements atomic error method
type AtomicError struct {
p unsafe.Pointer
}

// Get returns error
func (e *AtomicError) Get() error {
p := atomic.LoadPointer(&e.p)
if p == nil {
return nil
}
return *(*error)(p)
}

// Set sets error to AtomicError
func (e *AtomicError) Set(err error) {
atomic.StorePointer(&e.p, unsafe.Pointer(&err))
}
50 changes: 50 additions & 0 deletions pkg/atomic2/atomic_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2020 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package atomic2

import (
"errors"
"testing"

"github.com/pingcap/check"
)

func TestT(t *testing.T) {
check.TestingT(t)
}

var _ = check.Suite(&testAtomicSuite{})

type testAtomicSuite struct{}

func (t *testAtomicSuite) TestAtomicError(c *check.C) {
var (
e AtomicError
err = errors.New("test")
)
err2 := e.Get()
c.Assert(err2, check.Equals, nil)

e.Set(err)
err2 = e.Get()
c.Assert(err2, check.DeepEquals, err)

err = errors.New("test2")
err2 = e.Get()
c.Assert(err2.Error(), check.Equals, "test")

e.Set(nil)
err2 = e.Get()
c.Assert(err2, check.Equals, nil)
}
4 changes: 2 additions & 2 deletions syncer/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ func (cp *RemoteCheckPoint) SaveGlobalPoint(location binlog.Location) {

// FlushPointsExcept implements CheckPoint.FlushPointsExcept
func (cp *RemoteCheckPoint) FlushPointsExcept(tctx *tcontext.Context, exceptTables [][]string, extraSQLs []string, extraArgs [][]interface{}) error {
cp.RLock()
defer cp.RUnlock()
cp.Lock()
defer cp.Unlock()

// convert slice to map
excepts := make(map[string]map[string]struct{})
Expand Down
4 changes: 2 additions & 2 deletions syncer/optimist.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ func (s *Syncer) handleQueryEventOptimistic(
return err
}

if s.execErrorDetected.Get() {
return terror.ErrSyncerUnitHandleDDLFailed.Generate(ev.Query)
if err := s.execError.Get(); err != nil {
return terror.ErrSyncerUnitHandleDDLFailed.Delegate(err, ev.Query)
}

for _, table := range onlineDDLTableNames {
Expand Down
Loading