Let system panic if kv operation fail (#7143)

Signed-off-by: yudong.cai <yudong.cai@zilliz.com>
This commit is contained in:
Cai Yudong 2021-08-17 23:06:10 +08:00 committed by GitHub
parent ecd9847848
commit 21117241ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 67 additions and 55 deletions

View File

@ -200,7 +200,8 @@ func (mt *metaTable) AddTenant(te *pb.TenantMeta) (typeutil.Timestamp, error) {
ts, err := mt.client.Save(k, v)
if err != nil {
return 0, err
log.Error("SnapShotKV Save fail", zap.Error(err))
panic("SnapShotKV Save fail")
}
mt.tenantID2Meta[te.ID] = *te
return ts, nil
@ -215,7 +216,8 @@ func (mt *metaTable) AddProxy(po *pb.ProxyMeta) (typeutil.Timestamp, error) {
ts, err := mt.client.Save(k, v)
if err != nil {
return 0, err
log.Error("SnapShotKV Save fail", zap.Error(err))
panic("SnapShotKV Save fail")
}
mt.proxyID2Meta[po.ID] = *po
return ts, nil
@ -266,8 +268,8 @@ func (mt *metaTable) AddCollection(coll *pb.CollectionInfo, idx []*pb.IndexInfo,
ts, err := mt.client.MultiSave(meta, addition, saveColl)
if err != nil {
_ = mt.reloadFromKV()
return 0, err
log.Error("SnapShotKV MultiSave fail", zap.Error(err))
panic("SnapShotKV MultiSave fail")
}
return ts, nil
@ -319,8 +321,8 @@ func (mt *metaTable) DeleteCollection(collID typeutil.UniqueID, ddOpStr func(ts
addition := mt.getAdditionKV(ddOpStr, saveMeta)
ts, err := mt.client.MultiSaveAndRemoveWithPrefix(saveMeta, delMetakeys, addition)
if err != nil {
_ = mt.reloadFromKV()
return 0, err
log.Error("SnapShotKV MultiSaveAndRemoveWithPrefix fail", zap.Error(err))
panic("SnapShotKV MultiSaveAndRemoveWithPrefix fail")
}
return ts, nil
@ -504,8 +506,8 @@ func (mt *metaTable) AddPartition(collID typeutil.UniqueID, partitionName string
ts, err := mt.client.MultiSave(meta, addition, saveColl)
if err != nil {
_ = mt.reloadFromKV()
return 0, err
log.Error("SnapShotKV MultiSave fail", zap.Error(err))
panic("SnapShotKV MultiSave fail")
}
return ts, nil
}
@ -587,7 +589,7 @@ func (mt *metaTable) HasPartition(collID typeutil.UniqueID, partitionName string
return err == nil
}
//return timestamp, partitionid, error
//return timestamp, partition id, error
func (mt *metaTable) DeletePartition(collID typeutil.UniqueID, partitionName string, ddOpStr func(ts typeutil.Timestamp) (string, error)) (typeutil.Timestamp, typeutil.UniqueID, error) {
mt.ddLock.Lock()
defer mt.ddLock.Unlock()
@ -646,8 +648,8 @@ func (mt *metaTable) DeletePartition(collID typeutil.UniqueID, partitionName str
ts, err := mt.client.MultiSaveAndRemoveWithPrefix(meta, delMetaKeys, addition)
if err != nil {
_ = mt.reloadFromKV()
return 0, 0, err
log.Error("SnapShotKV MultiSaveAndRemoveWithPrefix fail", zap.Error(err))
panic("SnapShotKV MultiSaveAndRemoveWithPrefix fail")
}
return ts, partID, nil
}
@ -699,8 +701,8 @@ func (mt *metaTable) AddIndex(segIdxInfo *pb.SegmentIndexInfo) (typeutil.Timesta
ts, err := mt.client.Save(k, v)
if err != nil {
_ = mt.reloadFromKV()
return 0, err
log.Error("SnapShotKV Save fail", zap.Error(err))
panic("SnapShotKV Save fail")
}
return ts, nil
@ -772,8 +774,8 @@ func (mt *metaTable) DropIndex(collName, fieldName, indexName string) (typeutil.
ts, err := mt.client.MultiSaveAndRemoveWithPrefix(saveMeta, delMeta)
if err != nil {
_ = mt.reloadFromKV()
return 0, 0, false, err
log.Error("SnapShotKV MultiSaveAndRemoveWithPrefix fail", zap.Error(err))
panic("SnapShotKV MultiSaveAndRemoveWithPrefix fail")
}
return ts, dropIdxID, true, nil
@ -946,8 +948,8 @@ func (mt *metaTable) GetNotIndexedSegments(collName string, fieldName string, id
_, err = mt.client.MultiSave(meta)
if err != nil {
_ = mt.reloadFromKV()
return nil, schemapb.FieldSchema{}, err
log.Error("SnapShotKV MultiSave fail", zap.Error(err))
panic("SnapShotKV MultiSave fail")
}
} else {
@ -969,8 +971,8 @@ func (mt *metaTable) GetNotIndexedSegments(collName string, fieldName string, id
_, err = mt.client.MultiSave(meta)
if err != nil {
_ = mt.reloadFromKV()
return nil, schemapb.FieldSchema{}, err
log.Error("SnapShotKV MultiSave fail", zap.Error(err))
panic("SnapShotKV MultiSave fail")
}
}
}

View File

@ -121,16 +121,18 @@ func Test_MockKV(t *testing.T) {
k1.save = func(key, value string) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("save tenant error")
}
_, err = m1.AddTenant(&pb.TenantMeta{})
assert.NotNil(t, err)
assert.EqualError(t, err, "save tenant error")
assert.Panics(t, func() { m1.AddTenant(&pb.TenantMeta{}) })
//_, err = m1.AddTenant(&pb.TenantMeta{})
//assert.NotNil(t, err)
//assert.EqualError(t, err, "save tenant error")
k1.save = func(key, value string) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("save proxy error")
}
_, err = m1.AddProxy(&pb.ProxyMeta{})
assert.NotNil(t, err)
assert.EqualError(t, err, "save proxy error")
assert.Panics(t, func() { m1.AddProxy(&pb.ProxyMeta{}) })
//_, err = m1.AddProxy(&pb.ProxyMeta{})
//assert.NotNil(t, err)
//assert.EqualError(t, err, "save proxy error")
}
func TestMetaTable(t *testing.T) {
@ -458,9 +460,10 @@ func TestMetaTable(t *testing.T) {
collInfo.PartitionIDs = nil
collInfo.PartitionNames = nil
collInfo.PartitionCreatedTimestamps = nil
_, err := mt.AddCollection(collInfo, idxInfo, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "multi save error")
assert.Panics(t, func() { mt.AddCollection(collInfo, idxInfo, nil) })
//_, err := mt.AddCollection(collInfo, idxInfo, nil)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "multi save error")
})
t.Run("delete collection failed", func(t *testing.T) {
@ -482,9 +485,10 @@ func TestMetaTable(t *testing.T) {
_, err := mt.AddCollection(collInfo, idxInfo, nil)
assert.Nil(t, err)
mt.indexID2Meta = make(map[int64]pb.IndexInfo)
_, err = mt.DeleteCollection(collInfo.ID, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "multi save and remove with prefix error")
assert.Panics(t, func() { mt.DeleteCollection(collInfo.ID, nil) })
//_, err = mt.DeleteCollection(collInfo.ID, nil)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "multi save and remove with prefix error")
})
t.Run("get collection failed", func(t *testing.T) {
@ -539,9 +543,10 @@ func TestMetaTable(t *testing.T) {
mockKV.multiSave = func(kvs map[string]string, addition ...func(ts typeutil.Timestamp) (string, string, error)) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("multi save error")
}
_, err = mt.AddPartition(coll.ID, "no-part", 22, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "multi save error")
assert.Panics(t, func() { mt.AddPartition(coll.ID, "no-part", 22, nil) })
//_, err = mt.AddPartition(coll.ID, "no-part", 22, nil)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "multi save error")
mockKV.multiSave = func(kvs map[string]string, addition ...func(ts typeutil.Timestamp) (string, string, error)) (typeutil.Timestamp, error) {
ts := ftso()
@ -556,10 +561,10 @@ func TestMetaTable(t *testing.T) {
collInfo.PartitionNames = nil
collInfo.PartitionCreatedTimestamps = nil
_, err = mt.AddCollection(collInfo, idxInfo, nil)
assert.Nil(t, err)
_, err = mt.AddPartition(coll.ID, partName, partID, nil)
assert.Nil(t, err)
//_, err = mt.AddCollection(collInfo, idxInfo, nil)
//assert.Nil(t, err)
//_, err = mt.AddPartition(coll.ID, partName, partID, nil)
//assert.Nil(t, err)
_, err = mt.AddPartition(coll.ID, partName, 22, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, fmt.Sprintf("partition name = %s already exists", partName))
@ -623,9 +628,10 @@ func TestMetaTable(t *testing.T) {
mockKV.multiSaveAndRemoveWithPrefix = func(saves map[string]string, removals []string, addition ...func(ts typeutil.Timestamp) (string, string, error)) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("multi save and remove with prefix error")
}
_, _, err = mt.DeletePartition(collInfo.ID, partName, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "multi save and remove with prefix error")
assert.Panics(t, func() { mt.DeletePartition(collInfo.ID, partName, nil) })
//_, _, err = mt.DeletePartition(collInfo.ID, partName, nil)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "multi save and remove with prefix error")
mt.collID2Meta = make(map[int64]pb.CollectionInfo)
_, _, err = mt.DeletePartition(collInfo.ID, "abc", nil)
@ -688,9 +694,10 @@ func TestMetaTable(t *testing.T) {
mockKV.save = func(key, value string) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("save error")
}
_, err = mt.AddIndex(&segIdxInfo)
assert.NotNil(t, err)
assert.EqualError(t, err, "save error")
assert.Panics(t, func() { mt.AddIndex(&segIdxInfo) })
//_, err = mt.AddIndex(&segIdxInfo)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "save error")
})
t.Run("drop index failed", func(t *testing.T) {
@ -759,9 +766,10 @@ func TestMetaTable(t *testing.T) {
mockKV.multiSaveAndRemoveWithPrefix = func(saves map[string]string, removals []string, addition ...func(ts typeutil.Timestamp) (string, string, error)) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("multi save and remove with prefix error")
}
_, _, _, err = mt.DropIndex(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idxInfo[0].IndexName)
assert.NotNil(t, err)
assert.EqualError(t, err, "multi save and remove with prefix error")
assert.Panics(t, func() { mt.DropIndex(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idxInfo[0].IndexName) })
//_, _, _, err = mt.DropIndex(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idxInfo[0].IndexName)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "multi save and remove with prefix error")
})
t.Run("get segment index info by id", func(t *testing.T) {
@ -928,9 +936,10 @@ func TestMetaTable(t *testing.T) {
mockKV.multiSave = func(kvs map[string]string, addition ...func(ts typeutil.Timestamp) (string, string, error)) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("multi save error")
}
_, _, err = mt.GetNotIndexedSegments(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idx, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "multi save error")
assert.Panics(t, func() { mt.GetNotIndexedSegments(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idx, nil) })
//_, _, err = mt.GetNotIndexedSegments(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idx, nil)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "multi save error")
mockKV.multiSave = func(kvs map[string]string, addition ...func(ts typeutil.Timestamp) (string, string, error)) (typeutil.Timestamp, error) {
ts := ftso()
@ -944,8 +953,8 @@ func TestMetaTable(t *testing.T) {
collInfo.PartitionIDs = nil
collInfo.PartitionNames = nil
collInfo.PartitionCreatedTimestamps = nil
_, err = mt.AddCollection(collInfo, idxInfo, nil)
assert.Nil(t, err)
//_, err = mt.AddCollection(collInfo, idxInfo, nil)
//assert.Nil(t, err)
coll, ok := mt.collID2Meta[collInfo.ID]
assert.True(t, ok)
coll.FieldIndexes = append(coll.FieldIndexes, &pb.FieldIndexInfo{FiledID: coll.FieldIndexes[0].FiledID, IndexID: coll.FieldIndexes[0].IndexID + 1})
@ -967,9 +976,10 @@ func TestMetaTable(t *testing.T) {
mockKV.multiSave = func(kvs map[string]string, addition ...func(ts typeutil.Timestamp) (string, string, error)) (typeutil.Timestamp, error) {
return 0, fmt.Errorf("multi save error")
}
_, _, err = mt.GetNotIndexedSegments(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idx, nil)
assert.NotNil(t, err)
assert.EqualError(t, err, "multi save error")
assert.Panics(t, func() { mt.GetNotIndexedSegments(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idx, nil) })
//_, _, err = mt.GetNotIndexedSegments(collInfo.Schema.Name, collInfo.Schema.Fields[0].Name, idx, nil)
//assert.NotNil(t, err)
//assert.EqualError(t, err, "multi save error")
})
t.Run("get index by name failed", func(t *testing.T) {