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) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "include/types.h"
16 #include "include/buffer.h"
17 #include "osd/osd_types.h"
20 #include "HashIndex.h"
22 #include "common/errno.h"
23 #include "common/debug.h"
24 #define dout_context cct
25 #define dout_subsys ceph_subsys_filestore
27 const string
HashIndex::SUBDIR_ATTR
= "contents";
28 const string
HashIndex::SETTINGS_ATTR
= "settings";
29 const string
HashIndex::IN_PROGRESS_OP_TAG
= "in_progress_op";
31 /// hex digit to integer value
32 int hex_to_int(char c
)
34 if (c
>= '0' && c
<= '9')
36 if (c
>= 'A' && c
<= 'F')
41 /// int value to hex digit
42 char int_to_hex(int v
)
50 /// reverse bits in a nibble (0..15)
51 int reverse_nibble_bits(int in
)
61 /// reverse nibble bits in a hex digit
62 char reverse_hexdigit_bits(char c
)
64 return int_to_hex(reverse_nibble_bits(hex_to_int(c
)));
67 /// reverse nibble bits in a hex string
68 string
reverse_hexdigit_bits_string(string s
)
70 for (unsigned i
=0; i
<s
.size(); ++i
)
71 s
[i
] = reverse_hexdigit_bits(s
[i
]);
75 /// compare hex digit (as length 1 string) bitwise
76 bool cmp_hexdigit_bitwise(const string
& l
, const string
& r
)
78 assert(l
.length() == 1 && r
.length() == 1);
79 int lv
= hex_to_int(l
[0]);
80 int rv
= hex_to_int(r
[0]);
83 return reverse_nibble_bits(lv
) < reverse_nibble_bits(rv
);
86 /// compare hex digit string bitwise
87 bool cmp_hexdigit_string_bitwise(const string
& l
, const string
& r
)
89 string ll
= reverse_hexdigit_bits_string(l
);
90 string rr
= reverse_hexdigit_bits_string(r
);
94 int HashIndex::cleanup() {
96 int r
= get_attr_path(vector
<string
>(), IN_PROGRESS_OP_TAG
, bl
);
98 // No in progress operations!
101 bufferlist::iterator i
= bl
.begin();
102 InProgressOp
in_progress(i
);
104 r
= get_info(in_progress
.path
, &info
);
106 return end_split_or_merge(in_progress
.path
);
111 if (in_progress
.is_split())
112 return complete_split(in_progress
.path
, info
);
113 else if (in_progress
.is_merge())
114 return complete_merge(in_progress
.path
, info
);
115 else if (in_progress
.is_col_split()) {
116 for (vector
<string
>::iterator i
= in_progress
.path
.begin();
117 i
!= in_progress
.path
.end();
119 vector
<string
> path(in_progress
.path
.begin(), i
);
120 int r
= reset_attr(path
);
130 int HashIndex::reset_attr(
131 const vector
<string
> &path
)
134 int r
= path_exists(path
, &exists
);
139 map
<string
, ghobject_t
> objects
;
140 vector
<string
> subdirs
;
141 r
= list_objects(path
, 0, 0, &objects
);
144 r
= list_subdirs(path
, &subdirs
);
149 info
.hash_level
= path
.size();
150 info
.objs
= objects
.size();
151 info
.subdirs
= subdirs
.size();
152 return set_info(path
, info
);
155 int HashIndex::col_split_level(
158 const vector
<string
> &path
,
163 /* For each subdir, move, recurse, or ignore based on comparing the low order
164 * bits of the hash represented by the subdir path with inbits, match passed
167 vector
<string
> subdirs
;
168 int r
= from
.list_subdirs(path
, &subdirs
);
171 map
<string
, ghobject_t
> objects
;
172 r
= from
.list_objects(path
, 0, 0, &objects
);
177 for (vector
<string
>::iterator i
= subdirs
.begin();
182 vector
<string
> sub_path(path
.begin(), path
.end());
183 sub_path
.push_back(*i
);
184 path_to_hobject_hash_prefix(sub_path
, &bits
, &hash
);
186 if (hobject_t::match_hash(hash
, bits
, match
)) {
196 if (*mkdirred
> path
.size())
197 *mkdirred
= path
.size();
198 } // else, skip, doesn't need to be moved or recursed into
200 if (hobject_t::match_hash(hash
, inbits
, match
)) {
203 } // else, skip, doesn't need to be moved or recursed into
206 /* Then, do the same for each object */
207 map
<string
, ghobject_t
> objs_to_move
;
208 for (map
<string
, ghobject_t
>::iterator i
= objects
.begin();
211 if (i
->second
.match(inbits
, match
)) {
212 objs_to_move
.insert(*i
);
216 if (objs_to_move
.empty() && to_move
.empty())
219 // Make parent directories as needed
220 while (*mkdirred
< path
.size()) {
223 vector
<string
> creating_path(path
.begin(), path
.begin()+*mkdirred
);
224 r
= to
.path_exists(creating_path
, &exists
);
232 info
.hash_level
= creating_path
.size();
233 if (*mkdirred
< path
.size() - 1)
235 r
= to
.start_col_split(creating_path
);
238 r
= to
.create_path(creating_path
);
241 r
= to
.set_info(creating_path
, info
);
244 r
= to
.end_split_or_merge(creating_path
);
249 subdir_info_s from_info
;
250 subdir_info_s to_info
;
251 r
= from
.get_info(path
, &from_info
);
254 r
= to
.get_info(path
, &to_info
);
258 from
.start_col_split(path
);
259 to
.start_col_split(path
);
262 for (set
<string
>::iterator i
= to_move
.begin();
267 r
= move_subdir(from
, to
, path
, *i
);
272 for (map
<string
, ghobject_t
>::iterator i
= objs_to_move
.begin();
273 i
!= objs_to_move
.end();
277 r
= move_object(from
, to
, path
, *i
);
283 r
= to
.set_info(path
, to_info
);
286 r
= from
.set_info(path
, from_info
);
289 from
.end_split_or_merge(path
);
290 to
.end_split_or_merge(path
);
294 int HashIndex::_split(
297 CollectionIndex
* dest
) {
298 assert(collection_version() == dest
->collection_version());
299 unsigned mkdirred
= 0;
300 return col_split_level(
302 *static_cast<HashIndex
*>(dest
),
309 int HashIndex::split_dirs(const vector
<string
> &path
) {
310 dout(20) << __func__
<< " " << path
<< dendl
;
312 int r
= get_info(path
, &info
);
314 dout(10) << "error looking up info for " << path
<< ": "
315 << cpp_strerror(r
) << dendl
;
319 if (must_split(info
)) {
320 dout(1) << __func__
<< " " << path
<< " has " << info
.objs
321 << " objects, starting split." << dendl
;
322 r
= initiate_split(path
, info
);
324 dout(10) << "error initiating split on " << path
<< ": "
325 << cpp_strerror(r
) << dendl
;
329 r
= complete_split(path
, info
);
330 dout(1) << __func__
<< " " << path
<< " split completed."
333 dout(10) << "error completing split on " << path
<< ": "
334 << cpp_strerror(r
) << dendl
;
339 vector
<string
> subdirs
;
340 r
= list_subdirs(path
, &subdirs
);
342 dout(10) << "error listing subdirs of " << path
<< ": "
343 << cpp_strerror(r
) << dendl
;
346 for (vector
<string
>::const_iterator it
= subdirs
.begin();
347 it
!= subdirs
.end(); ++it
) {
348 vector
<string
> subdir_path(path
);
349 subdir_path
.push_back(*it
);
350 r
= split_dirs(subdir_path
);
359 int HashIndex::apply_layout_settings() {
361 dout(10) << __func__
<< " split multiple = " << split_multiplier
362 << " merge threshold = " << merge_threshold
363 << " split rand factor = " << cct
->_conf
->filestore_split_rand_factor
365 int r
= write_settings();
368 return split_dirs(path
);
371 int HashIndex::_init() {
374 int r
= set_info(path
, info
);
377 return write_settings();
380 int HashIndex::write_settings() {
381 if (cct
->_conf
->filestore_split_rand_factor
> 0) {
382 settings
.split_rand_factor
= rand() % cct
->_conf
->filestore_split_rand_factor
;
384 settings
.split_rand_factor
= 0;
389 return add_attr_path(path
, SETTINGS_ATTR
, bl
);
392 int HashIndex::read_settings() {
395 int r
= get_attr_path(path
, SETTINGS_ATTR
, bl
);
399 derr
<< __func__
<< " error reading settings: " << cpp_strerror(r
) << dendl
;
402 bufferlist::iterator it
= bl
.begin();
404 dout(20) << __func__
<< " split_rand_factor = " << settings
.split_rand_factor
<< dendl
;
408 /* LFNIndex virtual method implementations */
409 int HashIndex::_created(const vector
<string
> &path
,
410 const ghobject_t
&oid
,
411 const string
&mangled_name
) {
414 r
= get_info(path
, &info
);
418 r
= set_info(path
, info
);
422 if (must_split(info
)) {
423 dout(1) << __func__
<< " " << path
<< " has " << info
.objs
424 << " objects, starting split." << dendl
;
425 int r
= initiate_split(path
, info
);
428 r
= complete_split(path
, info
);
429 dout(1) << __func__
<< " " << path
<< " split completed."
437 int HashIndex::_remove(const vector
<string
> &path
,
438 const ghobject_t
&oid
,
439 const string
&mangled_name
) {
441 r
= remove_object(path
, oid
);
445 r
= get_info(path
, &info
);
449 r
= set_info(path
, info
);
452 if (must_merge(info
)) {
453 r
= initiate_merge(path
, info
);
456 return complete_merge(path
, info
);
462 int HashIndex::_lookup(const ghobject_t
&oid
,
463 vector
<string
> *path
,
464 string
*mangled_name
,
466 vector
<string
> path_comp
;
467 get_path_components(oid
, &path_comp
);
468 vector
<string
>::iterator next
= path_comp
.begin();
471 int r
= path_exists(*path
, &exists
);
480 if (next
== path_comp
.end())
482 path
->push_back(*(next
++));
484 return get_mangled_name(*path
, oid
, mangled_name
, hardlink
);
487 int HashIndex::_collection_list_partial(const ghobject_t
&start
,
488 const ghobject_t
&end
,
490 vector
<ghobject_t
> *ls
,
497 dout(20) << __func__
<< " start:" << start
<< " end:" << end
<< "-" << max_count
<< " ls.size " << ls
->size() << dendl
;
498 return list_by_hash(path
, end
, max_count
, next
, ls
);
501 int HashIndex::prep_delete() {
502 return recursive_remove(vector
<string
>());
505 int HashIndex::_pre_hash_collection(uint32_t pg_num
, uint64_t expected_num_objs
) {
508 subdir_info_s root_info
;
509 // Make sure there is neither objects nor sub-folders
510 // in this collection
511 ret
= get_info(path
, &root_info
);
515 // Do the folder splitting first
516 ret
= pre_split_folder(pg_num
, expected_num_objs
);
519 // Initialize the folder info starting from root
520 return init_split_folder(path
, 0);
523 int HashIndex::pre_split_folder(uint32_t pg_num
, uint64_t expected_num_objs
)
525 // If folder merging is enabled (by setting the threshold positive),
527 if (merge_threshold
> 0)
529 const coll_t c
= coll();
530 // Do not split if the expected number of objects in this collection is zero (by default)
531 if (expected_num_objs
== 0)
534 // Calculate the number of leaf folders (which actually store files)
535 // need to be created
536 const uint64_t objs_per_folder
= ((uint64_t)(abs(merge_threshold
)) * (uint64_t)split_multiplier
+ settings
.split_rand_factor
) * 16;
537 uint64_t leavies
= expected_num_objs
/ objs_per_folder
;
539 if (leavies
== 0 || expected_num_objs
== objs_per_folder
)
543 if (!c
.is_pg_prefix(&spgid
))
545 const ps_t ps
= spgid
.pgid
.ps();
547 // the most significant bits of pg_num
548 const int pg_num_bits
= calc_num_bits(pg_num
- 1);
550 // calculate the number of levels we only create one sub folder
551 int num
= pg_num_bits
/ 4;
552 // pg num's hex value is like 1xxx,xxxx,xxxx but not 1111,1111,1111,
553 // so that splitting starts at level 3
554 if (pg_num_bits
% 4 == 0 && pg_num
< ((uint32_t)1 << pg_num_bits
)) {
559 // Start with creation that only has one subfolder
560 vector
<string
> paths
;
563 ps_t v
= tmp_id
& 0x0000000f;
564 paths
.push_back(to_hex(v
));
565 ret
= create_path(paths
);
566 if (ret
< 0 && ret
!= -EEXIST
)
568 tmp_id
= tmp_id
>> 4;
571 // Starting from here, we can split by creating multiple subfolders
572 const int left_bits
= pg_num_bits
- dump_num
* 4;
573 // this variable denotes how many bits (for this level) that can be
574 // used for sub folder splitting
575 int split_bits
= 4 - left_bits
;
576 // the below logic is inspired by rados.h#ceph_stable_mod,
577 // it basically determines how many sub-folders should we
578 // create for splitting
579 assert(pg_num_bits
> 0); // otherwise BAD_SHIFT
580 if (((1 << (pg_num_bits
- 1)) | ps
) >= pg_num
) {
583 const uint32_t subs
= (1 << split_bits
);
584 // Calculate how many levels we create starting from here
587 while (leavies
> 1) {
589 leavies
= leavies
>> 4;
591 for (uint32_t i
= 0; i
< subs
; ++i
) {
592 assert(split_bits
<= 4); // otherwise BAD_SHIFT
593 int v
= tmp_id
| (i
<< ((4 - split_bits
) % 4));
594 paths
.push_back(to_hex(v
));
595 ret
= create_path(paths
);
596 if (ret
< 0 && ret
!= -EEXIST
)
598 ret
= recursive_create_path(paths
, level
);
606 int HashIndex::init_split_folder(vector
<string
> &path
, uint32_t hash_level
)
608 // Get the number of sub directories for the current path
609 vector
<string
> subdirs
;
610 int ret
= list_subdirs(path
, &subdirs
);
614 info
.subdirs
= subdirs
.size();
615 info
.hash_level
= hash_level
;
616 ret
= set_info(path
, info
);
619 ret
= fsync_dir(path
);
623 // Do the same for subdirs
624 vector
<string
>::const_iterator iter
;
625 for (iter
= subdirs
.begin(); iter
!= subdirs
.end(); ++iter
) {
626 path
.push_back(*iter
);
627 ret
= init_split_folder(path
, hash_level
+ 1);
635 int HashIndex::recursive_create_path(vector
<string
>& path
, int level
)
639 for (int i
= 0; i
< 16; ++i
) {
640 path
.push_back(to_hex(i
));
641 int ret
= create_path(path
);
642 if (ret
< 0 && ret
!= -EEXIST
)
644 ret
= recursive_create_path(path
, level
- 1);
652 int HashIndex::recursive_remove(const vector
<string
> &path
) {
653 return _recursive_remove(path
, true);
656 int HashIndex::_recursive_remove(const vector
<string
> &path
, bool top
) {
657 vector
<string
> subdirs
;
658 dout(20) << __func__
<< " path=" << path
<< dendl
;
659 int r
= list_subdirs(path
, &subdirs
);
662 map
<string
, ghobject_t
> objects
;
663 r
= list_objects(path
, 0, 0, &objects
);
666 if (!objects
.empty())
668 vector
<string
> subdir(path
);
669 for (vector
<string
>::iterator i
= subdirs
.begin();
672 subdir
.push_back(*i
);
673 r
= _recursive_remove(subdir
, false);
681 return remove_path(path
);
684 int HashIndex::start_col_split(const vector
<string
> &path
) {
686 InProgressOp
op_tag(InProgressOp::COL_SPLIT
, path
);
688 int r
= add_attr_path(vector
<string
>(), IN_PROGRESS_OP_TAG
, bl
);
691 return fsync_dir(vector
<string
>());
694 int HashIndex::start_split(const vector
<string
> &path
) {
696 InProgressOp
op_tag(InProgressOp::SPLIT
, path
);
698 int r
= add_attr_path(vector
<string
>(), IN_PROGRESS_OP_TAG
, bl
);
701 return fsync_dir(vector
<string
>());
704 int HashIndex::start_merge(const vector
<string
> &path
) {
706 InProgressOp
op_tag(InProgressOp::MERGE
, path
);
708 int r
= add_attr_path(vector
<string
>(), IN_PROGRESS_OP_TAG
, bl
);
711 return fsync_dir(vector
<string
>());
714 int HashIndex::end_split_or_merge(const vector
<string
> &path
) {
715 return remove_attr_path(vector
<string
>(), IN_PROGRESS_OP_TAG
);
718 int HashIndex::get_info(const vector
<string
> &path
, subdir_info_s
*info
) {
720 int r
= get_attr_path(path
, SUBDIR_ATTR
, buf
);
723 bufferlist::iterator bufiter
= buf
.begin();
724 info
->decode(bufiter
);
725 assert(path
.size() == (unsigned)info
->hash_level
);
729 int HashIndex::set_info(const vector
<string
> &path
, const subdir_info_s
&info
) {
731 assert(path
.size() == (unsigned)info
.hash_level
);
733 return add_attr_path(path
, SUBDIR_ATTR
, buf
);
736 bool HashIndex::must_merge(const subdir_info_s
&info
) {
737 return (info
.hash_level
> 0 &&
738 merge_threshold
> 0 &&
739 info
.objs
< (unsigned)merge_threshold
&&
743 bool HashIndex::must_split(const subdir_info_s
&info
) {
744 return (info
.hash_level
< (unsigned)MAX_HASH_LEVEL
&&
745 info
.objs
> ((unsigned)(abs(merge_threshold
) * split_multiplier
+ settings
.split_rand_factor
) * 16));
749 int HashIndex::initiate_merge(const vector
<string
> &path
, subdir_info_s info
) {
750 return start_merge(path
);
753 int HashIndex::complete_merge(const vector
<string
> &path
, subdir_info_s info
) {
754 vector
<string
> dst
= path
;
756 subdir_info_s dstinfo
;
758 r
= path_exists(path
, &exists
);
761 r
= get_info(dst
, &dstinfo
);
765 r
= move_objects(path
, dst
);
771 r
= remove_path(path
);
775 if (must_merge(dstinfo
)) {
776 r
= initiate_merge(dst
, dstinfo
);
782 return complete_merge(dst
, dstinfo
);
787 return end_split_or_merge(path
);
790 int HashIndex::initiate_split(const vector
<string
> &path
, subdir_info_s info
) {
791 return start_split(path
);
794 int HashIndex::complete_split(const vector
<string
> &path
, subdir_info_s info
) {
795 int level
= info
.hash_level
;
796 map
<string
, ghobject_t
> objects
;
797 vector
<string
> dst
= path
;
800 r
= list_objects(path
, 0, 0, &objects
);
803 vector
<string
> subdirs_vec
;
804 r
= list_subdirs(path
, &subdirs_vec
);
808 subdirs
.insert(subdirs_vec
.begin(), subdirs_vec
.end());
809 map
<string
, map
<string
, ghobject_t
> > mapped
;
810 map
<string
, ghobject_t
> moved
;
812 for (map
<string
, ghobject_t
>::iterator i
= objects
.begin();
815 vector
<string
> new_path
;
816 get_path_components(i
->second
, &new_path
);
817 mapped
[new_path
[level
]][i
->first
] = i
->second
;
819 for (map
<string
, map
<string
, ghobject_t
> >::iterator i
= mapped
.begin();
822 dst
[level
] = i
->first
;
823 /* If the info already exists, it must be correct,
824 * we may be picking up a partially finished split */
826 // subdir has already been fully copied
827 if (subdirs
.count(i
->first
) && !get_info(dst
, &temp
)) {
828 for (map
<string
, ghobject_t
>::iterator j
= i
->second
.begin();
829 j
!= i
->second
.end();
831 moved
[j
->first
] = j
->second
;
833 objects
.erase(j
->first
);
839 subdir_info_s info_new
;
840 info_new
.objs
= i
->second
.size();
841 info_new
.subdirs
= 0;
842 info_new
.hash_level
= level
+ 1;
843 if (must_merge(info_new
) && !subdirs
.count(i
->first
)) {
848 // Subdir doesn't yet exist
849 if (!subdirs
.count(i
->first
)) {
851 r
= create_path(dst
);
854 } // else subdir has been created but only partially copied
856 for (map
<string
, ghobject_t
>::iterator j
= i
->second
.begin();
857 j
!= i
->second
.end();
859 moved
[j
->first
] = j
->second
;
861 objects
.erase(j
->first
);
862 r
= link_object(path
, dst
, j
->second
, j
->first
);
863 // May be a partially finished split
864 if (r
< 0 && r
!= -EEXIST
) {
873 // Presence of info must imply that all objects have been copied
874 r
= set_info(dst
, info_new
);
884 r
= remove_objects(path
, moved
, &objects
);
887 info
.objs
= objects
.size();
888 r
= reset_attr(path
);
894 return end_split_or_merge(path
);
897 void HashIndex::get_path_components(const ghobject_t
&oid
,
898 vector
<string
> *path
) {
899 char buf
[MAX_HASH_LEVEL
+ 1];
900 snprintf(buf
, sizeof(buf
), "%.*X", MAX_HASH_LEVEL
, (uint32_t)oid
.hobj
.get_nibblewise_key());
902 // Path components are the hex characters of oid.hobj.hash, least
904 for (int i
= 0; i
< MAX_HASH_LEVEL
; ++i
) {
905 path
->push_back(string(&buf
[i
], 1));
909 string
HashIndex::get_hash_str(uint32_t hash
) {
910 char buf
[MAX_HASH_LEVEL
+ 1];
911 snprintf(buf
, sizeof(buf
), "%.*X", MAX_HASH_LEVEL
, hash
);
913 for (int i
= 0; i
< MAX_HASH_LEVEL
; ++i
) {
914 retval
.push_back(buf
[MAX_HASH_LEVEL
- 1 - i
]);
919 string
HashIndex::get_path_str(const ghobject_t
&oid
) {
920 assert(!oid
.is_max());
921 return get_hash_str(oid
.hobj
.get_hash());
924 uint32_t HashIndex::hash_prefix_to_hash(string prefix
) {
925 while (prefix
.size() < sizeof(uint32_t) * 2) {
926 prefix
.push_back('0');
929 sscanf(prefix
.c_str(), "%x", &hash
);
931 hash
= ((hash
& 0x0f0f0f0f) << 4) | ((hash
& 0xf0f0f0f0) >> 4);
932 hash
= ((hash
& 0x00ff00ff) << 8) | ((hash
& 0xff00ff00) >> 8);
933 hash
= ((hash
& 0x0000ffff) << 16) | ((hash
& 0xffff0000) >> 16);
937 int HashIndex::get_path_contents_by_hash_bitwise(
938 const vector
<string
> &path
,
939 const ghobject_t
*next_object
,
940 set
<string
, CmpHexdigitStringBitwise
> *hash_prefixes
,
941 set
<pair
<string
, ghobject_t
>, CmpPairBitwise
> *objects
)
943 map
<string
, ghobject_t
> rev_objects
;
945 r
= list_objects(path
, 0, 0, &rev_objects
);
949 for (map
<string
, ghobject_t
>::iterator i
= rev_objects
.begin();
950 i
!= rev_objects
.end();
952 if (next_object
&& i
->second
< *next_object
)
954 string hash_prefix
= get_path_str(i
->second
);
955 hash_prefixes
->insert(hash_prefix
);
956 objects
->insert(pair
<string
, ghobject_t
>(hash_prefix
, i
->second
));
958 vector
<string
> subdirs
;
959 r
= list_subdirs(path
, &subdirs
);
963 // sort subdirs bitwise (by reversing hex digit nibbles)
964 std::sort(subdirs
.begin(), subdirs
.end(), cmp_hexdigit_bitwise
);
966 // Local to this function, we will convert the prefix strings
967 // (previously simply the reversed hex digits) to also have each
968 // digit's nibbles reversed. This will make the strings sort
971 for (vector
<string
>::const_iterator i
= path
.begin();
974 cur_prefix
.append(reverse_hexdigit_bits_string(*i
));
976 string next_object_string
;
978 next_object_string
= reverse_hexdigit_bits_string(get_path_str(*next_object
));
979 for (vector
<string
>::iterator i
= subdirs
.begin();
982 string candidate
= cur_prefix
+ reverse_hexdigit_bits_string(*i
);
984 if (next_object
->is_max())
986 if (candidate
< next_object_string
.substr(0, candidate
.size()))
989 // re-reverse the hex digit nibbles for the caller
990 hash_prefixes
->insert(reverse_hexdigit_bits_string(candidate
));
995 int HashIndex::list_by_hash(const vector
<string
> &path
,
996 const ghobject_t
&end
,
999 vector
<ghobject_t
> *out
)
1002 return list_by_hash_bitwise(path
, end
, max_count
, next
, out
);
1005 int HashIndex::list_by_hash_bitwise(
1006 const vector
<string
> &path
,
1007 const ghobject_t
& end
,
1010 vector
<ghobject_t
> *out
)
1012 vector
<string
> next_path
= path
;
1013 next_path
.push_back("");
1014 set
<string
, CmpHexdigitStringBitwise
> hash_prefixes
;
1015 set
<pair
<string
, ghobject_t
>, CmpPairBitwise
> objects
;
1016 int r
= get_path_contents_by_hash_bitwise(path
,
1022 for (set
<string
, CmpHexdigitStringBitwise
>::iterator i
= hash_prefixes
.begin();
1023 i
!= hash_prefixes
.end();
1025 dout(20) << __func__
<< " prefix " << *i
<< dendl
;
1026 set
<pair
<string
, ghobject_t
>, CmpPairBitwise
>::iterator j
= objects
.lower_bound(
1027 make_pair(*i
, ghobject_t()));
1028 if (j
== objects
.end() || j
->first
!= *i
) {
1029 *(next_path
.rbegin()) = *(i
->rbegin());
1030 ghobject_t next_recurse
;
1032 next_recurse
= *next
;
1033 r
= list_by_hash_bitwise(next_path
,
1041 if (!next_recurse
.is_max()) {
1043 *next
= next_recurse
;
1047 while (j
!= objects
.end() && j
->first
== *i
) {
1048 if (max_count
> 0 && out
->size() == (unsigned)max_count
) {
1053 if (j
->second
>= end
) {
1058 if (!next
|| j
->second
>= *next
) {
1059 dout(20) << __func__
<< " prefix " << *i
<< " ob " << j
->second
<< dendl
;
1060 out
->push_back(j
->second
);
1067 *next
= ghobject_t::get_max();