Skip to content

Commit

Permalink
[cherry-pick] pr #13909 fix some unhandled error and redundant codes (#…
Browse files Browse the repository at this point in the history
…13910)

some error was unhandled and it may cause hung.
removed some unused codes like redundant type conversion.

Approved by: @nnsgmsone, @sukki37
  • Loading branch information
m-schen committed Dec 30, 2023
1 parent 94a7724 commit f435599
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
6 changes: 5 additions & 1 deletion pkg/sql/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func (c *Compile) runOnce() error {
for i := range c.scope {
wg.Add(1)
scope := c.scope[i]
ants.Submit(func() {
errSubmit := ants.Submit(func() {
defer func() {
if e := recover(); e != nil {
err := moerr.ConvertPanicError(c.ctx, e)
Expand All @@ -541,6 +541,10 @@ func (c *Compile) runOnce() error {
}()
errC <- c.run(scope)
})
if errSubmit != nil {
errC <- errSubmit
wg.Done()
}
}
wg.Wait()
close(errC)
Expand Down
8 changes: 4 additions & 4 deletions pkg/sql/compile/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ func (s *Scope) AlterTableInplace(c *Compile) error {
}
if !originHasIndexDef && addIndex != nil {
newCt.Cts = append(newCt.Cts, &engine.IndexDef{
Indexes: []*plan.IndexDef(addIndex),
Indexes: addIndex,
})
}

Expand Down Expand Up @@ -1331,7 +1331,7 @@ func (s *Scope) TruncateTable(c *Compile) error {
for _, name := range tqry.PartitionTableNames {
var err error
if isTemp {
dbSource.Truncate(c.ctx, engine.GetTempTableName(dbName, name))
_, err = dbSource.Truncate(c.ctx, engine.GetTempTableName(dbName, name))
} else {
_, err = dbSource.Truncate(c.ctx, name)
}
Expand Down Expand Up @@ -2268,8 +2268,8 @@ func makeAlterSequenceParam[T constraints.Integer](ctx context.Context, stmt *tr
preStartWith := preLastSeqNum
if stmt.StartWith != nil {
startNum = getValue[T](stmt.StartWith.Minus, stmt.StartWith.Num)
if startNum < T(preStartWith) {
startNum = T(preStartWith)
if startNum < preStartWith {
startNum = preStartWith
}
} else {
startNum = getInterfaceValue[T](preStartWith)
Expand Down
13 changes: 9 additions & 4 deletions pkg/sql/compile/fuzzyCheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
// 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
// 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package compile

import (
Expand Down Expand Up @@ -132,7 +133,9 @@ func (f *fuzzyCheck) fill(ctx context.Context, bat *batch.Batch) error {
// the last condition does not need to be followed by "and"
one.WriteString(fmt.Sprintf("%s = %s", cAttrs[j], pkeys[j][i]))
one.WriteByte(')')
one.WriteTo(&all)
if _, err = one.WriteTo(&all); err != nil {
return err
}

// use or join each compound primary keys
all.WriteString(" or ")
Expand All @@ -144,7 +147,9 @@ func (f *fuzzyCheck) fill(ctx context.Context, bat *batch.Batch) error {
}

one.WriteString(fmt.Sprintf("%s = %s", cAttrs[j], pkeys[j][lastRow]))
one.WriteTo(&all)
if _, err = one.WriteTo(&all); err != nil {
return err
}
f.condition = all.String()
}

Expand Down Expand Up @@ -377,7 +382,7 @@ func (f *fuzzyCheck) formatNonCompound(toCheck *vector.Vector, useInErr bool) ([

// datime time and timestamp type can not split by space directly
func (f *fuzzyCheck) handletimesType(toCheck *vector.Vector) []string {
result := []string{}
result := make([]string, 0, toCheck.Length())
typ := toCheck.GetType()

if typ.Oid == types.T_timestamp {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/compile/runtime_filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func ApplyRuntimeFilters(

case pipeline.RuntimeFilter_MIN_MAX:
evaluators[i] = &RuntimeZonemapFilter{
Zm: objectio.ZoneMap(filter.Data),
Zm: filter.Data,
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/sql/compile/scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (s *Scope) MergeRun(c *Compile) error {
for i := range s.PreScopes {
wg.Add(1)
scope := s.PreScopes[i]
ants.Submit(func() {
errSubmit := ants.Submit(func() {
defer func() {
if e := recover(); e != nil {
err := moerr.ConvertPanicError(c.ctx, e)
Expand All @@ -136,6 +136,10 @@ func (s *Scope) MergeRun(c *Compile) error {
errChan <- scope.ParallelRun(c, scope.IsRemote)
}
})
if errSubmit != nil {
errChan <- errSubmit
wg.Done()
}
}
defer wg.Wait()

Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/compile/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const (
Replace
)

// Source contains information of a relation which will be used in execution,
// Source contains information of a relation which will be used in execution.
type Source struct {
PushdownId uint64
PushdownAddr string
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/compile/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ func genInsertMOIndexesSql(eg engine.Engine, proc *process.Process, databaseId s
case *engine.IndexDef:
for _, indexdef := range def.Indexes {
ctx, cancelFunc := context.WithTimeout(proc.Ctx, time.Second*30)
defer cancelFunc()
index_id, err := eg.AllocateIDByKey(ctx, ALLOCID_INDEX_KEY)
cancelFunc()
if err != nil {
return "", err
}
Expand Down Expand Up @@ -247,8 +247,8 @@ func genInsertMOIndexesSql(eg engine.Engine, proc *process.Process, databaseId s
}
case *engine.PrimaryKeyDef:
ctx, cancelFunc := context.WithTimeout(proc.Ctx, time.Second*30)
defer cancelFunc()
index_id, err := eg.AllocateIDByKey(ctx, ALLOCID_INDEX_KEY)
cancelFunc()
if err != nil {
return "", err
}
Expand Down

0 comments on commit f435599

Please sign in to comment.