]> git.proxmox.com Git - ceph.git/blob - ceph/src/os/Transaction.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / os / Transaction.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "ObjectStore.h"
5 #include "common/Formatter.h"
6
7 void ObjectStore::Transaction::dump(ceph::Formatter *f)
8 {
9 f->open_array_section("ops");
10 iterator i = begin();
11 int op_num = 0;
12 bool stop_looping = false;
13 while (i.have_op() && !stop_looping) {
14 Transaction::Op *op = i.decode_op();
15 f->open_object_section("op");
16 f->dump_int("op_num", op_num);
17
18 switch (op->op) {
19 case Transaction::OP_NOP:
20 f->dump_string("op_name", "nop");
21 break;
22 case Transaction::OP_TOUCH:
23 {
24 coll_t cid = i.get_cid(op->cid);
25 ghobject_t oid = i.get_oid(op->oid);
26 f->dump_string("op_name", "touch");
27 f->dump_stream("collection") << cid;
28 f->dump_stream("oid") << oid;
29 }
30 break;
31
32 case Transaction::OP_WRITE:
33 {
34 coll_t cid = i.get_cid(op->cid);
35 ghobject_t oid = i.get_oid(op->oid);
36 uint64_t off = op->off;
37 uint64_t len = op->len;
38 bufferlist bl;
39 i.decode_bl(bl);
40 f->dump_string("op_name", "write");
41 f->dump_stream("collection") << cid;
42 f->dump_stream("oid") << oid;
43 f->dump_unsigned("length", len);
44 f->dump_unsigned("offset", off);
45 f->dump_unsigned("bufferlist length", bl.length());
46 }
47 break;
48
49 case Transaction::OP_ZERO:
50 {
51 coll_t cid = i.get_cid(op->cid);
52 ghobject_t oid = i.get_oid(op->oid);
53 uint64_t off = op->off;
54 uint64_t len = op->len;
55 f->dump_string("op_name", "zero");
56 f->dump_stream("collection") << cid;
57 f->dump_stream("oid") << oid;
58 f->dump_unsigned("offset", off);
59 f->dump_unsigned("length", len);
60 }
61 break;
62
63 case Transaction::OP_TRIMCACHE:
64 {
65 // deprecated, no-op
66 f->dump_string("op_name", "trim_cache");
67 }
68 break;
69
70 case Transaction::OP_TRUNCATE:
71 {
72 coll_t cid = i.get_cid(op->cid);
73 ghobject_t oid = i.get_oid(op->oid);
74 uint64_t off = op->off;
75 f->dump_string("op_name", "truncate");
76 f->dump_stream("collection") << cid;
77 f->dump_stream("oid") << oid;
78 f->dump_unsigned("offset", off);
79 }
80 break;
81
82 case Transaction::OP_REMOVE:
83 {
84 coll_t cid = i.get_cid(op->cid);
85 ghobject_t oid = i.get_oid(op->oid);
86 f->dump_string("op_name", "remove");
87 f->dump_stream("collection") << cid;
88 f->dump_stream("oid") << oid;
89 }
90 break;
91
92 case Transaction::OP_SETATTR:
93 {
94 coll_t cid = i.get_cid(op->cid);
95 ghobject_t oid = i.get_oid(op->oid);
96 string name = i.decode_string();
97 bufferlist bl;
98 i.decode_bl(bl);
99 f->dump_string("op_name", "setattr");
100 f->dump_stream("collection") << cid;
101 f->dump_stream("oid") << oid;
102 f->dump_string("name", name);
103 f->dump_unsigned("length", bl.length());
104 }
105 break;
106
107 case Transaction::OP_SETATTRS:
108 {
109 coll_t cid = i.get_cid(op->cid);
110 ghobject_t oid = i.get_oid(op->oid);
111 map<string, bufferptr> aset;
112 i.decode_attrset(aset);
113 f->dump_string("op_name", "setattrs");
114 f->dump_stream("collection") << cid;
115 f->dump_stream("oid") << oid;
116 f->open_object_section("attr_lens");
117 for (map<string,bufferptr>::iterator p = aset.begin();
118 p != aset.end(); ++p) {
119 f->dump_unsigned(p->first.c_str(), p->second.length());
120 }
121 f->close_section();
122 }
123 break;
124
125 case Transaction::OP_RMATTR:
126 {
127 coll_t cid = i.get_cid(op->cid);
128 ghobject_t oid = i.get_oid(op->oid);
129 string name = i.decode_string();
130 f->dump_string("op_name", "rmattr");
131 f->dump_stream("collection") << cid;
132 f->dump_stream("oid") << oid;
133 f->dump_string("name", name);
134 }
135 break;
136
137 case Transaction::OP_RMATTRS:
138 {
139 coll_t cid = i.get_cid(op->cid);
140 ghobject_t oid = i.get_oid(op->oid);
141 f->dump_string("op_name", "rmattrs");
142 f->dump_stream("collection") << cid;
143 f->dump_stream("oid") << oid;
144 }
145 break;
146
147 case Transaction::OP_CLONE:
148 {
149 coll_t cid = i.get_cid(op->cid);
150 ghobject_t oid = i.get_oid(op->oid);
151 ghobject_t noid = i.get_oid(op->dest_oid);
152 f->dump_string("op_name", "clone");
153 f->dump_stream("collection") << cid;
154 f->dump_stream("src_oid") << oid;
155 f->dump_stream("dst_oid") << noid;
156 }
157 break;
158
159 case Transaction::OP_CLONERANGE:
160 {
161 coll_t cid = i.get_cid(op->cid);
162 ghobject_t oid = i.get_oid(op->oid);
163 ghobject_t noid = i.get_oid(op->dest_oid);
164 uint64_t off = op->off;
165 uint64_t len = op->len;
166 f->dump_string("op_name", "clonerange");
167 f->dump_stream("collection") << cid;
168 f->dump_stream("src_oid") << oid;
169 f->dump_stream("dst_oid") << noid;
170 f->dump_unsigned("offset", off);
171 f->dump_unsigned("len", len);
172 }
173 break;
174
175 case Transaction::OP_CLONERANGE2:
176 {
177 coll_t cid = i.get_cid(op->cid);
178 ghobject_t oid = i.get_oid(op->oid);
179 ghobject_t noid = i.get_oid(op->dest_oid);
180 uint64_t srcoff = op->off;
181 uint64_t len = op->len;
182 uint64_t dstoff = op->dest_off;
183 f->dump_string("op_name", "clonerange2");
184 f->dump_stream("collection") << cid;
185 f->dump_stream("src_oid") << oid;
186 f->dump_stream("dst_oid") << noid;
187 f->dump_unsigned("src_offset", srcoff);
188 f->dump_unsigned("len", len);
189 f->dump_unsigned("dst_offset", dstoff);
190 }
191 break;
192
193 case Transaction::OP_MKCOLL:
194 {
195 coll_t cid = i.get_cid(op->cid);
196 f->dump_string("op_name", "mkcoll");
197 f->dump_stream("collection") << cid;
198 }
199 break;
200
201 case Transaction::OP_COLL_HINT:
202 {
203 using ceph::decode;
204 coll_t cid = i.get_cid(op->cid);
205 uint32_t type = op->hint_type;
206 f->dump_string("op_name", "coll_hint");
207 f->dump_stream("collection") << cid;
208 f->dump_unsigned("type", type);
209 bufferlist hint;
210 i.decode_bl(hint);
211 auto hiter = hint.cbegin();
212 if (type == Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS) {
213 uint32_t pg_num;
214 uint64_t num_objs;
215 decode(pg_num, hiter);
216 decode(num_objs, hiter);
217 f->dump_unsigned("pg_num", pg_num);
218 f->dump_unsigned("expected_num_objects", num_objs);
219 }
220 }
221 break;
222
223 case Transaction::OP_COLL_SET_BITS:
224 {
225 coll_t cid = i.get_cid(op->cid);
226 f->dump_string("op_name", "coll_set_bits");
227 f->dump_stream("collection") << cid;
228 f->dump_unsigned("bits", op->split_bits);
229 }
230 break;
231
232 case Transaction::OP_RMCOLL:
233 {
234 coll_t cid = i.get_cid(op->cid);
235 f->dump_string("op_name", "rmcoll");
236 f->dump_stream("collection") << cid;
237 }
238 break;
239
240 case Transaction::OP_COLL_ADD:
241 {
242 coll_t ocid = i.get_cid(op->cid);
243 coll_t ncid = i.get_cid(op->dest_cid);
244 ghobject_t oid = i.get_oid(op->oid);
245 f->dump_string("op_name", "collection_add");
246 f->dump_stream("src_collection") << ocid;
247 f->dump_stream("dst_collection") << ncid;
248 f->dump_stream("oid") << oid;
249 }
250 break;
251
252 case Transaction::OP_COLL_REMOVE:
253 {
254 coll_t cid = i.get_cid(op->cid);
255 ghobject_t oid = i.get_oid(op->oid);
256 f->dump_string("op_name", "collection_remove");
257 f->dump_stream("collection") << cid;
258 f->dump_stream("oid") << oid;
259 }
260 break;
261
262 case Transaction::OP_COLL_MOVE:
263 {
264 coll_t ocid = i.get_cid(op->cid);
265 coll_t ncid = i.get_cid(op->dest_cid);
266 ghobject_t oid = i.get_oid(op->oid);
267 f->open_object_section("collection_move");
268 f->dump_stream("src_collection") << ocid;
269 f->dump_stream("dst_collection") << ncid;
270 f->dump_stream("oid") << oid;
271 f->close_section();
272 }
273 break;
274
275 case Transaction::OP_COLL_SETATTR:
276 {
277 coll_t cid = i.get_cid(op->cid);
278 string name = i.decode_string();
279 bufferlist bl;
280 i.decode_bl(bl);
281 f->dump_string("op_name", "collection_setattr");
282 f->dump_stream("collection") << cid;
283 f->dump_string("name", name);
284 f->dump_unsigned("length", bl.length());
285 }
286 break;
287
288 case Transaction::OP_COLL_RMATTR:
289 {
290 coll_t cid = i.get_cid(op->cid);
291 string name = i.decode_string();
292 f->dump_string("op_name", "collection_rmattr");
293 f->dump_stream("collection") << cid;
294 f->dump_string("name", name);
295 }
296 break;
297
298 case Transaction::OP_COLL_RENAME:
299 {
300 f->dump_string("op_name", "collection_rename");
301 }
302 break;
303
304 case Transaction::OP_OMAP_CLEAR:
305 {
306 coll_t cid = i.get_cid(op->cid);
307 ghobject_t oid = i.get_oid(op->oid);
308 f->dump_string("op_name", "omap_clear");
309 f->dump_stream("collection") << cid;
310 f->dump_stream("oid") << oid;
311 }
312 break;
313
314 case Transaction::OP_OMAP_SETKEYS:
315 {
316 coll_t cid = i.get_cid(op->cid);
317 ghobject_t oid = i.get_oid(op->oid);
318 map<string, bufferlist> aset;
319 i.decode_attrset(aset);
320 f->dump_string("op_name", "omap_setkeys");
321 f->dump_stream("collection") << cid;
322 f->dump_stream("oid") << oid;
323 f->open_object_section("attr_lens");
324 for (map<string, bufferlist>::iterator p = aset.begin();
325 p != aset.end(); ++p) {
326 f->dump_unsigned(p->first.c_str(), p->second.length());
327 }
328 f->close_section();
329 }
330 break;
331
332 case Transaction::OP_OMAP_RMKEYS:
333 {
334 coll_t cid = i.get_cid(op->cid);
335 ghobject_t oid = i.get_oid(op->oid);
336 set<string> keys;
337 i.decode_keyset(keys);
338 f->dump_string("op_name", "omap_rmkeys");
339 f->dump_stream("collection") << cid;
340 f->dump_stream("oid") << oid;
341 f->open_array_section("attrs");
342 for (auto& k : keys) {
343 f->dump_string("", k.c_str());
344 }
345 f->close_section();
346 }
347 break;
348
349 case Transaction::OP_OMAP_SETHEADER:
350 {
351 coll_t cid = i.get_cid(op->cid);
352 ghobject_t oid = i.get_oid(op->oid);
353 bufferlist bl;
354 i.decode_bl(bl);
355 f->dump_string("op_name", "omap_setheader");
356 f->dump_stream("collection") << cid;
357 f->dump_stream("oid") << oid;
358 f->dump_stream("header_length") << bl.length();
359 }
360 break;
361
362 case Transaction::OP_SPLIT_COLLECTION:
363 {
364 coll_t cid = i.get_cid(op->cid);
365 uint32_t bits = op->split_bits;
366 uint32_t rem = op->split_rem;
367 coll_t dest = i.get_cid(op->dest_cid);
368 f->dump_string("op_name", "op_split_collection_create");
369 f->dump_stream("collection") << cid;
370 f->dump_stream("bits") << bits;
371 f->dump_stream("rem") << rem;
372 f->dump_stream("dest") << dest;
373 }
374 break;
375
376 case Transaction::OP_SPLIT_COLLECTION2:
377 {
378 coll_t cid = i.get_cid(op->cid);
379 uint32_t bits = op->split_bits;
380 uint32_t rem = op->split_rem;
381 coll_t dest = i.get_cid(op->dest_cid);
382 f->dump_string("op_name", "op_split_collection");
383 f->dump_stream("collection") << cid;
384 f->dump_stream("bits") << bits;
385 f->dump_stream("rem") << rem;
386 f->dump_stream("dest") << dest;
387 }
388 break;
389
390 case Transaction::OP_MERGE_COLLECTION:
391 {
392 coll_t cid = i.get_cid(op->cid);
393 uint32_t bits = op->split_bits;
394 coll_t dest = i.get_cid(op->dest_cid);
395 f->dump_string("op_name", "op_merge_collection");
396 f->dump_stream("collection") << cid;
397 f->dump_stream("dest") << dest;
398 f->dump_stream("bits") << bits;
399 }
400 break;
401
402 case Transaction::OP_OMAP_RMKEYRANGE:
403 {
404 coll_t cid = i.get_cid(op->cid);
405 ghobject_t oid = i.get_oid(op->oid);
406 string first, last;
407 first = i.decode_string();
408 last = i.decode_string();
409 f->dump_string("op_name", "op_omap_rmkeyrange");
410 f->dump_stream("collection") << cid;
411 f->dump_stream("oid") << oid;
412 f->dump_string("first", first);
413 f->dump_string("last", last);
414 }
415 break;
416
417 case Transaction::OP_COLL_MOVE_RENAME:
418 {
419 coll_t old_cid = i.get_cid(op->cid);
420 ghobject_t old_oid = i.get_oid(op->oid);
421 coll_t new_cid = i.get_cid(op->dest_cid);
422 ghobject_t new_oid = i.get_oid(op->dest_oid);
423 f->dump_string("op_name", "op_coll_move_rename");
424 f->dump_stream("old_collection") << old_cid;
425 f->dump_stream("old_oid") << old_oid;
426 f->dump_stream("new_collection") << new_cid;
427 f->dump_stream("new_oid") << new_oid;
428 }
429 break;
430
431 case Transaction::OP_TRY_RENAME:
432 {
433 coll_t cid = i.get_cid(op->cid);
434 ghobject_t old_oid = i.get_oid(op->oid);
435 ghobject_t new_oid = i.get_oid(op->dest_oid);
436 f->dump_string("op_name", "op_coll_move_rename");
437 f->dump_stream("collection") << cid;
438 f->dump_stream("old_oid") << old_oid;
439 f->dump_stream("new_oid") << new_oid;
440 }
441 break;
442
443 case Transaction::OP_SETALLOCHINT:
444 {
445 coll_t cid = i.get_cid(op->cid);
446 ghobject_t oid = i.get_oid(op->oid);
447 uint64_t expected_object_size = op->expected_object_size;
448 uint64_t expected_write_size = op->expected_write_size;
449 f->dump_string("op_name", "op_setallochint");
450 f->dump_stream("collection") << cid;
451 f->dump_stream("oid") << oid;
452 f->dump_stream("expected_object_size") << expected_object_size;
453 f->dump_stream("expected_write_size") << expected_write_size;
454 }
455 break;
456
457 default:
458 f->dump_string("op_name", "unknown");
459 f->dump_unsigned("op_code", op->op);
460 stop_looping = true;
461 break;
462 }
463 f->close_section();
464 op_num++;
465 }
466 f->close_section();
467 }
468
469 #pragma GCC diagnostic ignored "-Wpragmas"
470 #pragma GCC diagnostic push
471 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
472
473 void ObjectStore::Transaction::generate_test_instances(list<ObjectStore::Transaction*>& o)
474 {
475 o.push_back(new Transaction);
476
477 Transaction *t = new Transaction;
478 t->nop();
479 o.push_back(t);
480
481 t = new Transaction;
482 coll_t c(spg_t(pg_t(1,2), shard_id_t::NO_SHARD));
483 coll_t c2(spg_t(pg_t(4,5), shard_id_t::NO_SHARD));
484 ghobject_t o1(hobject_t("obj", "", 123, 456, -1, ""));
485 ghobject_t o2(hobject_t("obj2", "", 123, 456, -1, ""));
486 ghobject_t o3(hobject_t("obj3", "", 123, 456, -1, ""));
487 t->touch(c, o1);
488 bufferlist bl;
489 bl.append("some data");
490 t->write(c, o1, 1, bl.length(), bl);
491 t->zero(c, o1, 22, 33);
492 t->truncate(c, o1, 99);
493 t->remove(c, o1);
494 o.push_back(t);
495
496 t = new Transaction;
497 t->setattr(c, o1, "key", bl);
498 map<string,bufferptr> m;
499 m["a"] = buffer::copy("this", 4);
500 m["b"] = buffer::copy("that", 4);
501 t->setattrs(c, o1, m);
502 t->rmattr(c, o1, "b");
503 t->rmattrs(c, o1);
504
505 t->clone(c, o1, o2);
506 t->clone(c, o1, o3);
507 t->clone_range(c, o1, o2, 1, 12, 99);
508
509 t->create_collection(c, 12);
510 t->collection_move_rename(c, o2, c2, o3);
511 t->remove_collection(c);
512 o.push_back(t);
513 }
514
515 #pragma GCC diagnostic pop
516 #pragma GCC diagnostic warning "-Wpragmas"