@@ -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 {
4243type 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,10 +361,14 @@ func (store *fileStore) SaveMessageAndIncrNextSenderMsgSeqNum(seqNum int, msg []
360361}
361362
362363func (store * fileStore ) getMessage (seqNum int ) (msg []byte , found bool , err error ) {
363- msgInfo , found := store .offsets [ seqNum ]
364+ msgInfoTemp , found := store .offsets . Load ( seqNum )
364365 if ! found {
365366 return
366367 }
368+ msgInfo , ok := msgInfoTemp .(msgDef )
369+ if ! ok {
370+ return nil , true , fmt .Errorf ("incorrect msgInfo type while reading file: %s" , store .bodyFname )
371+ }
367372
368373 msg = make ([]byte , msgInfo .size )
369374 if _ , err = store .bodyFile .ReadAt (msg , msgInfo .offset ); err != nil {
0 commit comments