summaryrefslogtreecommitdiffstats
path: root/src/client/SyntheticClient.h
blob: 2c160163732e5e1b0534923f6831a85a7a2bf990 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
// vim: ts=8 sw=2 smarttab
/*
 * Ceph - scalable distributed file system
 *
 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
 *
 * This is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1, as published by the Free Software 
 * Foundation.  See file COPYING.
 * 
 */


#ifndef CEPH_SYNTHETICCLIENT_H
#define CEPH_SYNTHETICCLIENT_H

#include <pthread.h>

#include "Client.h"
#include "include/Distribution.h"

#include "Trace.h"

#define SYNCLIENT_FIRST_POOL	0

#define SYNCLIENT_MODE_RANDOMWALK  1
#define SYNCLIENT_MODE_FULLWALK    2
#define SYNCLIENT_MODE_REPEATWALK  3

#define SYNCLIENT_MODE_MAKEDIRMESS  7
#define SYNCLIENT_MODE_MAKEDIRS     8      // dirs files depth
#define SYNCLIENT_MODE_STATDIRS     9     // dirs files depth
#define SYNCLIENT_MODE_READDIRS     10     // dirs files depth

#define SYNCLIENT_MODE_MAKEFILES    11     // num count private
#define SYNCLIENT_MODE_MAKEFILES2   12     // num count private
#define SYNCLIENT_MODE_CREATESHARED 13     // num
#define SYNCLIENT_MODE_OPENSHARED   14     // num count

#define SYNCLIENT_MODE_RMFILE      19
#define SYNCLIENT_MODE_WRITEFILE   20
#define SYNCLIENT_MODE_READFILE    21
#define SYNCLIENT_MODE_WRITEBATCH  22
#define SYNCLIENT_MODE_WRSHARED    23
#define SYNCLIENT_MODE_READSHARED    24
#define SYNCLIENT_MODE_RDWRRANDOM    25
#define SYNCLIENT_MODE_RDWRRANDOM_EX    26

#define SYNCLIENT_MODE_LINKTEST   27

#define SYNCLIENT_MODE_OVERLOAD_OSD_0 28 // two args

#define SYNCLIENT_MODE_DROPCACHE   29

#define SYNCLIENT_MODE_TRACE       30

#define SYNCLIENT_MODE_CREATEOBJECTS 35
#define SYNCLIENT_MODE_OBJECTRW 36

#define SYNCLIENT_MODE_OPENTEST     40
#define SYNCLIENT_MODE_OPTEST       41

#define SYNCLIENT_MODE_ONLY        50
#define SYNCLIENT_MODE_ONLYRANGE   51
#define SYNCLIENT_MODE_EXCLUDE     52
#define SYNCLIENT_MODE_EXCLUDERANGE  53

#define SYNCLIENT_MODE_UNTIL       55
#define SYNCLIENT_MODE_SLEEPUNTIL  56

#define SYNCLIENT_MODE_RANDOMSLEEP  61
#define SYNCLIENT_MODE_SLEEP        62

#define SYNCLIENT_MODE_DUMP 63

#define SYNCLIENT_MODE_LOOKUPHASH     70
#define SYNCLIENT_MODE_LOOKUPINO     71

#define SYNCLIENT_MODE_TRUNCATE     200

#define SYNCLIENT_MODE_FOO        100
#define SYNCLIENT_MODE_THRASHLINKS  101

#define SYNCLIENT_MODE_IMPORTFIND 300

#define SYNCLIENT_MODE_CHUNK    400

#define SYNCLIENT_MODE_MKSNAP 1000
#define SYNCLIENT_MODE_RMSNAP 1001

#define SYNCLIENT_MODE_MKSNAPFILE 1002



void parse_syn_options(std::vector<const char*>& args);
extern int num_client;

class SyntheticClient {
  StandaloneClient *client;
  int whoami;

  pthread_t thread_id;

  Distribution op_dist;

  void init_op_dist();
  int get_op();

  
  filepath cwd;
  std::map<std::string, struct stat*> contents;
  std::set<std::string> subdirs;
  bool did_readdir;
  std::set<int> open_files;

  void up();

  void clear_dir() {
    contents.clear();
    subdirs.clear();
    did_readdir = false;
  }

  int get_random_fh() {
    int r = rand() % open_files.size();
    std::set<int>::iterator it = open_files.begin();
    while (r--) ++it;
    return *it;
  }


  filepath n1;
  const char *get_random_subdir() {
    ceph_assert(!subdirs.empty());
    int r = ((rand() % subdirs.size()) + (rand() % subdirs.size())) / 2;  // non-uniform distn
    std::set<std::string>::iterator it = subdirs.begin();
    while (r--) ++it;

    n1 = cwd;
    n1.push_dentry( *it );
    return n1.get_path().c_str();
  }
  filepath n2;
  const char *get_random_sub() {
    ceph_assert(!contents.empty());
    int r = ((rand() % contents.size()) + (rand() % contents.size())) / 2;  // non-uniform distn
    if (cwd.depth() && cwd.last_dentry().length()) 
      r += cwd.last_dentry().c_str()[0];                                         // slightly permuted
    r %= contents.size();

    std::map<std::string,struct stat*>::iterator it = contents.begin();
    while (r--) ++it;

    n2 = cwd;
    n2.push_dentry( it->first );
    return n2.get_path().c_str();
  }
  
  filepath sub;
  char sub_s[50];
  const char *make_sub(const char *base) {
    snprintf(sub_s, sizeof(sub_s), "%s.%d", base, rand() % 100);
    std::string f = sub_s;
    sub = cwd;
    sub.push_dentry(f);
    return sub.c_str();
  }

 public:
  SyntheticClient(StandaloneClient *client, int w = -1);

  int start_thread();
  int join_thread();

  int run();

  bool run_me() {
    if (run_only >= 0) {
      if (run_only == client->get_nodeid())
        return true;
      else
	return false;
    }
    return true;
  }
  void did_run_me() {
    run_only = -1;
    run_until = utime_t();
  }

  // run() will do one of these things:
  std::list<int> modes;
  std::list<std::string> sargs;
  std::list<int> iargs;
  utime_t run_start;
  utime_t run_until;

  client_t run_only;
  client_t exclude;

  std::string get_sarg(int seq);
  int get_iarg() {
    int i = iargs.front();
    iargs.pop_front();
    return i;
  }

  bool time_to_stop() {
    utime_t now = ceph_clock_now();
    if (0) std::cout << "time_to_stop .. now " << now
		     << " until " << run_until
		     << " start " << run_start
		     << std::endl;
    if (run_until.sec() && now > run_until)
      return true;
    else
      return false;
  }

  std::string compose_path(std::string& prefix, char *rest) {
    return prefix + rest;
  }

  int full_walk(std::string& fromdir);
  int random_walk(int n);

  int dump_placement(std::string& fn);


  int make_dirs(const char *basedir, int dirs, int files, int depth);
  int stat_dirs(const char *basedir, int dirs, int files, int depth);
  int read_dirs(const char *basedir, int dirs, int files, int depth);
  int make_files(int num, int count, int priv, bool more);
  int link_test();

  int create_shared(int num);
  int open_shared(int num, int count);

  int rm_file(std::string& fn);
  int write_file(std::string& fn, int mb, loff_t chunk);
  int write_fd(int fd, int size, int wrsize);

  int write_batch(int nfile, int mb, int chunk);
  int read_file(const std::string& fn, int mb, int chunk, bool ignoreprint=false);

  int create_objects(int nobj, int osize, int inflight);
  int object_rw(int nobj, int osize, int wrpc, int overlap, 
		double rskew, double wskew);

  int read_random(std::string& fn, int mb, int chunk);
  int read_random_ex(std::string& fn, int mb, int chunk);
  
  int overload_osd_0(int n, int sie, int wrsize);
  int check_first_primary(int fd);

  int clean_dir(std::string& basedir);

  int play_trace(Trace& t, std::string& prefix, bool metadata_only=false);

  void make_dir_mess(const char *basedir, int n);
  void foo();

  int thrash_links(const char *basedir, int dirs, int files, int depth, int n);

  void import_find(const char *basedir, const char *find, bool writedata);

  int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name,
		  const UserPerm& perms);
  int lookup_ino(inodeno_t ino, const UserPerm& perms);

  int chunk_file(std::string &filename);

  void mksnap(const char *base, const char *name, const UserPerm& perms);
  void rmsnap(const char *base, const char *name, const UserPerm& perms);
  void mksnapfile(const char *dir);

};

#endif