@@ -19,9 +19,7 @@ const (
19
19
established state = "established" // connection established
20
20
ready state = "ready" // ready for requests
21
21
22
- defaultMaxSizeWriteBatch = 100
23
- prefixMetaDataWriteBatch = "m"
24
- prefixStateDataWriteBatch = "s"
22
+ defaultMaxSizeWriteBatch = 100
25
23
)
26
24
27
25
// PeerChaincodeStream is the common stream interface for Peer - chaincode communication.
@@ -426,7 +424,11 @@ func (h *Handler) handlePurgeState(collection string, key string, channelID stri
426
424
}
427
425
428
426
// handleWriteBatch communicates with the peer to write batch to state all changes information into the ledger.
429
- func (h * Handler ) handleWriteBatch (batch * peer.WriteBatchState , channelID string , txid string ) error {
427
+ func (h * Handler ) handleWriteBatch (writes []* peer.WriteRecord , channelID string , txid string ) error {
428
+ batch := & peer.WriteBatchState {
429
+ Rec : writes ,
430
+ }
431
+
430
432
// Construct payload for PUT_STATE_BATCH
431
433
payloadBytes := marshalOrPanic (batch )
432
434
@@ -453,21 +455,14 @@ func (h *Handler) handleWriteBatch(batch *peer.WriteBatchState, channelID string
453
455
}
454
456
455
457
func (h * Handler ) sendBatch (channelID string , txid string , writes []* peer.WriteRecord ) error {
456
- batch := & peer.WriteBatchState {}
457
- for _ , kv := range writes {
458
- batch .Rec = append (batch .Rec , kv )
459
- if len (batch .Rec ) >= int (h .maxSizeWriteBatch ) {
460
- err := h .handleWriteBatch (batch , channelID , txid )
461
- if err != nil {
462
- return fmt .Errorf ("failed send batch: %s" , err )
463
- }
464
- batch .Rec = batch .Rec [:0 ]
458
+ for ; len (writes ) > int (h .maxSizeWriteBatch ); writes = writes [h .maxSizeWriteBatch :] {
459
+ if err := h .handleWriteBatch (writes [:h .maxSizeWriteBatch ], channelID , txid ); err != nil {
460
+ return fmt .Errorf ("failed send batch: %s" , err )
465
461
}
466
462
}
467
463
468
- if len (batch .Rec ) != 0 {
469
- err := h .handleWriteBatch (batch , channelID , txid )
470
- if err != nil {
464
+ if len (writes ) > 0 {
465
+ if err := h .handleWriteBatch (writes , channelID , txid ); err != nil {
471
466
return fmt .Errorf ("failed send batch: %s" , err )
472
467
}
473
468
}
0 commit comments