@@ -18,6 +18,7 @@ import (
18
18
. "github.com/kahing/goofys/api/common"
19
19
. "gopkg.in/check.v1"
20
20
21
+ "fmt"
21
22
"syscall"
22
23
"time"
23
24
)
@@ -57,13 +58,30 @@ type S3BucketEventualConsistency struct {
57
58
* S3Backend
58
59
}
59
60
61
+ func (s * S3BucketEventualConsistency ) Init (key string ) (err error ) {
62
+ // TODO: make Init return errno instead
63
+ NoSuchBucket := fmt .Sprintf ("bucket %v does not exist" , s .Bucket ())
64
+
65
+ for i := 0 ; i < 10 ; i ++ {
66
+ err = s .S3Backend .Init (key )
67
+ if err != nil && err .Error () == NoSuchBucket {
68
+ s3Log .Infof ("waiting for bucket" )
69
+ time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
70
+ } else {
71
+ return
72
+ }
73
+ }
74
+
75
+ return
76
+ }
77
+
60
78
func (s * S3BucketEventualConsistency ) ListBlobs (param * ListBlobsInput ) (* ListBlobsOutput , error ) {
61
79
for i := 0 ; i < 10 ; i ++ {
62
80
res , err := s .S3Backend .ListBlobs (param )
63
81
switch err {
64
82
case syscall .ENXIO :
65
- time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
66
83
s3Log .Infof ("waiting for bucket" )
84
+ time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
67
85
default :
68
86
return res , err
69
87
}
@@ -77,8 +95,8 @@ func (s *S3BucketEventualConsistency) DeleteBlob(param *DeleteBlobInput) (*Delet
77
95
res , err := s .S3Backend .DeleteBlob (param )
78
96
switch err {
79
97
case syscall .ENXIO :
80
- time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
81
98
s3Log .Infof ("waiting for bucket" )
99
+ time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
82
100
default :
83
101
return res , err
84
102
}
@@ -92,8 +110,8 @@ func (s *S3BucketEventualConsistency) DeleteBlobs(param *DeleteBlobsInput) (*Del
92
110
res , err := s .S3Backend .DeleteBlobs (param )
93
111
switch err {
94
112
case syscall .ENXIO :
95
- time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
96
113
s3Log .Infof ("waiting for bucket" )
114
+ time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
97
115
default :
98
116
return res , err
99
117
}
@@ -107,8 +125,8 @@ func (s *S3BucketEventualConsistency) CopyBlob(param *CopyBlobInput) (*CopyBlobO
107
125
res , err := s .S3Backend .CopyBlob (param )
108
126
switch err {
109
127
case syscall .ENXIO :
110
- time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
111
128
s3Log .Infof ("waiting for bucket" )
129
+ time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
112
130
default :
113
131
return res , err
114
132
}
@@ -123,8 +141,8 @@ func (s *S3BucketEventualConsistency) PutBlob(param *PutBlobInput) (*PutBlobOutp
123
141
switch err {
124
142
case syscall .ENXIO :
125
143
param .Body .Seek (0 , 0 )
126
- time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
127
144
s3Log .Infof ("waiting for bucket" )
145
+ time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
128
146
default :
129
147
return res , err
130
148
}
@@ -138,8 +156,8 @@ func (s *S3BucketEventualConsistency) RemoveBucket(param *RemoveBucketInput) (*R
138
156
res , err := s .S3Backend .RemoveBucket (param )
139
157
switch err {
140
158
case syscall .ENXIO :
141
- time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
142
159
s3Log .Infof ("waiting for bucket" )
160
+ time .Sleep ((time .Duration (i ) + 1 ) * 2 * time .Second )
143
161
default :
144
162
return res , err
145
163
}
0 commit comments