Skip to content

Commit e6d4700

Browse files
committed
change StartWriteBatch
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent 2fad4d7 commit e6d4700

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

shim/handler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -544,17 +544,17 @@ func (h *Handler) sendBatch(channelID string, txid string) error {
544544
return nil
545545
}
546546

547-
func (h *Handler) handleStartWriteBatch(channelID string, txID string) error {
547+
func (h *Handler) handleStartWriteBatch(channelID string, txID string) (isSupportWriteBatch bool) {
548548
if !h.usePeerWriteBatch {
549-
return errors.New("peer does not support write batch")
549+
return false
550550
}
551551

552552
txCtxID := transactionContextID(channelID, txID)
553553
h.startWriteBatchMutex.Lock()
554554
defer h.startWriteBatchMutex.Unlock()
555555

556556
h.startWriteBatch[txCtxID] = true
557-
return nil
557+
return true
558558
}
559559

560560
func (h *Handler) handleFinishWriteBatch(channelID string, txID string) error {

shim/interfaces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,9 @@ type ChaincodeStubInterface interface {
374374
// StartWriteBatch enables a mode where all changes are not immediately forwarded to the feast,
375375
// but accumulate in the cache. The cache is sent in large batches either at the end of transaction
376376
// execution or after the FinishWriteBatch call.
377+
// StartWriteBatch returns a bool indication that the peer supports or does not support writing by batches.
377378
// IMPORTANT: in this mode, the expected order of transaction execution and expected errors can be changed.
378-
StartWriteBatch() error
379+
StartWriteBatch() (isSupportWriteBatch bool)
379380

380381
// FinishWriteBatch sends accumulated changes in large batches to the peer
381382
// if StartWriteBatch has been called before it.

shim/stub.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ func (s *ChaincodeStub) GetQueryResultWithPagination(query string, pageSize int3
582582
// --------- Batch State functions ----------
583583

584584
// StartWriteBatch documentation can be found in interfaces.go
585-
func (s *ChaincodeStub) StartWriteBatch() error {
585+
func (s *ChaincodeStub) StartWriteBatch() (isSupportWriteBatch bool) {
586586
return s.handler.handleStartWriteBatch(s.ChannelID, s.TxID)
587587
}
588588

shim/stub_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ func TestChaincodeStubHandlers(t *testing.T) {
321321
resType: peer.ChaincodeMessage_RESPONSE,
322322
payload: []byte("myvalue"),
323323
testFunc: func(s *ChaincodeStub, h *Handler, t *testing.T, payload []byte) {
324-
s.StartWriteBatch() //nolint:errcheck
324+
s.StartWriteBatch()
325325
err := s.PutState("key", payload)
326326
assert.NoError(t, err)
327327
err = s.PutPrivateData("col", "key", payload)
@@ -339,8 +339,8 @@ func TestChaincodeStubHandlers(t *testing.T) {
339339
err = s.FinishWriteBatch()
340340
assert.NoError(t, err)
341341

342-
s.StartWriteBatch() //nolint:errcheck
343-
s.StartWriteBatch() //nolint:errcheck
342+
s.StartWriteBatch()
343+
s.StartWriteBatch()
344344
err = s.PutState("key", payload)
345345
assert.NoError(t, err)
346346
err = s.PutPrivateData("col", "key", payload)
@@ -609,8 +609,8 @@ func TestChaincodeStubHandlers(t *testing.T) {
609609
resp := s.InvokeChaincode("cc", [][]byte{}, "channel")
610610
assert.Equal(t, payload, resp.GetPayload())
611611

612-
s.StartWriteBatch() //nolint:errcheck
613-
s.StartWriteBatch() //nolint:errcheck
612+
s.StartWriteBatch()
613+
s.StartWriteBatch()
614614
err = s.PutState("key", payload)
615615
assert.NoError(t, err)
616616
err = s.FinishWriteBatch()

0 commit comments

Comments
 (0)