Skip to content

Commit

Permalink
make it safe by return error instead of nil
Browse files Browse the repository at this point in the history
Signed-off-by: Wenqi Mou <[email protected]>
  • Loading branch information
Tristan1900 committed Jan 23, 2025
1 parent de2100f commit 4bd16ca
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions br/pkg/stream/rewrite_meta_rawkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ func (sr *SchemasReplace) rewriteKeyForDB(key []byte, cf string) ([]byte, error)

dbMap, exist := sr.DbMap[dbID]
if !exist {
// db filtered out
return nil, nil
return nil, errors.Annotatef(berrors.ErrInvalidArgument, "failed to find db id:%v in maps", dbID)
}

rawMetaKey.UpdateField(meta.DBkey(dbMap.DbID))
Expand All @@ -148,8 +147,7 @@ func (sr *SchemasReplace) rewriteDBInfo(value []byte) ([]byte, error) {

dbMap, exist := sr.DbMap[dbInfo.ID]
if !exist {
// db filtered out
return nil, nil
return nil, errors.Annotatef(berrors.ErrInvalidArgument, "failed to find db id:%v in maps", dbInfo.ID)
}

dbInfo.ID = dbMap.DbID
Expand Down Expand Up @@ -208,14 +206,12 @@ func (sr *SchemasReplace) rewriteKeyForTable(

dbReplace, exist := sr.DbMap[dbID]
if !exist {
// db filtered out
return nil, nil
return nil, errors.Annotatef(berrors.ErrInvalidArgument, "failed to find db id:%v in maps", dbID)
}

tableReplace, exist := dbReplace.TableMap[tableID]
if !exist {
// table filtered out
return nil, nil
return nil, errors.Annotatef(berrors.ErrInvalidArgument, "failed to find table id:%v in maps", tableID)
}

rawMetaKey.UpdateKey(meta.DBkey(dbReplace.DbID))
Expand All @@ -241,14 +237,12 @@ func (sr *SchemasReplace) rewriteTableInfo(value []byte, dbID int64) ([]byte, er
// construct or find the id map.
dbReplace, exist = sr.DbMap[dbID]
if !exist {
// db filtered out
return nil, nil
return nil, errors.Annotatef(berrors.ErrInvalidArgument, "failed to find db id:%v in maps", dbID)
}

tableReplace, exist = dbReplace.TableMap[tableInfo.ID]
if !exist {
// table filtered out
return nil, nil
return nil, errors.Annotatef(berrors.ErrInvalidArgument, "failed to find table id:%v in maps", tableInfo.ID)
}

// update table ID and partition ID.
Expand Down

0 comments on commit 4bd16ca

Please sign in to comment.