Skip to content

Commit 4bd16ca

Browse files
committed
make it safe by return error instead of nil
Signed-off-by: Wenqi Mou <[email protected]>
1 parent de2100f commit 4bd16ca

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

br/pkg/stream/rewrite_meta_rawkv.go

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,7 @@ func (sr *SchemasReplace) rewriteKeyForDB(key []byte, cf string) ([]byte, error)
129129

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

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

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

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

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

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

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

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

254248
// update table ID and partition ID.

0 commit comments

Comments
 (0)