PurgeByTxids removes private write sets of a given set of transactions from the transient store. PurgeByTxids() is expected to be called by coordinator after committing a block to ledger.
(txids []string)
| 383 | // transient store. PurgeByTxids() is expected to be called by coordinator after |
| 384 | // committing a block to ledger. |
| 385 | func (s *Store) PurgeByTxids(txids []string) error { |
| 386 | logger.Debug("Purging private data from transient store for committed txids") |
| 387 | |
| 388 | dbBatch := s.db.NewUpdateBatch() |
| 389 | |
| 390 | for _, txid := range txids { |
| 391 | // Construct startKey and endKey to do an range query |
| 392 | startKey := createPurgeIndexByTxidRangeStartKey(txid) |
| 393 | endKey := createPurgeIndexByTxidRangeEndKey(txid) |
| 394 | |
| 395 | iter, err := s.db.GetIterator(startKey, endKey) |
| 396 | if err != nil { |
| 397 | return err |
| 398 | } |
| 399 | |
| 400 | // Get all txid and uuid from above result and remove it from transient store (both |
| 401 | // write set and the corresponding indexes. |
| 402 | for iter.Next() { |
| 403 | // For each entry, remove the private read-write set and corresponding indexes |
| 404 | |
| 405 | // Remove private write set |
| 406 | compositeKeyPurgeIndexByTxid := iter.Key() |
| 407 | // Note: We can create compositeKeyPvtRWSet by just replacing the prefix of compositeKeyPurgeIndexByTxid |
| 408 | // with prwsetPrefix. For code readability and to be expressive, we split and create again. |
| 409 | uuid, blockHeight, err := splitCompositeKeyOfPurgeIndexByTxid(compositeKeyPurgeIndexByTxid) |
| 410 | if err != nil { |
| 411 | return err |
| 412 | } |
| 413 | compositeKeyPvtRWSet := createCompositeKeyForPvtRWSet(txid, uuid, blockHeight) |
| 414 | dbBatch.Delete(compositeKeyPvtRWSet) |
| 415 | |
| 416 | // Remove purge index -- purgeIndexByHeight |
| 417 | compositeKeyPurgeIndexByHeight := createCompositeKeyForPurgeIndexByHeight(blockHeight, txid, uuid) |
| 418 | dbBatch.Delete(compositeKeyPurgeIndexByHeight) |
| 419 | |
| 420 | // Remove purge index -- purgeIndexByTxid |
| 421 | dbBatch.Delete(compositeKeyPurgeIndexByTxid) |
| 422 | } |
| 423 | iter.Release() |
| 424 | } |
| 425 | // If peer fails before/while writing the batch to golevelDB, these entries will be |
| 426 | // removed as per BTL policy later by PurgeBelowHeight() |
| 427 | return s.db.WriteBatch(dbBatch, true) |
| 428 | } |
| 429 | |
| 430 | // PurgeBelowHeight removes private write sets at block height lesser than |
| 431 | // a given maxBlockNumToRetain. In other words, Purge only retains private write sets |