(rs historyRecords)
| 704 | } |
| 705 | |
| 706 | func validateSequential(rs historyRecords) error { |
| 707 | sort.Stable(rs) |
| 708 | |
| 709 | type bucketAndKey struct { |
| 710 | bucket string |
| 711 | key string |
| 712 | } |
| 713 | lastWriteKeyValueMap := make(map[bucketAndKey]*historyRecord) |
| 714 | |
| 715 | for _, rec := range rs { |
| 716 | bk := bucketAndKey{ |
| 717 | bucket: rec.Bucket, |
| 718 | key: rec.Key, |
| 719 | } |
| 720 | if v, ok := lastWriteKeyValueMap[bk]; ok { |
| 721 | if rec.OperationType == Write { |
| 722 | v.Txid = rec.Txid |
| 723 | if rec.Key != noopTxKey { |
| 724 | v.Value = rec.Value |
| 725 | } |
| 726 | } else if rec.OperationType == Delete { |
| 727 | delete(lastWriteKeyValueMap, bk) |
| 728 | } else { |
| 729 | if !bytes.Equal(v.Value, rec.Value) { |
| 730 | return fmt.Errorf("readOperation[txid: %d, bucket: %s, key: %s] read %x, \nbut writer[txid: %d] wrote %x", |
| 731 | rec.Txid, rec.Bucket, rec.Key, rec.Value, v.Txid, v.Value) |
| 732 | } |
| 733 | } |
| 734 | } else { |
| 735 | if rec.OperationType == Write && rec.Key != noopTxKey { |
| 736 | lastWriteKeyValueMap[bk] = &historyRecord{ |
| 737 | OperationType: Write, |
| 738 | Bucket: rec.Bucket, |
| 739 | Key: rec.Key, |
| 740 | Value: rec.Value, |
| 741 | Txid: rec.Txid, |
| 742 | } |
| 743 | } else if rec.OperationType == Read { |
| 744 | if len(rec.Value) != 0 { |
| 745 | return fmt.Errorf("expected the first readOperation[txid: %d, bucket: %s, key: %s] read nil, \nbut got %x", |
| 746 | rec.Txid, rec.Bucket, rec.Key, rec.Value) |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
| 751 | |
| 752 | return nil |
| 753 | } |
| 754 | |
| 755 | /* |
| 756 | TestConcurrentRepeatableRead verifies repeatable read. The case |
no test coverage detected