@@ -71,7 +71,7 @@ type diskQueue struct {
71
71
// instantiation time metadata
72
72
name string
73
73
dataPath string
74
- maxBytesDiskSpace int64
74
+ maxBytesDiskSize int64
75
75
maxBytesPerFile int64 // cannot change once created
76
76
maxBytesPerFileRead int64
77
77
minMsgSize int32
@@ -106,7 +106,7 @@ type diskQueue struct {
106
106
logf AppLogFunc
107
107
108
108
// disk limit implementation flag
109
- diskLimitFeatIsOn bool
109
+ enableDiskLimitation bool
110
110
}
111
111
112
112
// New instantiates an instance of diskQueue, retrieving metadata
@@ -115,43 +115,43 @@ func New(name string, dataPath string, maxBytesPerFile int64,
115
115
minMsgSize int32 , maxMsgSize int32 ,
116
116
syncEvery int64 , syncTimeout time.Duration , logf AppLogFunc ) Interface {
117
117
118
- return NewWithDiskSpace (name , dataPath ,
118
+ return NewWithDiskSize (name , dataPath ,
119
119
0 , maxBytesPerFile ,
120
120
minMsgSize , maxMsgSize ,
121
121
syncEvery , syncTimeout , logf )
122
122
}
123
123
124
- // Another constructor that allows users to use Disk Space Limit feature
125
- // If user is not using Disk Space Limit feature, maxBytesDiskSpace will
124
+ // Another constructor that allows users to use Disk Size Limit feature
125
+ // If user is not using Disk Size Limit feature, maxBytesDiskSize will
126
126
// be 0
127
- func NewWithDiskSpace (name string , dataPath string ,
128
- maxBytesDiskSpace int64 , maxBytesPerFile int64 ,
127
+ func NewWithDiskSize (name string , dataPath string ,
128
+ maxBytesDiskSize int64 , maxBytesPerFile int64 ,
129
129
minMsgSize int32 , maxMsgSize int32 ,
130
130
syncEvery int64 , syncTimeout time.Duration , logf AppLogFunc ) Interface {
131
- diskLimitFeatIsOn := true
132
- if maxBytesDiskSpace <= 0 {
133
- maxBytesDiskSpace = 0
134
- diskLimitFeatIsOn = false
131
+ enableDiskLimitation := true
132
+ if maxBytesDiskSize <= 0 {
133
+ maxBytesDiskSize = 0
134
+ enableDiskLimitation = false
135
135
}
136
136
d := diskQueue {
137
- name : name ,
138
- dataPath : dataPath ,
139
- maxBytesDiskSpace : maxBytesDiskSpace ,
140
- maxBytesPerFile : maxBytesPerFile ,
141
- minMsgSize : minMsgSize ,
142
- maxMsgSize : maxMsgSize ,
143
- readChan : make (chan []byte ),
144
- depthChan : make (chan int64 ),
145
- writeChan : make (chan []byte ),
146
- writeResponseChan : make (chan error ),
147
- emptyChan : make (chan int ),
148
- emptyResponseChan : make (chan error ),
149
- exitChan : make (chan int ),
150
- exitSyncChan : make (chan int ),
151
- syncEvery : syncEvery ,
152
- syncTimeout : syncTimeout ,
153
- logf : logf ,
154
- diskLimitFeatIsOn : diskLimitFeatIsOn ,
137
+ name : name ,
138
+ dataPath : dataPath ,
139
+ maxBytesDiskSize : maxBytesDiskSize ,
140
+ maxBytesPerFile : maxBytesPerFile ,
141
+ minMsgSize : minMsgSize ,
142
+ maxMsgSize : maxMsgSize ,
143
+ readChan : make (chan []byte ),
144
+ depthChan : make (chan int64 ),
145
+ writeChan : make (chan []byte ),
146
+ writeResponseChan : make (chan error ),
147
+ emptyChan : make (chan int ),
148
+ emptyResponseChan : make (chan error ),
149
+ exitChan : make (chan int ),
150
+ exitSyncChan : make (chan int ),
151
+ syncEvery : syncEvery ,
152
+ syncTimeout : syncTimeout ,
153
+ logf : logf ,
154
+ enableDiskLimitation : enableDiskLimitation ,
155
155
}
156
156
157
157
d .start ()
@@ -335,7 +335,7 @@ func (d *diskQueue) readOne() ([]byte, error) {
335
335
stat , err := d .readFile .Stat ()
336
336
if err == nil {
337
337
d .maxBytesPerFileRead = stat .Size ()
338
- if d .diskLimitFeatIsOn {
338
+ if d .enableDiskLimitation {
339
339
// last 8 bytes are reserved for the number of messages in this file
340
340
d .maxBytesPerFileRead -= 8
341
341
}
@@ -437,7 +437,7 @@ func (d *diskQueue) writeOne(data []byte) error {
437
437
totalBytes := int64 (4 + dataLen )
438
438
439
439
// check if we reached the file size limit with this message
440
- if d .diskLimitFeatIsOn && d .writePos + totalBytes + 8 >= d .maxBytesPerFile {
440
+ if d .enableDiskLimitation && d .writePos + totalBytes + 8 >= d .maxBytesPerFile {
441
441
// write number of messages in binary to file
442
442
err = binary .Write (& d .writeBuf , binary .BigEndian , d .writeMessages + 1 )
443
443
if err != nil {
@@ -458,7 +458,7 @@ func (d *diskQueue) writeOne(data []byte) error {
458
458
459
459
fileSize := d .writePos
460
460
461
- if d .diskLimitFeatIsOn {
461
+ if d .enableDiskLimitation {
462
462
// save space for the number of messages in this file
463
463
fileSize += 8
464
464
d .writeMessages += 1
@@ -520,8 +520,8 @@ func (d *diskQueue) retrieveMetaData() error {
520
520
}
521
521
defer f .Close ()
522
522
523
- // if user is using disk space limit feature
524
- if d .diskLimitFeatIsOn {
523
+ // if user is using disk size limit feature
524
+ if d .enableDiskLimitation {
525
525
_ , err = fmt .Fscanf (f , "%d\n %d,%d,%d\n %d,%d,%d\n " ,
526
526
& d .depth ,
527
527
& d .readFileNum , & d .readMessages , & d .readPos ,
@@ -557,8 +557,8 @@ func (d *diskQueue) persistMetaData() error {
557
557
return err
558
558
}
559
559
560
- // if user is using disk space limit feature
561
- if d .diskLimitFeatIsOn {
560
+ // if user is using disk size limit feature
561
+ if d .enableDiskLimitation {
562
562
_ , err = fmt .Fprintf (f , "%d\n %d,%d,%d\n %d,%d,%d\n " ,
563
563
d .depth ,
564
564
d .readFileNum , d .readMessages , d .readPos ,
0 commit comments