@@ -2,6 +2,7 @@ package storage
2
2
3
3
import (
4
4
"fmt"
5
+ "sync"
5
6
"sync/atomic"
6
7
7
8
"github.com/chrislusf/seaweedfs/weed/glog"
@@ -35,14 +36,18 @@ type Store struct {
35
36
DeletedVolumesChan chan master_pb.VolumeShortInformationMessage
36
37
NewEcShardsChan chan master_pb.VolumeEcShardInformationMessage
37
38
DeletedEcShardsChan chan master_pb.VolumeEcShardInformationMessage
39
+
40
+ fsyncThreshold int
41
+ writtenFileCount int
42
+ fsyncLock sync.Mutex
38
43
}
39
44
40
45
func (s * Store ) String () (str string ) {
41
46
str = fmt .Sprintf ("Ip:%s, Port:%d, PublicUrl:%s, dataCenter:%s, rack:%s, connected:%v, volumeSizeLimit:%d" , s .Ip , s .Port , s .PublicUrl , s .dataCenter , s .rack , s .connected , s .GetVolumeSizeLimit ())
42
47
return
43
48
}
44
49
45
- func NewStore (grpcDialOption grpc.DialOption , port int , ip , publicUrl string , dirnames []string , maxVolumeCounts []int , needleMapKind NeedleMapType ) (s * Store ) {
50
+ func NewStore (grpcDialOption grpc.DialOption , port int , ip , publicUrl string , dirnames []string , maxVolumeCounts []int , needleMapKind NeedleMapType , fsyncThreshold int ) (s * Store ) {
46
51
s = & Store {grpcDialOption : grpcDialOption , Port : port , Ip : ip , PublicUrl : publicUrl , NeedleMapType : needleMapKind }
47
52
s .Locations = make ([]* DiskLocation , 0 )
48
53
for i := 0 ; i < len (dirnames ); i ++ {
@@ -57,6 +62,8 @@ func NewStore(grpcDialOption grpc.DialOption, port int, ip, publicUrl string, di
57
62
s .NewEcShardsChan = make (chan master_pb.VolumeEcShardInformationMessage , 3 )
58
63
s .DeletedEcShardsChan = make (chan master_pb.VolumeEcShardInformationMessage , 3 )
59
64
65
+ s .fsyncThreshold = fsyncThreshold
66
+
60
67
return
61
68
}
62
69
func (s * Store ) AddVolume (volumeId needle.VolumeId , collection string , needleMapKind NeedleMapType , replicaPlacement string , ttlString string , preallocate int64 ) error {
@@ -219,6 +226,15 @@ func (s *Store) WriteVolumeNeedle(i needle.VolumeId, n *needle.Needle) (size uin
219
226
}
220
227
if MaxPossibleVolumeSize >= v .ContentSize ()+ uint64 (needle .GetActualSize (size , v .version )) {
221
228
_ , size , isUnchanged , err = v .writeNeedle (n )
229
+ if s .fsyncThreshold != 0 {
230
+ s .fsyncLock .Lock ()
231
+ s .writtenFileCount ++
232
+ if s .writtenFileCount > s .fsyncThreshold {
233
+ v .dataFile .Sync ()
234
+ s .writtenFileCount = 0
235
+ }
236
+ s .fsyncLock .Unlock ()
237
+ }
222
238
} else {
223
239
err = fmt .Errorf ("volume size limit %d exceeded! current size is %d" , s .GetVolumeSizeLimit (), v .ContentSize ())
224
240
}
0 commit comments