@@ -19,17 +19,18 @@ package couchdbtxmgmt
19
19
import (
20
20
"bytes"
21
21
"encoding/json"
22
- "errors"
23
22
"sync"
24
23
25
24
"github.com/golang/protobuf/proto"
26
25
"github.com/hyperledger/fabric/core/ledger"
27
- "github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt"
28
26
"github.com/hyperledger/fabric/core/ledger/util/couchdb"
29
27
"github.com/hyperledger/fabric/core/ledger/util/db"
30
28
"github.com/op/go-logging"
31
29
32
- "github.com/hyperledger/fabric/core/ledger/kvledger/version"
30
+ "fmt"
31
+
32
+ "github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/rwset"
33
+ "github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt/version"
33
34
"github.com/hyperledger/fabric/protos/common"
34
35
pb "github.com/hyperledger/fabric/protos/peer"
35
36
putils "github.com/hyperledger/fabric/protos/utils"
@@ -153,7 +154,7 @@ func (txmgr *CouchDBTxMgr) ValidateAndPrepare(block *common.Block, doMVCCValidat
153
154
}
154
155
155
156
//preparation for extracting RWSet from transaction
156
- txRWSet := & txmgmt .TxReadWriteSet {}
157
+ txRWSet := & rwset .TxReadWriteSet {}
157
158
158
159
// Get the Result from the Action
159
160
// and then Unmarshal it into a TxReadWriteSet using custom unmarshalling
@@ -201,7 +202,7 @@ func (txmgr *CouchDBTxMgr) Shutdown() {
201
202
txmgr .db .Close ()
202
203
}
203
204
204
- func (txmgr * CouchDBTxMgr ) validateTx (txRWSet * txmgmt .TxReadWriteSet ) (bool , error ) {
205
+ func (txmgr * CouchDBTxMgr ) validateTx (txRWSet * rwset .TxReadWriteSet ) (bool , error ) {
205
206
206
207
var err error
207
208
var currentVersion * version.Height
@@ -226,7 +227,7 @@ func (txmgr *CouchDBTxMgr) validateTx(txRWSet *txmgmt.TxReadWriteSet) (bool, err
226
227
return true , nil
227
228
}
228
229
229
- func (txmgr * CouchDBTxMgr ) addWriteSetToBatch (txRWSet * txmgmt .TxReadWriteSet , txHeight * version.Height ) error {
230
+ func (txmgr * CouchDBTxMgr ) addWriteSetToBatch (txRWSet * rwset .TxReadWriteSet , txHeight * version.Height ) error {
230
231
if txmgr .updateSet == nil {
231
232
txmgr .updateSet = newUpdateSet ()
232
233
}
@@ -259,7 +260,7 @@ func (txmgr *CouchDBTxMgr) Commit() error {
259
260
// SaveDoc using couchdb client and use JSON format
260
261
rev , err := txmgr .couchDB .SaveDoc (k , "" , v .value , nil )
261
262
if err != nil {
262
- logger .Errorf ("===COUCHDB=== Error during Commit(): %s\n " , err . Error () )
263
+ logger .Debugf ("===COUCHDB=== Error during Commit(): %s\n " , err )
263
264
return err
264
265
}
265
266
if rev != "" {
@@ -280,7 +281,7 @@ func (txmgr *CouchDBTxMgr) Commit() error {
280
281
// SaveDoc using couchdb client and use attachment
281
282
rev , err := txmgr .couchDB .SaveDoc (k , "" , nil , attachments )
282
283
if err != nil {
283
- logger .Errorf ("===COUCHDB=== Error during Commit(): %s\n " , err . Error () )
284
+ logger .Debugf ("===COUCHDB=== Error during Commit(): %s\n " , err )
284
285
return err
285
286
}
286
287
if rev != "" {
@@ -294,7 +295,7 @@ func (txmgr *CouchDBTxMgr) Commit() error {
294
295
// Record a savepoint
295
296
err := txmgr .recordSavepoint ()
296
297
if err != nil {
297
- logger .Errorf ("===COUCHDB=== Error during recordSavepoint: %s\n " , err . Error () )
298
+ logger .Debugf ("===COUCHDB=== Error during recordSavepoint: %s\n " , err )
298
299
return err
299
300
}
300
301
@@ -312,37 +313,37 @@ func (txmgr *CouchDBTxMgr) recordSavepoint() error {
312
313
// ensure full commit to flush all changes until now to disk
313
314
dbResponse , err := txmgr .couchDB .EnsureFullCommit ()
314
315
if err != nil || dbResponse .Ok != true {
315
- logger .Errorf ("====COUCHDB==== Failed to perform full commit\n " )
316
- return errors . New ("Failed to perform full commit" )
316
+ logger .Debugf ("====COUCHDB==== Failed to perform full commit\n " )
317
+ return fmt . Errorf ("Failed to perform full commit. Err: %s" , err )
317
318
}
318
319
319
320
// construct savepoint document
320
321
// UpdateSeq would be useful if we want to get all db changes since a logical savepoint
321
322
dbInfo , _ , err := txmgr .couchDB .GetDatabaseInfo ()
322
323
if err != nil {
323
- logger .Errorf ("====COUCHDB==== Failed to get DB info %s\n " , err . Error () )
324
+ logger .Debugf ("====COUCHDB==== Failed to get DB info %s\n " , err )
324
325
return err
325
326
}
326
327
savepointDoc .BlockNum = txmgr .blockNum
327
328
savepointDoc .UpdateSeq = dbInfo .UpdateSeq
328
329
329
330
savepointDocJSON , err := json .Marshal (savepointDoc )
330
331
if err != nil {
331
- logger .Errorf ("====COUCHDB==== Failed to create savepoint data %s\n " , err . Error () )
332
+ logger .Debugf ("====COUCHDB==== Failed to create savepoint data %s\n " , err )
332
333
return err
333
334
}
334
335
335
336
// SaveDoc using couchdb client and use JSON format
336
337
_ , err = txmgr .couchDB .SaveDoc (savepointDocID , "" , savepointDocJSON , nil )
337
338
if err != nil {
338
- logger .Errorf ("====CouchDB==== Failed to save the savepoint to DB %s\n " , err . Error () )
339
+ logger .Debugf ("====CouchDB==== Failed to save the savepoint to DB %s\n " , err )
339
340
}
340
341
341
342
// ensure full commit to flush savepoint to disk
342
343
dbResponse , err = txmgr .couchDB .EnsureFullCommit ()
343
344
if err != nil || dbResponse .Ok != true {
344
- logger .Errorf ("====COUCHDB==== Failed to perform full commit\n " )
345
- return errors . New ("Failed to perform full commit" )
345
+ logger .Debugf ("====COUCHDB==== Failed to perform full commit\n " )
346
+ return fmt . Errorf ("Failed to perform full commit. Err:%s" , err )
346
347
}
347
348
return nil
348
349
}
@@ -354,14 +355,14 @@ func (txmgr *CouchDBTxMgr) GetBlockNumFromSavepoint() (uint64, error) {
354
355
savepointJSON , _ , err := txmgr .couchDB .ReadDoc (savepointDocID )
355
356
if err != nil {
356
357
// TODO: differentiate between 404 and some other error code
357
- logger .Errorf ("====COUCHDB==== Failed to read savepoint data %s\n " , err . Error () )
358
+ logger .Debugf ("====COUCHDB==== Failed to read savepoint data %s\n " , err )
358
359
return 0 , err
359
360
}
360
361
361
362
savepointDoc := & couchSavepointData {}
362
363
err = json .Unmarshal (savepointJSON , & savepointDoc )
363
364
if err != nil {
364
- logger .Errorf ("====COUCHDB==== Failed to read savepoint data %s\n " , err . Error () )
365
+ logger .Debugf ("====COUCHDB==== Failed to read savepoint data %s\n " , err )
365
366
return 0 , err
366
367
}
367
368
0 commit comments