1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "ObjectStore.h"
5 #include "common/Formatter.h"
7 void ObjectStore::Transaction::dump(ceph::Formatter
*f
)
9 f
->open_array_section("ops");
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
);
19 case Transaction::OP_NOP
:
20 f
->dump_string("op_name", "nop");
22 case Transaction::OP_TOUCH
:
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
;
32 case Transaction::OP_WRITE
:
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
;
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());
49 case Transaction::OP_ZERO
:
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
);
63 case Transaction::OP_TRIMCACHE
:
66 f
->dump_string("op_name", "trim_cache");
70 case Transaction::OP_TRUNCATE
:
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
);
82 case Transaction::OP_REMOVE
:
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
;
92 case Transaction::OP_SETATTR
:
94 coll_t cid
= i
.get_cid(op
->cid
);
95 ghobject_t oid
= i
.get_oid(op
->oid
);
96 string name
= i
.decode_string();
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());
107 case Transaction::OP_SETATTRS
:
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());
125 case Transaction::OP_RMATTR
:
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
);
137 case Transaction::OP_RMATTRS
:
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
;
147 case Transaction::OP_CLONE
:
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
;
159 case Transaction::OP_CLONERANGE
:
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
);
175 case Transaction::OP_CLONERANGE2
:
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
);
193 case Transaction::OP_MKCOLL
:
195 coll_t cid
= i
.get_cid(op
->cid
);
196 f
->dump_string("op_name", "mkcoll");
197 f
->dump_stream("collection") << cid
;
201 case Transaction::OP_COLL_HINT
:
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
);
211 auto hiter
= hint
.cbegin();
212 if (type
== Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS
) {
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
);
223 case Transaction::OP_COLL_SET_BITS
:
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
);
232 case Transaction::OP_RMCOLL
:
234 coll_t cid
= i
.get_cid(op
->cid
);
235 f
->dump_string("op_name", "rmcoll");
236 f
->dump_stream("collection") << cid
;
240 case Transaction::OP_COLL_ADD
:
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
;
252 case Transaction::OP_COLL_REMOVE
:
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
;
262 case Transaction::OP_COLL_MOVE
:
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
;
275 case Transaction::OP_COLL_SETATTR
:
277 coll_t cid
= i
.get_cid(op
->cid
);
278 string name
= i
.decode_string();
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());
288 case Transaction::OP_COLL_RMATTR
:
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
);
298 case Transaction::OP_COLL_RENAME
:
300 f
->dump_string("op_name", "collection_rename");
304 case Transaction::OP_OMAP_CLEAR
:
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
;
314 case Transaction::OP_OMAP_SETKEYS
:
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());
332 case Transaction::OP_OMAP_RMKEYS
:
334 coll_t cid
= i
.get_cid(op
->cid
);
335 ghobject_t oid
= i
.get_oid(op
->oid
);
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());
349 case Transaction::OP_OMAP_SETHEADER
:
351 coll_t cid
= i
.get_cid(op
->cid
);
352 ghobject_t oid
= i
.get_oid(op
->oid
);
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();
362 case Transaction::OP_SPLIT_COLLECTION
:
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
;
376 case Transaction::OP_SPLIT_COLLECTION2
:
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
;
390 case Transaction::OP_MERGE_COLLECTION
:
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
;
402 case Transaction::OP_OMAP_RMKEYRANGE
:
404 coll_t cid
= i
.get_cid(op
->cid
);
405 ghobject_t oid
= i
.get_oid(op
->oid
);
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
);
417 case Transaction::OP_COLL_MOVE_RENAME
:
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
;
431 case Transaction::OP_TRY_RENAME
:
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
;
443 case Transaction::OP_SETALLOCHINT
:
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
;
458 f
->dump_string("op_name", "unknown");
459 f
->dump_unsigned("op_code", op
->op
);
469 #pragma GCC diagnostic ignored "-Wpragmas"
470 #pragma GCC diagnostic push
471 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
473 void ObjectStore::Transaction::generate_test_instances(list
<ObjectStore::Transaction
*>& o
)
475 o
.push_back(new Transaction
);
477 Transaction
*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, ""));
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);
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");
507 t
->clone_range(c
, o1
, o2
, 1, 12, 99);
509 t
->create_collection(c
, 12);
510 t
->collection_move_rename(c
, o2
, c2
, o3
);
511 t
->remove_collection(c
);
515 #pragma GCC diagnostic pop
516 #pragma GCC diagnostic warning "-Wpragmas"