@@ -3785,6 +3785,10 @@ func (mb *msgBlock) setupWriteCache(buf []byte) {
3785
3785
}
3786
3786
3787
3787
// Setup simple cache.
3788
+ if buf == nil {
3789
+ bsz := int (mb .fs .fcfg .BlockSize )
3790
+ buf = getMsgBlockBuf (bsz )
3791
+ }
3788
3792
mb .cache = & cache {buf : buf }
3789
3793
// Make sure we set the proper cache offset if we have existing data.
3790
3794
var fi os.FileInfo
@@ -5714,23 +5718,23 @@ func (mb *msgBlock) writeMsgRecord(rl, seq uint64, subj string, mhdr, msg []byte
5714
5718
// With headers, high bit on total length will be set.
5715
5719
// total_len(4) sequence(8) timestamp(8) subj_len(2) subj hdr_len(4) hdr msg hash(8)
5716
5720
5717
- // First write header, etc.
5718
5721
var le = binary .LittleEndian
5719
- var hdr [msgHdrSize ]byte
5720
5722
5721
5723
l := uint32 (rl )
5722
5724
hasHeaders := len (mhdr ) > 0
5723
5725
if hasHeaders {
5724
5726
l |= hbit
5725
5727
}
5726
5728
5729
+ // Reserve space for the header on the underlying buffer.
5730
+ mb .cache .buf = append (mb .cache .buf , make ([]byte , msgHdrSize )... )
5731
+ hdr := mb .cache .buf [len (mb .cache .buf )- msgHdrSize : len (mb .cache .buf )]
5727
5732
le .PutUint32 (hdr [0 :], l )
5728
5733
le .PutUint64 (hdr [4 :], seq )
5729
5734
le .PutUint64 (hdr [12 :], uint64 (ts ))
5730
5735
le .PutUint16 (hdr [20 :], uint16 (len (subj )))
5731
5736
5732
5737
// Now write to underlying buffer.
5733
- mb .cache .buf = append (mb .cache .buf , hdr [:]... )
5734
5738
mb .cache .buf = append (mb .cache .buf , subj ... )
5735
5739
5736
5740
if hasHeaders {
@@ -5744,13 +5748,12 @@ func (mb *msgBlock) writeMsgRecord(rl, seq uint64, subj string, mhdr, msg []byte
5744
5748
// Calculate hash.
5745
5749
mb .hh .Reset ()
5746
5750
mb .hh .Write (hdr [4 :20 ])
5747
- mb .hh .Write ([] byte (subj ))
5751
+ mb .hh .Write (stringToBytes (subj ))
5748
5752
if hasHeaders {
5749
5753
mb .hh .Write (mhdr )
5750
5754
}
5751
5755
mb .hh .Write (msg )
5752
- checksum := mb .hh .Sum (nil )
5753
- // Grab last checksum
5756
+ checksum := mb .hh .Sum (mb .lchk [:0 :highwayhash .Size64 ])
5754
5757
copy (mb .lchk [0 :], checksum )
5755
5758
5756
5759
// Update write through cache.
0 commit comments