The slowdown was due to trying top expire messages without a proper index info.

So now we read and encrypt index info in place as well.

Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
Derek Collison
2021-08-25 13:22:18 -07:00
parent 4a6f1b4819
commit ba4937f04e
2 changed files with 14 additions and 8 deletions

View File

@@ -557,8 +557,15 @@ func (fs *fileStore) recoverMsgBlock(fi os.FileInfo, index uint64) (*msgBlock, e
if err := ioutil.WriteFile(mb.mfn, buf, defaultFilePerms); err != nil {
return nil, err
}
// Remove the index file here since it will be in plaintext as well so we just rebuild.
os.Remove(mb.ifn)
if buf, err = ioutil.ReadFile(mb.ifn); err == nil && len(buf) > 0 {
if err := checkHeader(buf); err != nil {
return nil, err
}
buf = mb.aek.Seal(buf[:0], mb.nonce, buf, nil)
if err := ioutil.WriteFile(mb.ifn, buf, defaultFilePerms); err != nil {
return nil, err
}
}
}
// Open up the message file, but we will try to recover from the index file.

View File

@@ -2974,10 +2974,7 @@ func TestNoRaceJetStreamFileStoreCompaction(t *testing.T) {
}
}
func TestNoRaceJetStreamEncryptionEnabled(t *testing.T) {
// Disable for now.
skip(t)
func TestNoRaceJetStreamEncryptionEnabledOnRestartWithExpire(t *testing.T) {
conf := createConfFile(t, []byte(`
listen: 127.0.0.1:-1
jetstream: enabled
@@ -2996,9 +2993,12 @@ func TestNoRaceJetStreamEncryptionEnabled(t *testing.T) {
nc, js := jsClientConnect(t, s)
defer nc.Close()
toSend := 10_000
cfg := &nats.StreamConfig{
Name: "TEST",
Subjects: []string{"foo", "bar"},
MaxMsgs: int64(toSend),
}
if _, err := js.AddStream(cfg); err != nil {
t.Fatalf("Unexpected error: %v", err)
@@ -3006,7 +3006,6 @@ func TestNoRaceJetStreamEncryptionEnabled(t *testing.T) {
data := make([]byte, 4*1024) // 4K payload
rand.Read(data)
toSend := 100_000
for i := 0; i < toSend; i++ {
js.PublishAsync("foo", data)
@@ -3032,7 +3031,7 @@ func TestNoRaceJetStreamEncryptionEnabled(t *testing.T) {
defer removeFile(t, conf)
// Try to drain entropy to see if effects startup time.
drain := make([]byte, 128*1024*1024) // Pull 128Mb of crypto rand.
drain := make([]byte, 32*1024*1024) // Pull 32Mb of crypto rand.
crand.Read(drain)
start := time.Now()