Skip to content

Commit 384513e

Browse files
pfi79denyeart
authored andcommitted
remove ResetWriteBatch
Signed-off-by: Fedor Partanskiy <[email protected]>
1 parent 5a88977 commit 384513e

File tree

4 files changed

+11
-33
lines changed

4 files changed

+11
-33
lines changed

shim/handler.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -544,35 +544,22 @@ 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) {
548548
if !h.usePeerWriteBatch {
549-
return errors.New("peer does not support write batch")
549+
return
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
558557
}
559558

560559
func (h *Handler) handleFinishWriteBatch(channelID string, txID string) error {
561560
return h.sendBatch(channelID, txID)
562561
}
563562

564-
func (h *Handler) handleResetWriteBatch(channelID string, txID string) {
565-
if !h.usePeerWriteBatch || !h.isStartWriteBatch(channelID, txID) {
566-
return
567-
}
568-
569-
txCtxID := transactionContextID(channelID, txID)
570-
571-
h.batchMutex.Lock()
572-
delete(h.batch, txCtxID)
573-
h.batchMutex.Unlock()
574-
}
575-
576563
func (h *Handler) isStartWriteBatch(channelID string, txID string) bool {
577564
txCtxID := transactionContextID(channelID, txID)
578565
h.startWriteBatchMutex.RLock()

shim/interfaces.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -371,19 +371,15 @@ type ChaincodeStubInterface interface {
371371
// The marshaled ChaincodeEvent will be available in the transaction's ChaincodeAction.events field.
372372
SetEvent(name string, payload []byte) error
373373

374-
// StartWriteBatch enables a mode where all changes are not immediately forwarded to the feast,
374+
// StartWriteBatch enables a mode where all changes are not immediately forwarded to the peer,
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.
377377
// IMPORTANT: in this mode, the expected order of transaction execution and expected errors can be changed.
378-
StartWriteBatch() error
378+
StartWriteBatch()
379379

380380
// FinishWriteBatch sends accumulated changes in large batches to the peer
381381
// if StartWriteBatch has been called before it.
382382
FinishWriteBatch() error
383-
384-
// ResetWriteBatch clears the accumulated segment of changes, but does not cancel the batches writing mode.
385-
// After ResetWriteBatch, the changes will be written to the batches
386-
ResetWriteBatch()
387383
}
388384

389385
// CommonIteratorInterface allows a chaincode to check whether any more result

shim/stub.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -582,20 +582,15 @@ 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 {
586-
return s.handler.handleStartWriteBatch(s.ChannelID, s.TxID)
585+
func (s *ChaincodeStub) StartWriteBatch() {
586+
s.handler.handleStartWriteBatch(s.ChannelID, s.TxID)
587587
}
588588

589589
// FinishWriteBatch documentation can be found in interfaces.go
590590
func (s *ChaincodeStub) FinishWriteBatch() error {
591591
return s.handler.handleFinishWriteBatch(s.ChannelID, s.TxID)
592592
}
593593

594-
// ResetWriteBatch documentation can be found in interfaces.go
595-
func (s *ChaincodeStub) ResetWriteBatch() {
596-
s.handler.handleResetWriteBatch(s.ChannelID, s.TxID)
597-
}
598-
599594
// Next ...
600595
func (iter *StateQueryIterator) Next() (*queryresult.KV, error) {
601596
result, err := iter.nextResult(StateQueryResult)

shim/stub_test.go

+5-5
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)