@@ -35,7 +35,7 @@ import (
35
35
// Application info
36
36
const (
37
37
APP = "RDS Payload Generator"
38
- VER = "1.1.3 "
38
+ VER = "1.2.0 "
39
39
DESC = "Payload generator for Redis-Split"
40
40
)
41
41
@@ -66,7 +66,7 @@ type RedisStore struct {
66
66
// ////////////////////////////////////////////////////////////////////////////////// //
67
67
68
68
var optMap = options.Map {
69
- OPT_DIR : {Value : "/opt/redis-split" },
69
+ OPT_DIR : {},
70
70
OPT_KEYS : {Type : options .INT , Value : 5000 , Min : 10 , Max : 1000000 },
71
71
OPT_RATIO : {Type : options .INT , Value : 4 , Min : 1 , Max : 100 },
72
72
OPT_NO_COLOR : {Type : options .BOOL },
@@ -150,31 +150,19 @@ func configureUI() {
150
150
151
151
// checkRDSInstallation checks Redis-Split installation
152
152
func checkRDSInstallation () {
153
- rdsDir := options .GetS (OPT_DIR )
154
- metaDir := rdsDir + "/meta"
155
-
156
- if ! fsutil .IsExist (rdsDir ) {
157
- printError ("Directory %s doesn't exist" , rdsDir )
158
- os .Exit (1 )
159
- }
160
-
161
- if ! fsutil .IsExist (metaDir ) {
162
- printError ("Directory %s doesn't exist" , metaDir )
163
- os .Exit (1 )
164
- }
153
+ rdsDir := getRDSMainDir ()
154
+ err := fsutil .ValidatePerms ("DRX" , rdsDir )
165
155
166
- if ! fsutil . IsDir ( rdsDir ) {
167
- printError ("%s is not a directory" , metaDir )
156
+ if err != nil {
157
+ printError (err . Error () )
168
158
os .Exit (1 )
169
159
}
170
160
171
- if ! fsutil .IsDir (metaDir ) {
172
- printError ("%s is not a directory" , metaDir )
173
- os .Exit (1 )
174
- }
161
+ metaDir := rdsDir + "/meta"
162
+ err = fsutil .ValidatePerms ("DRX" , metaDir )
175
163
176
- if fsutil . IsEmptyDir ( metaDir ) {
177
- printError ("No instances are created" )
164
+ if err != nil {
165
+ printError (err . Error () )
178
166
os .Exit (1 )
179
167
}
180
168
}
@@ -188,7 +176,7 @@ func generatePayload() {
188
176
var reads , writes int64
189
177
190
178
store := & RedisStore {make (map [string ]* redy.Client )}
191
- metaDir := options . GetS ( OPT_DIR ) + "/meta"
179
+ metaDir := getRDSMainDir ( ) + "/meta"
192
180
maxKey := options .GetI (OPT_KEYS )
193
181
ratio := options .GetI (OPT_RATIO )
194
182
@@ -230,6 +218,20 @@ func generatePayload() {
230
218
}
231
219
}
232
220
221
+ // getRDSMainDir returns path to main Redis-Split directory
222
+ func getRDSMainDir () string {
223
+ return fsutil .ProperPath ("DRX" ,
224
+ []string {
225
+ options .GetS (OPT_DIR ),
226
+ "/opt/redis-split" ,
227
+ "/srv/redis-split" ,
228
+ "/srv2/redis-split" ,
229
+ "/srv3/redis-split" ,
230
+ "/srv4/redis-split" ,
231
+ },
232
+ )
233
+ }
234
+
233
235
// getPause returns pause between requests
234
236
func getPause () time.Duration {
235
237
r := 0.001 * float64 (rand .Int (25 ))
@@ -243,7 +245,7 @@ func getKey(max int) string {
243
245
244
246
// isInstanceWorks returns true if instance is works
245
247
func isInstanceWorks (id string ) bool {
246
- pidDir := options . GetS ( OPT_DIR ) + "/pid"
248
+ pidDir := getRDSMainDir ( ) + "/pid"
247
249
pidFile := fmt .Sprintf ("%s/%s.pid" , pidDir , id )
248
250
249
251
return fsutil .IsExist (pidFile )
@@ -326,9 +328,9 @@ func printMan() {
326
328
func genUsage () * usage.Info {
327
329
info := usage .NewInfo ()
328
330
329
- info .AddOption (OPT_DIR , "Redis-Split main dir" , "dir" )
331
+ info .AddOption (OPT_DIR , "Path to Redis-Split main dir" , "dir" )
330
332
info .AddOption (OPT_KEYS , "Number of keys {s-}(10-1000000 default: 5000){!}" )
331
- info .AddOption (OPT_RATIO , "Writes/reads ration {s-}(1-100 default: 4){!}" )
333
+ info .AddOption (OPT_RATIO , "Writes/reads ratio {s-}(1-100 default: 4){!}" )
332
334
info .AddOption (OPT_NO_COLOR , "Disable colors in output" )
333
335
info .AddOption (OPT_HELP , "Show this help message" )
334
336
info .AddOption (OPT_VER , "Show version" )
0 commit comments