]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/multi_stress_watch.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 #include "include/rados/librados.h"
3 #include "include/rados/librados.hpp"
4 #include "test/librados/test_cxx.h"
9 #include <condition_variable>
17 using namespace librados
;
21 class WatchNotifyTestCtx
: public WatchCtx
24 WatchNotifyTestCtx ( std :: mutex
& lock
)
26 void notify ( uint8_t opcode
, uint64_t ver
, bufferlist
& bl
) override
{
27 std :: unique_lock locker
{ lock
};
32 std :: unique_lock locker
{ lock
};
33 return cond
. wait_for ( locker
, std :: chrono :: seconds ( 1200 ),
34 [ this ] { return notified
; });
38 bool notified
= false ;
40 std :: condition_variable cond
;
43 #pragma GCC diagnostic ignored "-Wpragmas"
44 #pragma GCC diagnostic push
45 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
48 test_loop ( Rados
& cluster
, std :: string pool_name
, std :: string obj_name
)
52 ret
= cluster
. ioctx_create ( pool_name
. c_str (), ioctx
);
54 std :: cerr
<< "ioctx_create " << pool_name
<< " failed with " << ret
<< std :: endl
;
57 ioctx
. application_enable ( "rados" , true );
59 ret
= ioctx
. create ( obj_name
, false );
61 std :: cerr
<< "create failed with " << ret
<< std :: endl
;
66 constexpr int NR_ITERATIONS
= 10000 ;
67 for ( int i
= 0 ; i
< NR_ITERATIONS
; ++ i
) {
68 std :: cout
<< "Iteration " << i
<< std :: endl
;
70 WatchNotifyTestCtx ctx
{ lock
};
71 ret
= ioctx
. watch ( obj_name
, 0 , & handle
, & ctx
);
74 ret
= ioctx
. notify ( obj_name
, 0 , bl2
);
76 ceph_assert_always ( ctx
. wait ());
77 ioctx
. unwatch ( obj_name
, handle
);
80 ret
= cluster
. pool_delete ( pool_name
. c_str ());
82 std :: cerr
<< "pool_delete failed with " << ret
<< std :: endl
;
87 #pragma GCC diagnostic pop
88 #pragma GCC diagnostic warning "-Wpragmas"
91 test_replicated ( Rados
& cluster
, std :: string pool_name
, const std :: string
& obj_name
)
94 cluster
. pool_create ( pool_name
. c_str ());
96 test_loop ( cluster
, pool_name
, obj_name
);
100 test_erasure ( Rados
& cluster
, const std :: string
& pool_name
, const std :: string
& obj_name
)
105 ret
= cluster
. mon_command (
106 "{ \" prefix \" : \" osd erasure-code-profile set \" , \" name \" : \" testprofile \" , \" profile \" : [ \" k=2 \" , \" m=1 \" , \" crush-failure-domain=osd \" ]}" ,
109 std :: cerr
<< "mon_command erasure-code-profile set failed with " << ret
<< std :: endl
;
112 //std::cout << outs << std::endl;
115 ret
= cluster
. mon_command (
116 "{ \" prefix \" : \" osd pool create \" , \" pool \" : \" " + pool_name
+ " \" , \" pool_type \" : \" erasure \" , \" pg_num \" :12, \" pgp_num \" :12, \" erasure_code_profile \" : \" testprofile \" }" ,
119 std :: cerr
<< outs
<< std :: endl
;
120 std :: cerr
<< "mon_command create pool failed with " << ret
<< std :: endl
;
123 //std::cout << outs << std::endl;
125 cluster
. wait_for_latest_osdmap ();
126 test_loop ( cluster
, pool_name
, obj_name
);
130 int main ( int args
, char ** argv
)
132 if ( args
!= 3 && args
!= 4 ) {
133 std :: cerr
<< "Error: " << argv
[ 0 ] << " [ec|rep] pool_name obj_name" << std :: endl
;
137 std :: string pool_name
, obj_name
, type
;
138 // For backward compatibility with unmodified teuthology version
148 std :: cout
<< "Test type " << type
<< std :: endl
;
149 std :: cout
<< "pool_name, obj_name are " << pool_name
<< ", " << obj_name
<< std :: endl
;
151 if ( type
!= "ec" && type
!= "rep" ) {
152 std :: cerr
<< "Error: " << argv
[ 0 ] << " Invalid arg must be 'ec' or 'rep' saw " << type
<< std :: endl
;
157 std :: string err
= connect_cluster_pp ( cluster
);
159 std :: cerr
<< "Error " << err
<< std :: endl
;
164 test_replicated ( cluster
, pool_name
, obj_name
);
165 else if ( type
== "ec" )
166 test_erasure ( cluster
, pool_name
, obj_name
);