Skip to content

Commit

Permalink
Changing filestore.offsets from map[int]msgDef to sync.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
SNORRIS721 committed May 8, 2024
1 parent cf3fb98 commit 668e1f4
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions store/file/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"

"github.com/pkg/errors"
Expand All @@ -42,7 +43,7 @@ type fileStoreFactory struct {
type fileStore struct {
sessionID quickfix.SessionID
cache quickfix.MessageStore
offsets map[int]msgDef
offsets sync.Map
bodyFname string
headerFname string
sessionFname string
Expand Down Expand Up @@ -106,7 +107,7 @@ func newFileStore(sessionID quickfix.SessionID, dirname string, fileSync bool) (
store := &fileStore{
sessionID: sessionID,
cache: memStore,
offsets: make(map[int]msgDef),
offsets: sync.Map{},
bodyFname: path.Join(dirname, fmt.Sprintf("%s.%s", sessionPrefix, "body")),
headerFname: path.Join(dirname, fmt.Sprintf("%s.%s", sessionPrefix, "header")),
sessionFname: path.Join(dirname, fmt.Sprintf("%s.%s", sessionPrefix, "session")),
Expand Down Expand Up @@ -206,7 +207,7 @@ func (store *fileStore) populateCache() (creationTimePopulated bool, err error)
if cnt, err := fmt.Fscanf(tmpHeaderFile, "%d,%d,%d\n", &seqNum, &offset, &size); err != nil || cnt != 3 {
break
}
store.offsets[seqNum] = msgDef{offset: offset, size: size}
store.offsets.Store(seqNum, msgDef{offset: offset, size: size})
}
}

Expand Down Expand Up @@ -347,7 +348,7 @@ func (store *fileStore) SaveMessage(seqNum int, msg []byte) error {
}
}

store.offsets[seqNum] = msgDef{offset: offset, size: len(msg)}
store.offsets.Store(seqNum, msgDef{offset: offset, size: len(msg)})
return nil
}

Expand All @@ -360,7 +361,7 @@ func (store *fileStore) SaveMessageAndIncrNextSenderMsgSeqNum(seqNum int, msg []
}

func (store *fileStore) getMessage(seqNum int) (msg []byte, found bool, err error) {
msgInfo, found := store.offsets[seqNum]
msgInfo, found := store.offsets.Load(seqNum)
if !found {
return
}
Expand Down

0 comments on commit 668e1f4

Please sign in to comment.