@@ -79,7 +79,7 @@ type diskQueue struct {
79
79
// instantiation time metadata
80
80
name string
81
81
dataPath string
82
- maxBytesDiskSpace int64
82
+ maxBytesDiskSize int64
83
83
maxBytesPerFile int64 // cannot change once created
84
84
maxBytesPerFileRead int64
85
85
minMsgSize int32
@@ -94,6 +94,10 @@ type diskQueue struct {
94
94
nextReadPos int64
95
95
nextReadFileNum int64
96
96
97
+ // keep track of the msg size we have read
98
+ // (but not yet sent over readChan)
99
+ readMsgSize int32
100
+
97
101
readFile * os.File
98
102
writeFile * os.File
99
103
reader * bufio.Reader
@@ -123,17 +127,17 @@ func New(name string, dataPath string, maxBytesPerFile int64,
123
127
minMsgSize int32 , maxMsgSize int32 ,
124
128
syncEvery int64 , syncTimeout time.Duration , logf AppLogFunc ) Interface {
125
129
126
- return NewWithDiskSpace (name , dataPath ,
130
+ return NewWithDiskSize (name , dataPath ,
127
131
0 , maxBytesPerFile ,
128
132
minMsgSize , maxMsgSize ,
129
133
syncEvery , syncTimeout , logf )
130
134
}
131
135
132
- // Another constructor that allows users to use Disk Space Limit feature
133
- // If user is not using Disk Space Limit feature, maxBytesDiskSpace will
136
+ // Another constructor that allows users to use Disk Size Limit feature
137
+ // If user is not using Disk Size Limit feature, maxBytesDiskSize will
134
138
// be 0
135
- func NewWithDiskSpace (name string , dataPath string ,
136
- maxBytesDiskSpace int64 , maxBytesPerFile int64 ,
139
+ func NewWithDiskSize (name string , dataPath string ,
140
+ maxBytesDiskSize int64 , maxBytesPerFile int64 ,
137
141
minMsgSize int32 , maxMsgSize int32 ,
138
142
syncEvery int64 , syncTimeout time.Duration , logf AppLogFunc ) Interface {
139
143
enableDiskLimitation := true
@@ -967,6 +971,24 @@ func (d *diskQueue) handleReadError() {
967
971
d .name , badFn , badRenameFn )
968
972
}
969
973
974
+ if d .enableDiskLimitation {
975
+ var badFileSize int64
976
+ if d .readFileNum == d .writeFileNum {
977
+ badFileSize = d .writeBytes
978
+ } else {
979
+ var stat os.FileInfo
980
+ stat , err = os .Stat (badRenameFn )
981
+ if err == nil {
982
+ badFileSize = stat .Size ()
983
+ } else {
984
+ // max file size
985
+ badFileSize = int64 (d .maxMsgSize ) + d .maxBytesPerFile + 4 + numFileMsgsBytes
986
+ }
987
+ }
988
+
989
+ d .writeBytes -= badFileSize
990
+ }
991
+
970
992
d .readFileNum ++
971
993
d .readPos = 0
972
994
d .nextReadFileNum = d .readFileNum
0 commit comments