diff --git a/service/stonenode/sync.go b/service/stonenode/sync.go index 2849b2972..aa1240c3c 100644 --- a/service/stonenode/sync.go +++ b/service/stonenode/sync.go @@ -190,16 +190,24 @@ func (node *StoneNodeService) dispatchSecondarySP(pieceDataBySegment map[string] // if redundancyType is replica or inline, value is [][]byte type, a two-dimensional array // which only contains one []byte data var err error - switch redundancyType { - //case ptypes.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE, ptypes.RedundancyType_REDUNDANCY_TYPE_INLINE_TYPE: - // pieceDataBySecondary, err = fillReplicaOrInlineData(pieceDataBySegment, secondarySPs, targetIdx) - default: // ec type - pieceDataBySecondary, err = fillECData(pieceDataBySegment, secondarySPs, targetIdx, redundancyType) - } + pieceDataBySecondary, err = fillECData(pieceDataBySegment, secondarySPs, targetIdx, redundancyType) if err != nil { log.Errorw("fill piece data by secondary error", "error", err) return nil, err } + + /* + switch redundancyType { + case ptypes.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE, ptypes.RedundancyType_REDUNDANCY_TYPE_INLINE_TYPE: + pieceDataBySecondary, err = fillReplicaOrInlineData(pieceDataBySegment, secondarySPs, targetIdx) + default: // ec type + pieceDataBySecondary, err = fillECData(pieceDataBySegment, secondarySPs, targetIdx, redundancyType) + } + if err != nil { + log.Errorw("fill piece data by secondary error", "error", err) + return nil, err + } + */ return pieceDataBySecondary, nil } diff --git a/service/stonenode/sync_test.go b/service/stonenode/sync_test.go index c6eb0ad3d..ce6d88e45 100644 --- a/service/stonenode/sync_test.go +++ b/service/stonenode/sync_test.go @@ -216,7 +216,7 @@ func Test_dispatchSecondarySP(t *testing.T) { req2: ptypes.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE, req3: spList, req4: []uint32{0, 1, 2}, - wantedResult: 3, + wantedResult: 1, wantedErr: nil, }, { @@ -243,7 +243,7 @@ func Test_dispatchSecondarySP(t *testing.T) { req2: ptypes.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE, req3: spList, req4: []uint32{1, 2}, - wantedResult: 2, + wantedResult: 0, wantedErr: nil, }, { @@ -255,24 +255,24 @@ func Test_dispatchSecondarySP(t *testing.T) { wantedResult: 0, wantedErr: merrors.ErrSecondarySPNumber, }, - { - name: "wrong ec segment data length", - req1: dispatchSegmentMap(), - req2: ptypes.RedundancyType_REDUNDANCY_TYPE_EC_TYPE_UNSPECIFIED, - req3: spList, - req4: []uint32{0, 1, 2, 3, 4, 5}, - wantedResult: 0, - wantedErr: merrors.ErrInvalidECData, - }, - { - name: "wrong replica/inline segment data length", - req1: dispatchPieceMap(), - req2: ptypes.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE, - req3: spList, - req4: []uint32{0, 1, 2, 3, 4, 5}, - wantedResult: 0, - wantedErr: merrors.ErrInvalidSegmentData, - }, + //{ + // name: "wrong ec segment data length", + // req1: dispatchSegmentMap(), + // req2: ptypes.RedundancyType_REDUNDANCY_TYPE_EC_TYPE_UNSPECIFIED, + // req3: spList, + // req4: []uint32{0, 1, 2, 3, 4, 5}, + // wantedResult: 1, + // wantedErr: merrors.ErrInvalidECData, + //}, + //{ + // name: "wrong replica/inline segment data length", + // req1: dispatchPieceMap(), + // req2: ptypes.RedundancyType_REDUNDANCY_TYPE_REPLICA_TYPE, + // req3: spList, + // req4: []uint32{0, 1, 2, 3, 4, 5}, + // wantedResult: 1, + // wantedErr: merrors.ErrInvalidSegmentData, + //}, } node := setup(t) @@ -367,7 +367,7 @@ func TestSyncPieceSuccess(t *testing.T) { "123456_s4_p0": []byte("test5"), "123456_s5_p0": []byte("test6"), } - resp, err := node.SyncPiece(context.TODO(), sInfo, data, "test_traceID") + resp, err := node.syncPiece(context.TODO(), sInfo, data, "test_traceID") assert.Equal(t, err, nil) assert.Equal(t, resp.GetTraceId(), "test_traceID") assert.Equal(t, resp.GetSecondarySpInfo().GetPieceIdx(), uint32(1)) diff --git a/service/syncer/syncer_service.go b/service/syncer/syncer_service.go index d2cb34664..11f3f97a4 100644 --- a/service/syncer/syncer_service.go +++ b/service/syncer/syncer_service.go @@ -46,7 +46,6 @@ func (s *Syncer) SyncPiece(stream service.SyncerService_SyncPieceServer) error { sealInfo := generateSealInfo(spID, integrityMeta) integrityMeta.IntegrityHash = sealInfo.GetIntegrityHash() if err := s.setIntegrityMeta(s.metaDB, integrityMeta); err != nil { - log.Errorw("setIntegrityMeta error", "error", err) return err } return stream.SendAndClose(&service.SyncerServiceSyncPieceResponse{ @@ -63,7 +62,7 @@ func (s *Syncer) SyncPiece(stream service.SyncerService_SyncPieceServer) error { return err } spID = req.GetSyncerInfo().GetStorageProviderId() - integrityMeta, key, value, err = s.gatherPieceData(req) + integrityMeta, key, value, err = s.handlePieceData(req) if err != nil { return err } @@ -99,7 +98,7 @@ func generateSealInfo(spID string, integrityMeta *metadb.IntegrityMeta) *service return resp } -func (s *Syncer) gatherPieceData(req *service.SyncerServiceSyncPieceRequest) (*metadb.IntegrityMeta, string, []byte, error) { +func (s *Syncer) handlePieceData(req *service.SyncerServiceSyncPieceRequest) (*metadb.IntegrityMeta, string, []byte, error) { if len(req.GetPieceData()) != 1 { return nil, "", nil, errors.New("the length of piece data map is not equal to 1") }