Skip to content

Commit e9b23ac

Browse files
committed
Update variable names.
1 parent 30c6ef6 commit e9b23ac

File tree

2 files changed

+40
-40
lines changed

2 files changed

+40
-40
lines changed

diskqueue.go

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ type diskQueue struct {
7171
// instantiation time metadata
7272
name string
7373
dataPath string
74-
maxBytesDiskSpace int64
74+
maxBytesDiskSize int64
7575
maxBytesPerFile int64 // cannot change once created
7676
maxBytesPerFileRead int64
7777
minMsgSize int32
@@ -106,7 +106,7 @@ type diskQueue struct {
106106
logf AppLogFunc
107107

108108
// disk limit implementation flag
109-
diskLimitFeatIsOn bool
109+
enableDiskLimitation bool
110110
}
111111

112112
// New instantiates an instance of diskQueue, retrieving metadata
@@ -115,43 +115,43 @@ func New(name string, dataPath string, maxBytesPerFile int64,
115115
minMsgSize int32, maxMsgSize int32,
116116
syncEvery int64, syncTimeout time.Duration, logf AppLogFunc) Interface {
117117

118-
return NewWithDiskSpace(name, dataPath,
118+
return NewWithDiskSize(name, dataPath,
119119
0, maxBytesPerFile,
120120
minMsgSize, maxMsgSize,
121121
syncEvery, syncTimeout, logf)
122122
}
123123

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
126126
// 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,
129129
minMsgSize int32, maxMsgSize int32,
130130
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
135135
}
136136
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,
155155
}
156156

157157
d.start()
@@ -335,7 +335,7 @@ func (d *diskQueue) readOne() ([]byte, error) {
335335
stat, err := d.readFile.Stat()
336336
if err == nil {
337337
d.maxBytesPerFileRead = stat.Size()
338-
if d.diskLimitFeatIsOn {
338+
if d.enableDiskLimitation {
339339
// last 8 bytes are reserved for the number of messages in this file
340340
d.maxBytesPerFileRead -= 8
341341
}
@@ -437,7 +437,7 @@ func (d *diskQueue) writeOne(data []byte) error {
437437
totalBytes := int64(4 + dataLen)
438438

439439
// 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 {
441441
// write number of messages in binary to file
442442
err = binary.Write(&d.writeBuf, binary.BigEndian, d.writeMessages+1)
443443
if err != nil {
@@ -458,7 +458,7 @@ func (d *diskQueue) writeOne(data []byte) error {
458458

459459
fileSize := d.writePos
460460

461-
if d.diskLimitFeatIsOn {
461+
if d.enableDiskLimitation {
462462
// save space for the number of messages in this file
463463
fileSize += 8
464464
d.writeMessages += 1
@@ -520,8 +520,8 @@ func (d *diskQueue) retrieveMetaData() error {
520520
}
521521
defer f.Close()
522522

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 {
525525
_, err = fmt.Fscanf(f, "%d\n%d,%d,%d\n%d,%d,%d\n",
526526
&d.depth,
527527
&d.readFileNum, &d.readMessages, &d.readPos,
@@ -557,8 +557,8 @@ func (d *diskQueue) persistMetaData() error {
557557
return err
558558
}
559559

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 {
562562
_, err = fmt.Fprintf(f, "%d\n%d,%d,%d\n%d,%d,%d\n",
563563
d.depth,
564564
d.readFileNum, d.readMessages, d.readPos,

diskqueue_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,22 +259,22 @@ type md struct {
259259
writePos int64
260260
}
261261

262-
func readMetaDataFile(fileName string, retried int, diskLimitFeatIsOn bool) md {
262+
func readMetaDataFile(fileName string, retried int, enableDiskLimitation bool) md {
263263
f, err := os.OpenFile(fileName, os.O_RDONLY, 0600)
264264
if err != nil {
265265
// provide a simple retry that results in up to
266266
// another 500ms for the file to be written.
267267
if retried < 9 {
268268
retried++
269269
time.Sleep(50 * time.Millisecond)
270-
return readMetaDataFile(fileName, retried, diskLimitFeatIsOn)
270+
return readMetaDataFile(fileName, retried, enableDiskLimitation)
271271
}
272272
panic(err)
273273
}
274274
defer f.Close()
275275

276276
var ret md
277-
if diskLimitFeatIsOn {
277+
if enableDiskLimitation {
278278
_, err = fmt.Fscanf(f, "%d\n%d,%d,%d\n%d,%d,%d\n",
279279
&ret.depth,
280280
&ret.readFileNum, &ret.readMessages, &ret.readPos,
@@ -348,7 +348,7 @@ func TestDiskQueueSyncAfterReadWithDiskSizeImplementation(t *testing.T) {
348348
panic(err)
349349
}
350350
defer os.RemoveAll(tmpDir)
351-
dq := NewWithDiskSpace(dqName, tmpDir, 1<<11, 1<<11, 0, 1<<10, 2500, 50*time.Millisecond, l)
351+
dq := NewWithDiskSize(dqName, tmpDir, 1<<11, 1<<11, 0, 1<<10, 2500, 50*time.Millisecond, l)
352352
defer dq.Close()
353353

354354
msgSize := 1000

0 commit comments

Comments
 (0)