Skip to content

Commit 668e1f4

Browse files
committed
Changing filestore.offsets from map[int]msgDef to sync.Map
1 parent cf3fb98 commit 668e1f4

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

store/file/filestore.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"path"
2323
"strconv"
2424
"strings"
25+
"sync"
2526
"time"
2627

2728
"github.com/pkg/errors"
@@ -42,7 +43,7 @@ type fileStoreFactory struct {
4243
type fileStore struct {
4344
sessionID quickfix.SessionID
4445
cache quickfix.MessageStore
45-
offsets map[int]msgDef
46+
offsets sync.Map
4647
bodyFname string
4748
headerFname string
4849
sessionFname string
@@ -106,7 +107,7 @@ func newFileStore(sessionID quickfix.SessionID, dirname string, fileSync bool) (
106107
store := &fileStore{
107108
sessionID: sessionID,
108109
cache: memStore,
109-
offsets: make(map[int]msgDef),
110+
offsets: sync.Map{},
110111
bodyFname: path.Join(dirname, fmt.Sprintf("%s.%s", sessionPrefix, "body")),
111112
headerFname: path.Join(dirname, fmt.Sprintf("%s.%s", sessionPrefix, "header")),
112113
sessionFname: path.Join(dirname, fmt.Sprintf("%s.%s", sessionPrefix, "session")),
@@ -206,7 +207,7 @@ func (store *fileStore) populateCache() (creationTimePopulated bool, err error)
206207
if cnt, err := fmt.Fscanf(tmpHeaderFile, "%d,%d,%d\n", &seqNum, &offset, &size); err != nil || cnt != 3 {
207208
break
208209
}
209-
store.offsets[seqNum] = msgDef{offset: offset, size: size}
210+
store.offsets.Store(seqNum, msgDef{offset: offset, size: size})
210211
}
211212
}
212213

@@ -347,7 +348,7 @@ func (store *fileStore) SaveMessage(seqNum int, msg []byte) error {
347348
}
348349
}
349350

350-
store.offsets[seqNum] = msgDef{offset: offset, size: len(msg)}
351+
store.offsets.Store(seqNum, msgDef{offset: offset, size: len(msg)})
351352
return nil
352353
}
353354

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

362363
func (store *fileStore) getMessage(seqNum int) (msg []byte, found bool, err error) {
363-
msgInfo, found := store.offsets[seqNum]
364+
msgInfo, found := store.offsets.Load(seqNum)
364365
if !found {
365366
return
366367
}

0 commit comments

Comments
 (0)