Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / test / objectstore / DeterministicOpSequence.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2012 New Dream Network
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 */
13 #ifndef FILESTORE_DTRMNSTC_SEQ_OPS_H_
14 #define FILESTORE_DTRMNSTC_SEQ_OPS_H_
15
16 #include <iostream>
17 #include <fstream>
18 #include <set>
19 #include "os/ObjectStore.h"
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/random/mersenne_twister.hpp>
22 #include <boost/random/uniform_int.hpp>
23
24 #include "TestObjectStoreState.h"
25
26 typedef boost::mt11213b rngen_t;
27
28 class DeterministicOpSequence : public TestObjectStoreState {
29  public:
30   DeterministicOpSequence(ObjectStore *store, std::string status = std::string());
31   virtual ~DeterministicOpSequence();
32
33   virtual void generate(int seed, int num_txs);
34
35  protected:
36   enum {
37     DSOP_TOUCH = 0,
38     DSOP_WRITE = 1,
39     DSOP_CLONE = 2,
40     DSOP_CLONE_RANGE = 3,
41     DSOP_OBJ_REMOVE = 4,
42     DSOP_COLL_MOVE = 6,
43     DSOP_SET_ATTRS = 7,
44     DSOP_COLL_CREATE = 8,
45
46     DSOP_FIRST = DSOP_TOUCH,
47     DSOP_LAST = DSOP_COLL_CREATE,
48   };
49
50   int32_t txn;
51
52   coll_t txn_coll;
53   hobject_t txn_object;
54
55   ObjectStore::Sequencer m_osr;
56   std::ofstream m_status;
57
58   bool run_one_op(int op, rngen_t& gen);
59
60   void note_txn(ObjectStore::Transaction *t);
61   bool do_touch(rngen_t& gen);
62   bool do_remove(rngen_t& gen);
63   bool do_write(rngen_t& gen);
64   bool do_clone(rngen_t& gen);
65   bool do_clone_range(rngen_t& gen);
66   bool do_coll_move(rngen_t& gen);
67   bool do_set_attrs(rngen_t& gen);
68   bool do_coll_create(rngen_t& gen);
69
70   virtual void _do_touch(coll_t coll, hobject_t& obj);
71   virtual void _do_remove(coll_t coll, hobject_t& obj);
72   virtual void _do_write(coll_t coll, hobject_t& obj, uint64_t off,
73       uint64_t len, const bufferlist& data);
74   virtual void _do_set_attrs(coll_t coll,
75                              hobject_t &obj,
76                              const map<string, bufferlist> &attrs);
77   virtual void _do_clone(coll_t coll, hobject_t& orig_obj, hobject_t& new_obj);
78   virtual void _do_clone_range(coll_t coll, hobject_t& orig_obj,
79       hobject_t& new_obj, uint64_t srcoff, uint64_t srclen, uint64_t dstoff);
80   virtual void _do_write_and_clone_range(coll_t coll, hobject_t& orig_obj,
81       hobject_t& new_obj, uint64_t srcoff, uint64_t srclen,
82       uint64_t dstoff, bufferlist& bl);
83   virtual void _do_coll_move(coll_t orig_coll, coll_t new_coll, hobject_t& obj);
84   virtual void _do_coll_create(coll_t cid, uint32_t pg_num, uint64_t num_objs);
85
86   int _gen_coll_id(rngen_t& gen);
87   int _gen_obj_id(rngen_t& gen);
88   void _print_status(int seq, int op);
89
90  private:
91   bool _prepare_clone(rngen_t& gen, coll_t& coll_ret,
92       hobject_t& orig_obj_ret, hobject_t& new_obj_ret);
93   bool _prepare_colls(rngen_t& gen,
94       coll_entry_t* &orig_coll, coll_entry_t* &new_coll);
95 };
96
97
98 #endif /* FILESTORE_DTRMNSTC_SEQ_OPS_H_ */