Skip to content

Commit 240ced6

Browse files
committed
[perf]:featuredb dao add returns err
1 parent 56c0597 commit 240ced6

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

dao/feature_view_featuredb_dao.go

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (d *FeatureViewFeatureDBDao) GetFeatures(keys []interface{}, selectFields [
7777
return result, errors.New("FeatureDB datasource has not been created")
7878
}
7979

80+
errChan := make(chan error, len(keys)/groupSize+1)
8081
for i := 0; i < len(keys); i += groupSize {
8182
end := i + groupSize
8283
if end > len(keys) {
@@ -155,12 +156,14 @@ func (d *FeatureViewFeatureDBDao) GetFeatures(keys []interface{}, selectFields [
155156
binary.Read(innerReader, binary.LittleEndian, &protocalVersion)
156157
binary.Read(innerReader, binary.LittleEndian, &ifNullFlagVersion)
157158

158-
readFeatureDBFunc_F_1 := func() map[string]interface{} {
159+
readFeatureDBFunc_F_1 := func() (map[string]interface{}, error) {
159160
properties := make(map[string]interface{})
160161

161162
for _, field := range d.fields {
162163
var isNull uint8
163-
binary.Read(innerReader, binary.LittleEndian, &isNull)
164+
if err := binary.Read(innerReader, binary.LittleEndian, &isNull); err != nil {
165+
return nil, err
166+
}
164167

165168
if isNull == 1 {
166169
// 跳过空值
@@ -216,19 +219,27 @@ func (d *FeatureViewFeatureDBDao) GetFeatures(keys []interface{}, selectFields [
216219

217220
skipData := make([]byte, skipBytes)
218221
if _, err := io.ReadFull(innerReader, skipData); err != nil {
219-
panic(err)
222+
return nil, err
220223
}
221224
}
222225
}
223226
properties[d.primaryKeyField] = ks[keyStartIdx+i]
224227

225-
return properties
226-
}()
228+
return properties, nil
229+
}
227230

228231
if protocalVersion == FeatureDB_Protocal_Version_F && ifNullFlagVersion == FeatureDB_IfNull_Flag_Version_1 {
229-
innerResult = append(innerResult, readFeatureDBFunc_F_1)
232+
readResult, err := readFeatureDBFunc_F_1()
233+
if err != nil {
234+
errChan <- err
235+
fmt.Println(err)
236+
return
237+
}
238+
innerResult = append(innerResult, readResult)
230239
} else {
231-
panic(fmt.Sprintf("protocalVersion %v or ifNullFlagVersion %d is not supported\n", protocalVersion, ifNullFlagVersion))
240+
errChan <- fmt.Errorf("FeatureDB read key %v error: protocalVersion %v or ifNullFlagVersion %d is not supported", ks[keyStartIdx+i], protocalVersion, ifNullFlagVersion)
241+
fmt.Printf("FeatureDB read key %v error: protocalVersion %v or ifNullFlagVersion %d is not supported", ks[keyStartIdx+i], protocalVersion, ifNullFlagVersion)
242+
return
232243
}
233244
}
234245
keyStartIdx += recordBlock.ValuesLength()
@@ -240,6 +251,13 @@ func (d *FeatureViewFeatureDBDao) GetFeatures(keys []interface{}, selectFields [
240251

241252
}
242253
wg.Wait()
254+
close(errChan)
255+
256+
for err := range errChan {
257+
if err != nil {
258+
return nil, err
259+
}
260+
}
243261

244262
return result, nil
245263
}

0 commit comments

Comments
 (0)