]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/osd/TestOSDScrub.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2013 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Author: Loic Dachary <loic@dachary.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Library Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Library Public License for more details.
24 #include <gtest/gtest.h>
25 #include "common/async/context_pool.h"
27 #include "os/ObjectStore.h"
28 #include "mon/MonClient.h"
29 #include "common/ceph_argparse.h"
30 #include "msg/Messenger.h"
32 class TestOSDScrub
: public OSD
{
35 TestOSDScrub(CephContext
*cct_
,
36 std::unique_ptr
<ObjectStore
> store_
,
40 Messenger
*hb_front_client
,
41 Messenger
*hb_back_client
,
42 Messenger
*hb_front_server
,
43 Messenger
*hb_back_server
,
44 Messenger
*osdc_messenger
,
45 MonClient
*mc
, const std::string
&dev
, const std::string
&jdev
,
46 ceph::async::io_context_pool
& ictx
) :
47 OSD(cct_
, std::move(store_
), id
, internal
, external
,
48 hb_front_client
, hb_back_client
,
49 hb_front_server
, hb_back_server
,
50 osdc_messenger
, mc
, dev
, jdev
, ictx
)
54 bool scrub_time_permit(utime_t now
) {
55 return service
.get_scrub_services().scrub_time_permit(now
);
59 TEST(TestOSDScrub
, scrub_time_permit
) {
60 ceph::async::io_context_pool
icp(1);
61 std::unique_ptr
<ObjectStore
> store
= ObjectStore::create(g_ceph_context
,
62 g_conf()->osd_objectstore
,
64 g_conf()->osd_journal
);
65 std::string cluster_msgr_type
= g_conf()->ms_cluster_type
.empty() ? g_conf().get_val
<std::string
>("ms_type") : g_conf()->ms_cluster_type
;
66 Messenger
*ms
= Messenger::create(g_ceph_context
, cluster_msgr_type
,
67 entity_name_t::OSD(0), "make_checker",
69 ms
->set_cluster_protocol(CEPH_OSD_PROTOCOL
);
70 ms
->set_default_policy(Messenger::Policy::stateless_server(0));
71 ms
->bind(g_conf()->public_addr
);
72 MonClient
mc(g_ceph_context
, icp
);
73 mc
.build_initial_monmap();
74 TestOSDScrub
* osd
= new TestOSDScrub(g_ceph_context
, std::move(store
), 0, ms
, ms
, ms
, ms
, ms
, ms
, ms
, &mc
, "", "", icp
);
76 // These are now invalid
77 int err
= g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "24");
79 //GTEST_LOG_(INFO) << " osd_scrub_begin_hour = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_begin_hour");
81 err
= g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "24");
83 //GTEST_LOG_(INFO) << " osd_scrub_end_hour = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_end_hour");
85 err
= g_ceph_context
->_conf
.set_val("osd_scrub_begin_week_day", "7");
87 //GTEST_LOG_(INFO) << " osd_scrub_begin_week_day = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_begin_week_day");
89 err
= g_ceph_context
->_conf
.set_val("osd_scrub_end_week_day", "7");
91 //GTEST_LOG_(INFO) << " osd_scrub_end_week_day = " << g_ceph_context->_conf.get_val<int64_t>("osd_scrub_end_week_day");
94 g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "0");
95 g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "0");
96 g_ceph_context
->_conf
.apply_changes(nullptr);
99 strptime("2015-01-16 12:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
100 utime_t now
= utime_t(mktime(&tm
), 0);
101 bool ret
= osd
->scrub_time_permit(now
);
104 g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "20");
105 g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "07");
106 g_ceph_context
->_conf
.apply_changes(nullptr);
107 strptime("2015-01-16 01:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
108 now
= utime_t(mktime(&tm
), 0);
109 ret
= osd
->scrub_time_permit(now
);
112 g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "20");
113 g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "07");
114 g_ceph_context
->_conf
.apply_changes(nullptr);
115 strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
116 now
= utime_t(mktime(&tm
), 0);
117 ret
= osd
->scrub_time_permit(now
);
120 g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "20");
121 g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "07");
122 g_ceph_context
->_conf
.apply_changes(nullptr);
123 strptime("2015-01-16 08:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
124 now
= utime_t(mktime(&tm
), 0);
125 ret
= osd
->scrub_time_permit(now
);
128 g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "01");
129 g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "07");
130 g_ceph_context
->_conf
.apply_changes(nullptr);
131 strptime("2015-01-16 20:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
132 now
= utime_t(mktime(&tm
), 0);
133 ret
= osd
->scrub_time_permit(now
);
136 g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "01");
137 g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "07");
138 g_ceph_context
->_conf
.apply_changes(nullptr);
139 strptime("2015-01-16 00:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
140 now
= utime_t(mktime(&tm
), 0);
141 ret
= osd
->scrub_time_permit(now
);
144 g_ceph_context
->_conf
.set_val("osd_scrub_begin_hour", "01");
145 g_ceph_context
->_conf
.set_val("osd_scrub_end_hour", "07");
146 g_ceph_context
->_conf
.apply_changes(nullptr);
147 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
148 now
= utime_t(mktime(&tm
), 0);
149 ret
= osd
->scrub_time_permit(now
);
152 // Sun = 0, Mon = 1, Tue = 2, Wed = 3, Thu = 4m, Fri = 5, Sat = 6
153 // Jan 16, 2015 is a Friday (5)
155 g_ceph_context
->_conf
.set_val("osd_scrub_begin_week day", "0"); // inclusive
156 g_ceph_context
->_conf
.set_val("osd_scrub_end_week_day", "0"); // not inclusive
157 g_ceph_context
->_conf
.apply_changes(nullptr);
158 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
159 now
= utime_t(mktime(&tm
), 0);
160 ret
= osd
->scrub_time_permit(now
);
164 g_ceph_context
->_conf
.set_val("osd_scrub_begin_week day", "0"); // inclusive
165 g_ceph_context
->_conf
.set_val("osd_scrub_end_week_day", "5"); // not inclusive
166 g_ceph_context
->_conf
.apply_changes(nullptr);
167 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
168 now
= utime_t(mktime(&tm
), 0);
169 ret
= osd
->scrub_time_permit(now
);
173 g_ceph_context
->_conf
.set_val("osd_scrub_begin_week day", "5"); // inclusive
174 g_ceph_context
->_conf
.set_val("osd_scrub_end_week_day", "0"); // not inclusive
175 g_ceph_context
->_conf
.apply_changes(nullptr);
176 strptime("2015-01-16 04:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
177 now
= utime_t(mktime(&tm
), 0);
178 ret
= osd
->scrub_time_permit(now
);
181 // Jan 14, 2015 is a Wednesday (3)
183 g_ceph_context
->_conf
.set_val("osd_scrub_begin_week day", "2"); // inclusive
184 g_ceph_context
->_conf
.set_val("osd_scrub_end_week_day", "6"); // not inclusive
185 g_ceph_context
->_conf
.apply_changes(nullptr);
186 strptime("2015-01-14 04:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
187 now
= utime_t(mktime(&tm
), 0);
188 ret
= osd
->scrub_time_permit(now
);
192 g_ceph_context
->_conf
.set_val("osd_scrub_begin_week day", "6"); // inclusive
193 g_ceph_context
->_conf
.set_val("osd_scrub_end_week_day", "1"); // not inclusive
194 g_ceph_context
->_conf
.apply_changes(nullptr);
195 strptime("2015-01-14 04:05:13", "%Y-%m-%d %H:%M:%S", &tm
);
196 now
= utime_t(mktime(&tm
), 0);
197 ret
= osd
->scrub_time_permit(now
);
202 // compile-command: "cd ../.. ; make unittest_osdscrub ; ./unittest_osdscrub --log-to-stderr=true --debug-osd=20 # --gtest_filter=*.* "