summaryrefslogtreecommitdiffstats
path: root/src/test/librados/list.cc
blob: 829890c1ad9058c955bea0af3eab8ce882048de5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
#include "include/rados/librados.h"
#include "include/rados/librados.hpp"
#include "include/stringify.h"
#include "test/librados/test.h"
#include "test/librados/test_common.h"
#include "test/librados/TestCase.h"
#include "global/global_context.h"

#include "include/types.h"
#include "common/hobject.h"
#include "gtest/gtest.h"
#include <errno.h>
#include <string>
#include <stdexcept>

using namespace librados;

typedef RadosTestNSCleanup LibRadosList;
typedef RadosTestECNSCleanup LibRadosListEC;
typedef RadosTestNP LibRadosListNP;


TEST_F(LibRadosList, ListObjects) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));
  ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
  rados_list_ctx_t ctx;
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  const char *entry;
  bool foundit = false;
  while (rados_nobjects_list_next(ctx, &entry, NULL, NULL) != -ENOENT) {
    foundit = true;
    ASSERT_EQ(std::string(entry), "foo");
  }
  ASSERT_TRUE(foundit);
  rados_nobjects_list_close(ctx);
}

TEST_F(LibRadosList, ListObjectsZeroInName) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));
  ASSERT_EQ(0, rados_write(ioctx, "foo\0bar", buf, sizeof(buf), 0));
  rados_list_ctx_t ctx;
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  const char *entry;
  size_t entry_size;
  bool foundit = false;
  while (rados_nobjects_list_next2(ctx, &entry, NULL, NULL,
				   &entry_size, NULL, NULL) != -ENOENT) {
    foundit = true;
    ASSERT_EQ(std::string(entry, entry_size), "foo\0bar");
  }
  ASSERT_TRUE(foundit);
  rados_nobjects_list_close(ctx);
}

static void check_list(
  std::set<std::string>& myset,
  rados_list_ctx_t& ctx,
  const std::string &check_nspace)
{
  const char *entry, *nspace;
  cout << "myset " << myset << std::endl;
  // we should see every item exactly once.
  int ret;
  while ((ret = rados_nobjects_list_next(ctx, &entry, NULL, &nspace)) == 0) {
    std::string test_name;
    if (check_nspace == all_nspaces) {
      test_name = std::string(nspace) + ":" + std::string(entry);
    } else {
      ASSERT_TRUE(std::string(nspace) == check_nspace);
      test_name = std::string(entry);
    }
    cout << test_name << std::endl;

    ASSERT_TRUE(myset.end() != myset.find(test_name));
    myset.erase(test_name);
  }
  ASSERT_EQ(-ENOENT, ret);
  ASSERT_TRUE(myset.empty());
}

TEST_F(LibRadosList, ListObjectsNS) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));
  // Create :foo1, :foo2, :foo3, n1:foo1, ns1:foo4, ns1:foo5, ns2:foo6, n2:foo7
  rados_ioctx_set_namespace(ioctx, "");
  ASSERT_EQ(0, rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "ns1");
  ASSERT_EQ(0, rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "");
  ASSERT_EQ(0, rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
  ASSERT_EQ(0, rados_write(ioctx, "foo3", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "ns1");
  ASSERT_EQ(0, rados_write(ioctx, "foo4", buf, sizeof(buf), 0));
  ASSERT_EQ(0, rados_write(ioctx, "foo5", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "ns2");
  ASSERT_EQ(0, rados_write(ioctx, "foo6", buf, sizeof(buf), 0));
  ASSERT_EQ(0, rados_write(ioctx, "foo7", buf, sizeof(buf), 0));

  char nspace[4];
  ASSERT_EQ(-ERANGE, rados_ioctx_get_namespace(ioctx, nspace, 3));
  ASSERT_EQ(static_cast<int>(strlen("ns2")),
	    rados_ioctx_get_namespace(ioctx, nspace, sizeof(nspace)));
  ASSERT_EQ(0, strcmp("ns2", nspace));

  std::set<std::string> def, ns1, ns2, all;
  def.insert(std::string("foo1"));
  def.insert(std::string("foo2"));
  def.insert(std::string("foo3"));
  ns1.insert(std::string("foo1"));
  ns1.insert(std::string("foo4"));
  ns1.insert(std::string("foo5"));
  ns2.insert(std::string("foo6"));
  ns2.insert(std::string("foo7"));
  all.insert(std::string(":foo1"));
  all.insert(std::string(":foo2"));
  all.insert(std::string(":foo3"));
  all.insert(std::string("ns1:foo1"));
  all.insert(std::string("ns1:foo4"));
  all.insert(std::string("ns1:foo5"));
  all.insert(std::string("ns2:foo6"));
  all.insert(std::string("ns2:foo7"));

  rados_list_ctx_t ctx;
  // Check default namespace ""
  rados_ioctx_set_namespace(ioctx, "");
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(def, ctx, "");
  rados_nobjects_list_close(ctx);

  // Check namespace "ns1"
  rados_ioctx_set_namespace(ioctx, "ns1");
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(ns1, ctx, "ns1");
  rados_nobjects_list_close(ctx);

  // Check namespace "ns2"
  rados_ioctx_set_namespace(ioctx, "ns2");
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(ns2, ctx, "ns2");
  rados_nobjects_list_close(ctx);

  // Check ALL namespaces
  rados_ioctx_set_namespace(ioctx, LIBRADOS_ALL_NSPACES);
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(all, ctx, all_nspaces);
  rados_nobjects_list_close(ctx);
}


TEST_F(LibRadosList, ListObjectsStart) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));

  for (int i=0; i<16; ++i) {
    string n = stringify(i);
    ASSERT_EQ(0, rados_write(ioctx, n.c_str(), buf, sizeof(buf), 0));
  }

  rados_list_ctx_t ctx;
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  std::map<int, std::set<std::string> > pg_to_obj;
  const char *entry;
  while (rados_nobjects_list_next(ctx, &entry, NULL, NULL) == 0) {
    uint32_t pos = rados_nobjects_list_get_pg_hash_position(ctx);
    std::cout << entry << " " << pos << std::endl;
    pg_to_obj[pos].insert(entry);
  }
  rados_nobjects_list_close(ctx);

  std::map<int, std::set<std::string> >::reverse_iterator p =
    pg_to_obj.rbegin();
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  while (p != pg_to_obj.rend()) {
    ASSERT_EQ((uint32_t)p->first, rados_nobjects_list_seek(ctx, p->first));
    ASSERT_EQ(0, rados_nobjects_list_next(ctx, &entry, NULL, NULL));
    std::cout << "have " << entry << " expect one of " << p->second << std::endl;
    ASSERT_TRUE(p->second.count(entry));
    ++p;
  }
  rados_nobjects_list_close(ctx);
}

// this function replicates
// librados::operator<<(std::ostream& os, const librados::ObjectCursor& oc)
// because we don't want to use librados in librados client.
std::ostream& operator<<(std::ostream&os, const rados_object_list_cursor& oc)
{
  if (oc) {
    os << *(hobject_t *)oc;
  } else {
    os << hobject_t{};
  }
  return os;
}

TEST_F(LibRadosList, ListObjectsCursor) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));

  const int max_objs = 16;

  for (int i=0; i<max_objs; ++i) {
    string n = stringify(i);
    ASSERT_EQ(0, rados_write(ioctx, n.c_str(), buf, sizeof(buf), 0));
  }

  {
    rados_list_ctx_t ctx;
    const char *entry;
    rados_object_list_cursor cursor;
    ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
    ASSERT_EQ(rados_nobjects_list_get_cursor(ctx, &cursor), 0);
    rados_object_list_cursor first_cursor = cursor;
    cout << "x cursor=" << cursor << std::endl;
    while (rados_nobjects_list_next(ctx, &entry, NULL, NULL) == 0) {
      string oid = entry;
      ASSERT_EQ(rados_nobjects_list_get_cursor(ctx, &cursor), 0);
      cout << "> oid=" << oid << " cursor=" << cursor << std::endl;
    }
    rados_nobjects_list_seek_cursor(ctx, first_cursor);
    ASSERT_EQ(rados_nobjects_list_next(ctx, &entry, NULL, NULL), 0);
    cout << "FIRST> seek to " << first_cursor << " oid=" << string(entry) << std::endl;
  }
  rados_list_ctx_t ctx;
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));

  std::map<rados_object_list_cursor, string> cursor_to_obj;
  int count = 0;

  const char *entry;
  while (rados_nobjects_list_next(ctx, &entry, NULL, NULL) == 0) {
    rados_object_list_cursor cursor;
    ASSERT_EQ(rados_nobjects_list_get_cursor(ctx, &cursor), 0);
    string oid = entry;
    cout << ": oid=" << oid << " cursor=" << cursor << std::endl;
    cursor_to_obj[cursor] = oid;

    rados_nobjects_list_seek_cursor(ctx, cursor);
    cout << ": seek to " << cursor << std::endl;
    ASSERT_EQ(rados_nobjects_list_next(ctx, &entry, NULL, NULL), 0);
    cout << "> " << cursor << " -> " << entry << std::endl;
    ASSERT_EQ(string(entry), oid);
    ASSERT_LT(count, max_objs); /* avoid infinite loops due to bad seek */

    ++count;
  }

  ASSERT_EQ(count, max_objs);

  auto p = cursor_to_obj.rbegin();
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  while (p != cursor_to_obj.rend()) {
    cout << ": seek to " << p->first << std::endl;
    rados_object_list_cursor cursor;
    rados_object_list_cursor oid(p->first);
    rados_nobjects_list_seek_cursor(ctx, oid);
    ASSERT_EQ(rados_nobjects_list_get_cursor(ctx, &cursor), 0);
    cout << ": cursor()=" << cursor << " expected=" << oid << std::endl;
    // ASSERT_EQ(ObjectCursor(oid), ObjectCursor(cursor));
    ASSERT_EQ(rados_nobjects_list_next(ctx, &entry, NULL, NULL), 0);
    cout << "> " << cursor << " -> " << entry << std::endl;
    cout << ": entry=" << entry << " expected=" << p->second << std::endl;
    ASSERT_EQ(p->second, string(entry));

    ++p;

    rados_object_list_cursor_free(ctx, cursor);
  }
}

TEST_F(LibRadosListEC, ListObjects) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));
  ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));
  rados_list_ctx_t ctx;
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  const char *entry;
  bool foundit = false;
  while (rados_nobjects_list_next(ctx, &entry, NULL, NULL) != -ENOENT) {
    foundit = true;
    ASSERT_EQ(std::string(entry), "foo");
  }
  ASSERT_TRUE(foundit);
  rados_nobjects_list_close(ctx);
}

TEST_F(LibRadosListEC, ListObjectsNS) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));
  // Create :foo1, :foo2, :foo3, n1:foo1, ns1:foo4, ns1:foo5, ns2:foo6, n2:foo7
  rados_ioctx_set_namespace(ioctx, "");
  ASSERT_EQ(0, rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "ns1");
  ASSERT_EQ(0, rados_write(ioctx, "foo1", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "");
  ASSERT_EQ(0, rados_write(ioctx, "foo2", buf, sizeof(buf), 0));
  ASSERT_EQ(0, rados_write(ioctx, "foo3", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "ns1");
  ASSERT_EQ(0, rados_write(ioctx, "foo4", buf, sizeof(buf), 0));
  ASSERT_EQ(0, rados_write(ioctx, "foo5", buf, sizeof(buf), 0));
  rados_ioctx_set_namespace(ioctx, "ns2");
  ASSERT_EQ(0, rados_write(ioctx, "foo6", buf, sizeof(buf), 0));
  ASSERT_EQ(0, rados_write(ioctx, "foo7", buf, sizeof(buf), 0));

  std::set<std::string> def, ns1, ns2, all;
  def.insert(std::string("foo1"));
  def.insert(std::string("foo2"));
  def.insert(std::string("foo3"));
  ns1.insert(std::string("foo1"));
  ns1.insert(std::string("foo4"));
  ns1.insert(std::string("foo5"));
  ns2.insert(std::string("foo6"));
  ns2.insert(std::string("foo7"));
  all.insert(std::string(":foo1"));
  all.insert(std::string(":foo2"));
  all.insert(std::string(":foo3"));
  all.insert(std::string("ns1:foo1"));
  all.insert(std::string("ns1:foo4"));
  all.insert(std::string("ns1:foo5"));
  all.insert(std::string("ns2:foo6"));
  all.insert(std::string("ns2:foo7"));

  rados_list_ctx_t ctx;
  // Check default namespace ""
  rados_ioctx_set_namespace(ioctx, "");
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(def, ctx, "");
  rados_nobjects_list_close(ctx);

  // Check default namespace "ns1"
  rados_ioctx_set_namespace(ioctx, "ns1");
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(ns1, ctx, "ns1");
  rados_nobjects_list_close(ctx);

  // Check default namespace "ns2"
  rados_ioctx_set_namespace(ioctx, "ns2");
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(ns2, ctx, "ns2");
  rados_nobjects_list_close(ctx);

  // Check all namespaces
  rados_ioctx_set_namespace(ioctx, LIBRADOS_ALL_NSPACES);
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  check_list(all, ctx, all_nspaces);
  rados_nobjects_list_close(ctx);
}


TEST_F(LibRadosListEC, ListObjectsStart) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));

  for (int i=0; i<16; ++i) {
    string n = stringify(i);
    ASSERT_EQ(0, rados_write(ioctx, n.c_str(), buf, sizeof(buf), 0));
  }

  rados_list_ctx_t ctx;
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  std::map<int, std::set<std::string> > pg_to_obj;
  const char *entry;
  while (rados_nobjects_list_next(ctx, &entry, NULL, NULL) == 0) {
    uint32_t pos = rados_nobjects_list_get_pg_hash_position(ctx);
    std::cout << entry << " " << pos << std::endl;
    pg_to_obj[pos].insert(entry);
  }
  rados_nobjects_list_close(ctx);

  std::map<int, std::set<std::string> >::reverse_iterator p =
    pg_to_obj.rbegin();
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  while (p != pg_to_obj.rend()) {
    ASSERT_EQ((uint32_t)p->first, rados_nobjects_list_seek(ctx, p->first));
    ASSERT_EQ(0, rados_nobjects_list_next(ctx, &entry, NULL, NULL));
    std::cout << "have " << entry << " expect one of " << p->second << std::endl;
    ASSERT_TRUE(p->second.count(entry));
    ++p;
  }
  rados_nobjects_list_close(ctx);
}

TEST_F(LibRadosListNP, ListObjectsError) {
  std::string pool_name;
  rados_t cluster;
  rados_ioctx_t ioctx;
  pool_name = get_temp_pool_name();
  ASSERT_EQ("", create_one_pool(pool_name, &cluster));
  ASSERT_EQ(0, rados_ioctx_create(cluster, pool_name.c_str(), &ioctx));
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));
  rados_ioctx_set_namespace(ioctx, "");
  ASSERT_EQ(0, rados_write(ioctx, "foo", buf, sizeof(buf), 0));

  //ASSERT_EQ(0, rados_pool_delete(cluster, pool_name.c_str()));
  {
    char *buf, *st;
    size_t buflen, stlen;
    string c = "{\"prefix\":\"osd pool rm\",\"pool\": \"" + pool_name +
      "\",\"pool2\":\"" + pool_name +
      "\",\"yes_i_really_really_mean_it_not_faking\": true}";
    const char *cmd[2] = { c.c_str(), 0 };
    ASSERT_EQ(0, rados_mon_command(cluster, (const char **)cmd, 1, "", 0, &buf, &buflen, &st, &stlen));
    ASSERT_EQ(0, rados_wait_for_latest_osdmap(cluster));
  }

  rados_list_ctx_t ctx;
  ASSERT_EQ(0, rados_nobjects_list_open(ioctx, &ctx));
  const char *entry;
  ASSERT_EQ(-ENOENT, rados_nobjects_list_next(ctx, &entry, NULL, NULL));
  rados_nobjects_list_close(ctx);
  rados_ioctx_destroy(ioctx);
  rados_shutdown(cluster);
}



// ---------------------------------------------

TEST_F(LibRadosList, EnumerateObjects) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));

  const uint32_t n_objects = 16;
  for (unsigned i=0; i<n_objects; ++i) {
    ASSERT_EQ(0, rados_write(ioctx, stringify(i).c_str(), buf, sizeof(buf), 0));
  }

  // Ensure a non-power-of-two PG count to avoid only
  // touching the easy path.
  ASSERT_TRUE(set_pg_num(&s_cluster, pool_name, 11).empty());
  ASSERT_TRUE(set_pgp_num(&s_cluster, pool_name, 11).empty());

  std::set<std::string> saw_obj;
  rados_object_list_cursor c = rados_object_list_begin(ioctx);
  rados_object_list_cursor end = rados_object_list_end(ioctx);
  while(!rados_object_list_is_end(ioctx, c))
  {
    rados_object_list_item results[12];
    memset(results, 0, sizeof(rados_object_list_item) * 12);
    rados_object_list_cursor temp_end = rados_object_list_end(ioctx);
    int r = rados_object_list(ioctx, c, temp_end,
            12, NULL, 0, results, &c);
    rados_object_list_cursor_free(ioctx, temp_end);
    ASSERT_GE(r, 0);
    for (int i = 0; i < r; ++i) {
      std::string oid(results[i].oid, results[i].oid_length);
      if (saw_obj.count(oid)) {
          std::cerr << "duplicate obj " << oid << std::endl;
      }
      ASSERT_FALSE(saw_obj.count(oid));
      saw_obj.insert(oid);
    }
    rados_object_list_free(12, results);
  }
  rados_object_list_cursor_free(ioctx, c);
  rados_object_list_cursor_free(ioctx, end);

  for (unsigned i=0; i<n_objects; ++i) {
    if (!saw_obj.count(stringify(i))) {
        std::cerr << "missing object " << i << std::endl;
    }
    ASSERT_TRUE(saw_obj.count(stringify(i)));
  }
  ASSERT_EQ(n_objects, saw_obj.size());
}

TEST_F(LibRadosList, EnumerateObjectsSplit) {
  char buf[128];
  memset(buf, 0xcc, sizeof(buf));

  const uint32_t n_objects = 16;
  for (unsigned i=0; i<n_objects; ++i) {
    ASSERT_EQ(0, rados_write(ioctx, stringify(i).c_str(), buf, sizeof(buf), 0));
  }

  // Ensure a non-power-of-two PG count to avoid only
  // touching the easy path.
  ASSERT_TRUE(set_pg_num(&s_cluster, pool_name, 11).empty());
  ASSERT_TRUE(set_pgp_num(&s_cluster, pool_name, 11).empty());

  rados_object_list_cursor begin = rados_object_list_begin(ioctx);
  rados_object_list_cursor end = rados_object_list_end(ioctx);

  // Step through an odd number of shards
  unsigned m = 5;
  std::set<std::string> saw_obj;
  for (unsigned n = 0; n < m; ++n) {
      rados_object_list_cursor shard_start = rados_object_list_begin(ioctx);;
      rados_object_list_cursor shard_end = rados_object_list_end(ioctx);;

      rados_object_list_slice(
        ioctx,
        begin,
        end,
        n,
        m,
        &shard_start,
        &shard_end);
      std::cout << "split " << n << "/" << m << " -> "
		<< *(hobject_t*)shard_start << " "
		<< *(hobject_t*)shard_end << std::endl;

      rados_object_list_cursor c = shard_start;
      //while(c < shard_end)
      while(rados_object_list_cursor_cmp(ioctx, c, shard_end) == -1)
      {
        rados_object_list_item results[12];
        memset(results, 0, sizeof(rados_object_list_item) * 12);
        int r = rados_object_list(ioctx,
                c, shard_end,
                12, NULL, 0, results, &c);
        ASSERT_GE(r, 0);
        for (int i = 0; i < r; ++i) {
          std::string oid(results[i].oid, results[i].oid_length);
          if (saw_obj.count(oid)) {
              std::cerr << "duplicate obj " << oid << std::endl;
          }
          ASSERT_FALSE(saw_obj.count(oid));
          saw_obj.insert(oid);
        }
        rados_object_list_free(12, results);
      }
      rados_object_list_cursor_free(ioctx, shard_start);
      rados_object_list_cursor_free(ioctx, shard_end);
  }

  rados_object_list_cursor_free(ioctx, begin);
  rados_object_list_cursor_free(ioctx, end);

  for (unsigned i=0; i<n_objects; ++i) {
    if (!saw_obj.count(stringify(i))) {
        std::cerr << "missing object " << i << std::endl;
    }
    ASSERT_TRUE(saw_obj.count(stringify(i)));
  }
  ASSERT_EQ(n_objects, saw_obj.size());
}