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:
203 coll_t cid = i.get_cid(op->cid);
204 uint32_t type = op->hint_type;
205 f->dump_string("op_name", "coll_hint");
206 f->dump_stream("collection") << cid;
207 f->dump_unsigned("type", type);
210 bufferlist::iterator hiter = hint.begin();
211 if (type == Transaction::COLL_HINT_EXPECTED_NUM_OBJECTS) {
214 ::decode(pg_num, hiter);
215 ::decode(num_objs, hiter);
216 f->dump_unsigned("pg_num", pg_num);
217 f->dump_unsigned("expected_num_objects", num_objs);
222 case Transaction::OP_COLL_SET_BITS:
224 coll_t cid = i.get_cid(op->cid);
225 f->dump_string("op_name", "coll_set_bits");
226 f->dump_stream("collection") << cid;
227 f->dump_unsigned("bits", op->split_bits);
231 case Transaction::OP_RMCOLL:
233 coll_t cid = i.get_cid(op->cid);
234 f->dump_string("op_name", "rmcoll");
235 f->dump_stream("collection") << cid;
239 case Transaction::OP_COLL_ADD:
241 coll_t ocid = i.get_cid(op->cid);
242 coll_t ncid = i.get_cid(op->dest_cid);
243 ghobject_t oid = i.get_oid(op->oid);
244 f->dump_string("op_name", "collection_add");
245 f->dump_stream("src_collection") << ocid;
246 f->dump_stream("dst_collection") << ncid;
247 f->dump_stream("oid") << oid;
251 case Transaction::OP_COLL_REMOVE:
253 coll_t cid = i.get_cid(op->cid);
254 ghobject_t oid = i.get_oid(op->oid);
255 f->dump_string("op_name", "collection_remove");
256 f->dump_stream("collection") << cid;
257 f->dump_stream("oid") << oid;
261 case Transaction::OP_COLL_MOVE:
263 coll_t ocid = i.get_cid(op->cid);
264 coll_t ncid = i.get_cid(op->dest_cid);
265 ghobject_t oid = i.get_oid(op->oid);
266 f->open_object_section("collection_move");
267 f->dump_stream("src_collection") << ocid;
268 f->dump_stream("dst_collection") << ncid;
269 f->dump_stream("oid") << oid;
274 case Transaction::OP_COLL_SETATTR:
276 coll_t cid = i.get_cid(op->cid);
277 string name = i.decode_string();
280 f->dump_string("op_name", "collection_setattr");
281 f->dump_stream("collection") << cid;
282 f->dump_string("name", name);
283 f->dump_unsigned("length", bl.length());
287 case Transaction::OP_COLL_RMATTR:
289 coll_t cid = i.get_cid(op->cid);
290 string name = i.decode_string();
291 f->dump_string("op_name", "collection_rmattr");
292 f->dump_stream("collection") << cid;
293 f->dump_string("name", name);
297 case Transaction::OP_STARTSYNC:
298 f->dump_string("op_name", "startsync");
301 case Transaction::OP_COLL_RENAME:
303 f->dump_string("op_name", "collection_rename");
307 case Transaction::OP_OMAP_CLEAR:
309 coll_t cid = i.get_cid(op->cid);
310 ghobject_t oid = i.get_oid(op->oid);
311 f->dump_string("op_name", "omap_clear");
312 f->dump_stream("collection") << cid;
313 f->dump_stream("oid") << oid;
317 case Transaction::OP_OMAP_SETKEYS:
319 coll_t cid = i.get_cid(op->cid);
320 ghobject_t oid = i.get_oid(op->oid);
321 map<string, bufferlist> aset;
322 i.decode_attrset(aset);
323 f->dump_string("op_name", "omap_setkeys");
324 f->dump_stream("collection") << cid;
325 f->dump_stream("oid") << oid;
326 f->open_object_section("attr_lens");
327 for (map<string, bufferlist>::iterator p = aset.begin();
328 p != aset.end(); ++p) {
329 f->dump_unsigned(p->first.c_str(), p->second.length());
335 case Transaction::OP_OMAP_RMKEYS:
337 coll_t cid = i.get_cid(op->cid);
338 ghobject_t oid = i.get_oid(op->oid);
340 i.decode_keyset(keys);
341 f->dump_string("op_name", "omap_rmkeys");
342 f->dump_stream("collection") << cid;
343 f->dump_stream("oid") << oid;
347 case Transaction::OP_OMAP_SETHEADER:
349 coll_t cid = i.get_cid(op->cid);
350 ghobject_t oid = i.get_oid(op->oid);
353 f->dump_string("op_name", "omap_setheader");
354 f->dump_stream("collection") << cid;
355 f->dump_stream("oid") << oid;
356 f->dump_stream("header_length") << bl.length();
360 case Transaction::OP_SPLIT_COLLECTION:
362 coll_t cid = i.get_cid(op->cid);
363 uint32_t bits = op->split_bits;
364 uint32_t rem = op->split_rem;
365 coll_t dest = i.get_cid(op->dest_cid);
366 f->dump_string("op_name", "op_split_collection_create");
367 f->dump_stream("collection") << cid;
368 f->dump_stream("bits") << bits;
369 f->dump_stream("rem") << rem;
370 f->dump_stream("dest") << dest;
374 case Transaction::OP_SPLIT_COLLECTION2:
376 coll_t cid = i.get_cid(op->cid);
377 uint32_t bits = op->split_bits;
378 uint32_t rem = op->split_rem;
379 coll_t dest = i.get_cid(op->dest_cid);
380 f->dump_string("op_name", "op_split_collection");
381 f->dump_stream("collection") << cid;
382 f->dump_stream("bits") << bits;
383 f->dump_stream("rem") << rem;
384 f->dump_stream("dest") << dest;
388 case Transaction::OP_OMAP_RMKEYRANGE:
390 coll_t cid = i.get_cid(op->cid);
391 ghobject_t oid = i.get_oid(op->oid);
393 first = i.decode_string();
394 last = i.decode_string();
395 f->dump_string("op_name", "op_omap_rmkeyrange");
396 f->dump_stream("collection") << cid;
397 f->dump_stream("oid") << oid;
398 f->dump_string("first", first);
399 f->dump_string("last", last);
403 case Transaction::OP_COLL_MOVE_RENAME:
405 coll_t old_cid = i.get_cid(op->cid);
406 ghobject_t old_oid = i.get_oid(op->oid);
407 coll_t new_cid = i.get_cid(op->dest_cid);
408 ghobject_t new_oid = i.get_oid(op->dest_oid);
409 f->dump_string("op_name", "op_coll_move_rename");
410 f->dump_stream("old_collection") << old_cid;
411 f->dump_stream("old_oid") << old_oid;
412 f->dump_stream("new_collection") << new_cid;
413 f->dump_stream("new_oid") << new_oid;
417 case Transaction::OP_TRY_RENAME:
419 coll_t cid = i.get_cid(op->cid);
420 ghobject_t old_oid = i.get_oid(op->oid);
421 ghobject_t new_oid = i.get_oid(op->dest_oid);
422 f->dump_string("op_name", "op_coll_move_rename");
423 f->dump_stream("collection") << cid;
424 f->dump_stream("old_oid") << old_oid;
425 f->dump_stream("new_oid") << new_oid;
429 case Transaction::OP_SETALLOCHINT:
431 coll_t cid = i.get_cid(op->cid);
432 ghobject_t oid = i.get_oid(op->oid);
433 uint64_t expected_object_size = op->expected_object_size;
434 uint64_t expected_write_size = op->expected_write_size;
435 f->dump_string("op_name", "op_setallochint");
436 f->dump_stream("collection") << cid;
437 f->dump_stream("oid") << oid;
438 f->dump_stream("expected_object_size") << expected_object_size;
439 f->dump_stream("expected_write_size") << expected_write_size;
444 f->dump_string("op_name", "unknown");
445 f->dump_unsigned("op_code", op->op);
455 #pragma GCC diagnostic ignored "-Wpragmas"
456 #pragma GCC diagnostic push
457 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
459 void ObjectStore::Transaction::generate_test_instances(list<ObjectStore::Transaction*>& o)
461 o.push_back(new Transaction);
463 Transaction *t = new Transaction;
468 coll_t c(spg_t(pg_t(1,2), shard_id_t::NO_SHARD));
469 coll_t c2(spg_t(pg_t(4,5), shard_id_t::NO_SHARD));
470 ghobject_t o1(hobject_t("obj", "", 123, 456, -1, ""));
471 ghobject_t o2(hobject_t("obj2", "", 123, 456, -1, ""));
472 ghobject_t o3(hobject_t("obj3", "", 123, 456, -1, ""));
475 bl.append("some data");
476 t->write(c, o1, 1, bl.length(), bl);
477 t->zero(c, o1, 22, 33);
478 t->truncate(c, o1, 99);
483 t->setattr(c, o1, "key", bl);
484 map<string,bufferptr> m;
485 m["a"] = buffer::copy("this", 4);
486 m["b"] = buffer::copy("that", 4);
487 t->setattrs(c, o1, m);
488 t->rmattr(c, o1, "b");
493 t->clone_range(c, o1, o2, 1, 12, 99);
495 t->create_collection(c, 12);
496 t->collection_move_rename(c, o2, c2, o3);
497 t->remove_collection(c);
501 #pragma GCC diagnostic pop
502 #pragma GCC diagnostic warning "-Wpragmas"