42 #include <boost/lexical_cast.hpp>
48 #include <sys/param.h>
56 #include <sys/types.h>
57 #if defined(osx_platform)
58 #include <sys/malloc.h>
69 #if defined(solaris_platform)
70 #include <sys/statvfs.h>
72 #if defined(linux_platform)
85 template<
typename DEST_TYPE >
93 result =
PASSMSG(
"resource context is invalid", ret );
123 std::string this_name{};
129 ret = _parser.
next(this_name, child);
135 _ret_resc = (*cmap_ref)[child].second;
145 for (
auto& oper : _object_list) {
146 if (oper.object() == (*_object.get())) {
157 const std::string& _oper ) {
167 std::stringstream msg;
169 msg <<
" - Failed to get the object list from the resource.";
170 result =
PASSMSG( msg.str(), ret );
174 bool mismatched =
false;
188 "Existing object operation: \"%s\" does not match current operation: \"%s\".",
189 oper.operation().c_str(), _oper.c_str() );
192 oper.object() = *( file_obj.get() );
193 oper.operation() = _oper;
194 object_list.push_back( oper );
196 result =
ASSERT_PASS( ret,
"Failed to set the object list property on the resource." );
199 if ( !result.
ok() ) {
218 bool resc_hier_in_keyword{};
220 if (file_obj->l1_desc_idx() > 0) {
225 "[%s] - No hierarchy string found in keywords for file object.") %
226 __FUNCTION__).str().c_str());
228 selected_parser.set_string(hier_str);
229 resc_hier_in_keyword = selected_parser.resc_in_hier(
name);
233 if (!resc_hier_in_keyword) {
234 const auto& selected_hier = file_obj->resc_hier();
235 if (selected_hier.empty()) {
238 "[%s] - file object does not have a resource hierarchy.") %
239 __FUNCTION__).str().c_str());
241 selected_parser.set_string(selected_hier);
242 if (!selected_parser.resc_in_hier(
name)) {
245 "[%s] - Replicating a file object which does not exist in this hierarchy.") %
246 __FUNCTION__).str().c_str());
250 _out_parser = selected_parser;
260 if (object_list_to_repl.empty()) {
269 if (child_list.empty()) {
280 ret = selected_parser.str(child);
284 "[%s] - Failed to get the hierarchy string from the parser.") %
285 __FUNCTION__).str(), ret );
287 std::string root_resc{};
288 ret = selected_parser.first_resc(root_resc);
292 "[%s] - Failed to get the root resource from the parser.") %
293 __FUNCTION__).str(), ret );
304 ret = replicator.
replicate(_ctx, child_list, object_list_to_repl);
308 "[%s] - Failed to replicate the create/write operation to the siblings.") %
309 __FUNCTION__).str(), ret );
327 ret = replCheckParams< irods::file_object >( _ctx );
328 if ( ( result =
ASSERT_PASS( ret,
"Error checking passed paramters." ) ).ok() ) {
332 parser.set_string( file_obj->resc_hier() );
335 if ( ( result =
ASSERT_PASS( ret,
"Failed to get the next resource in hierarchy." ) ).ok() ) {
337 result =
ASSERT_PASS( ret,
"Failed while calling child operation." );
348 ret = replCheckParams< irods::file_object >( _ctx );
350 std::stringstream msg;
352 msg <<
" - Error found checking passed parameters.";
353 result =
PASSMSG( msg.str(), ret );
358 parser.set_string( file_obj->resc_hier() );
362 std::stringstream msg;
364 msg <<
" - Failed to get the next resource in hierarchy.";
365 result =
PASSMSG( msg.str(), ret );
370 std::stringstream msg;
372 msg <<
" - Failed while calling child operation.";
373 result =
PASSMSG( msg.str(), ret );
405 if(num_repl < child_list.size()) {
407 std::vector<size_t> picked_indicies{};
409 size_t rand_index{irods::getRandom<size_t>() % child_list.size()};
411 picked_indicies.begin(),
412 picked_indicies.end(),
413 rand_index) == picked_indicies.end()) {
414 new_list.push_back(child_list[rand_index]);
415 picked_indicies.push_back(rand_index);
416 if(picked_indicies.size() >= num_repl) {
423 if(0 == new_list.size()) {
439 const std::string& operation) {
453 std::string current_resc_hier_str{};
454 ret = selected_parser.str(current_resc_hier_str,
name);
462 if (cmap_ref->
empty()) {
472 const std::string host_name(host_name_str);
477 for (
auto&
entry : *cmap_ref) {
478 auto child{
entry.second.second};
479 std::string child_name{};
486 if (selected_parser.resc_in_hier(child_name)) {
492 parser.set_string(current_resc_hier_str);
497 "[%s] - Failed calling redirect on the child \"%s\".") %
498 __FUNCTION__ %
entry.first).str(), ret);
500 else if (out_vote > 0.0) {
501 repl_vector.push_back(
parser);
525 irods::error ret{replCheckParams<irods::file_object>(_ctx)};
533 parser.set_string(file_obj->resc_hier());
554 if (sub_parser.resc_in_hier(
name)) {
560 if (
nullptr == open_type_str) {
562 (boost::format(
"[%s] - no OPEN_TYPE_KW value provided") %
563 __FUNCTION__).str());
567 std::string operation{};
569 switch(std::stoi(open_type_str)) {
577 throw std::invalid_argument(open_type_str);
580 catch (
const std::invalid_argument&) {
582 (boost::format(
"[%s] - invalid OPEN_TYPE_KW value provided:[%s]") %
583 __FUNCTION__ % open_type_str).str());
598 "[%s] - Failed to replicate create/write operation for object: \"%s\".") %
599 __FUNCTION__ % file_obj->logical_path()).str(), ret);
616 ret = replCheckParams< irods::file_object >( _ctx );
618 result =
PASSMSG(
"repl_file_create - bad params.", ret );
623 parser.set_string( file_obj->resc_hier() );
627 std::stringstream msg;
629 msg <<
" - Failed to get the next resource in hierarchy.";
630 result =
PASSMSG( msg.str(), ret );
635 std::stringstream msg;
637 msg <<
" - Failed while calling child operation.";
638 result =
PASSMSG( msg.str(), ret );
652 ret = replCheckParams< irods::file_object >( _ctx );
654 std::stringstream msg;
656 msg <<
" - bad params.";
657 result =
PASSMSG( msg.str(), ret );
662 parser.set_string( file_obj->resc_hier() );
666 std::stringstream msg;
668 msg <<
" - Failed to get the next resource in hierarchy.";
669 result =
PASSMSG( msg.str(), ret );
674 std::stringstream msg;
676 msg <<
" - Failed while calling child operation.";
677 result =
PASSMSG( msg.str(), ret );
693 ret = replCheckParams< irods::file_object >( _ctx );
695 std::stringstream msg;
697 msg <<
" - bad params.";
698 result =
PASSMSG( msg.str(), ret );
703 parser.set_string( file_obj->resc_hier() );
707 std::stringstream msg;
709 msg <<
" - Failed to get the next resource in hierarchy.";
710 result =
PASSMSG( msg.str(), ret );
715 std::stringstream msg;
717 msg <<
" - Failed while calling child operation.";
718 result =
PASSMSG( msg.str(), ret );
741 ret = replCheckParams< irods::file_object >( _ctx );
743 std::stringstream msg;
745 msg <<
" - bad params.";
746 result =
PASSMSG( msg.str(), ret );
751 parser.set_string( file_obj->resc_hier() );
755 std::stringstream msg;
757 msg <<
" - Failed to get the next resource in hierarchy.";
758 result =
PASSMSG( msg.str(), ret );
763 std::stringstream msg;
765 msg <<
" - Failed while calling child operation.";
766 result =
PASSMSG( msg.str(), ret );
769 result =
CODE( ret.code() );
787 ret = replCheckParams< irods::file_object >( _ctx );
788 if ( ( result =
ASSERT_PASS( ret,
"Bad params." ) ).ok() ) {
792 parser.set_string( file_obj->resc_hier() );
795 if ( ( result =
ASSERT_PASS( ret,
"Failed to get the next resource in hierarchy." ) ).ok() ) {
798 result =
ASSERT_PASS( ret,
"Failed while calling child operation." );
812 ret = replCheckParams< irods::data_object >( _ctx );
814 std::stringstream msg;
816 msg <<
" - bad params.";
817 result =
PASSMSG( msg.str(), ret );
822 parser.set_string( data_obj->resc_hier() );
826 std::stringstream msg;
828 msg <<
" - Failed to get the next resource in hierarchy.";
829 result =
PASSMSG( msg.str(), ret );
834 std::stringstream msg;
836 msg <<
" - Failed while calling child operation.";
837 result =
PASSMSG( msg.str(), ret );
852 struct stat* _statbuf ) {
856 ret = replCheckParams< irods::data_object >( _ctx );
858 std::stringstream msg;
860 msg <<
" - bad params.";
861 result =
PASSMSG( msg.str(), ret );
866 parser.set_string( data_obj->resc_hier() );
870 std::stringstream msg;
872 msg <<
" - Failed to get the next resource in hierarchy.";
873 result =
PASSMSG( msg.str(), ret );
878 std::stringstream msg;
880 msg <<
" - Failed while calling child operation.";
881 result =
PASSMSG( msg.str(), ret );
900 ret = replCheckParams< irods::file_object >( _ctx );
902 std::stringstream msg;
904 msg <<
" - bad params.";
905 result =
PASSMSG( msg.str(), ret );
910 parser.set_string( file_obj->resc_hier() );
914 std::stringstream msg;
916 msg <<
" - Failed to get the next resource in hierarchy.";
917 result =
PASSMSG( msg.str(), ret );
922 std::stringstream msg;
924 msg <<
" - Failed while calling child operation.";
925 result =
PASSMSG( msg.str(), ret );
942 ret = replCheckParams< irods::collection_object >( _ctx );
944 std::stringstream msg;
946 msg <<
" - bad params.";
947 result =
PASSMSG( msg.str(), ret );
952 parser.set_string( collection_obj->resc_hier() );
956 std::stringstream msg;
958 msg <<
" - Failed to get the next resource in hierarchy.";
959 result =
PASSMSG( msg.str(), ret );
964 std::stringstream msg;
966 msg <<
" - Failed while calling child operation.";
967 result =
PASSMSG( msg.str(), ret );
984 ret = replCheckParams< irods::collection_object >( _ctx );
986 std::stringstream msg;
988 msg <<
" - bad params.";
989 result =
PASSMSG( msg.str(), ret );
994 parser.set_string( file_obj->resc_hier() );
998 std::stringstream msg;
1000 msg <<
" - Failed to get the next resource in hierarchy.";
1001 result =
PASSMSG( msg.str(), ret );
1006 std::stringstream msg;
1007 msg << __FUNCTION__;
1008 msg <<
" - Failed while calling child operation.";
1009 result =
PASSMSG( msg.str(), ret );
1026 ret = replCheckParams< irods::collection_object >( _ctx );
1028 std::stringstream msg;
1029 msg << __FUNCTION__;
1030 msg <<
" - bad params.";
1031 result =
PASSMSG( msg.str(), ret );
1036 parser.set_string( collection_obj->resc_hier() );
1040 std::stringstream msg;
1041 msg << __FUNCTION__;
1042 msg <<
" - Failed to get the next resource in hierarchy.";
1043 result =
PASSMSG( msg.str(), ret );
1048 std::stringstream msg;
1049 msg << __FUNCTION__;
1050 msg <<
" - Failed while calling child operation.";
1051 result =
PASSMSG( msg.str(), ret );
1068 ret = replCheckParams< irods::collection_object >( _ctx );
1070 std::stringstream msg;
1071 msg << __FUNCTION__;
1072 msg <<
" - bad params.";
1073 result =
PASSMSG( msg.str(), ret );
1078 parser.set_string( collection_obj->resc_hier() );
1082 std::stringstream msg;
1083 msg << __FUNCTION__;
1084 msg <<
" - Failed to get the next resource in hierarchy.";
1085 result =
PASSMSG( msg.str(), ret );
1090 std::stringstream msg;
1091 msg << __FUNCTION__;
1092 msg <<
" - Failed while calling child operation.";
1093 result =
PASSMSG( msg.str(), ret );
1111 ret = replCheckParams< irods::collection_object >( _ctx );
1113 std::stringstream msg;
1114 msg << __FUNCTION__;
1115 msg <<
" - bad params.";
1116 result =
PASSMSG( msg.str(), ret );
1121 parser.set_string( collection_obj->resc_hier() );
1125 std::stringstream msg;
1126 msg << __FUNCTION__;
1127 msg <<
" - Failed to get the next resource in hierarchy.";
1128 result =
PASSMSG( msg.str(), ret );
1133 std::stringstream msg;
1134 msg << __FUNCTION__;
1135 msg <<
" - Failed while calling child operation.";
1136 result =
PASSMSG( msg.str(), ret );
1150 const char* _new_file_name ) {
1154 ret = replCheckParams< irods::file_object >( _ctx );
1156 std::stringstream msg;
1157 msg << __FUNCTION__;
1158 msg <<
" - bad params.";
1159 result =
PASSMSG( msg.str(), ret );
1164 parser.set_string( file_obj->resc_hier() );
1168 std::stringstream msg;
1169 msg << __FUNCTION__;
1170 msg <<
" - Failed to get the next resource in hierarchy.";
1171 result =
PASSMSG( msg.str(), ret );
1176 std::stringstream msg;
1177 msg << __FUNCTION__;
1178 msg <<
" - Failed while calling child operation.";
1179 result =
PASSMSG( msg.str(), ret );
1197 ret = replCheckParams<irods::file_object>( _ctx );
1199 std::stringstream msg;
1200 msg << __FUNCTION__;
1201 msg <<
" - bad params.";
1202 result =
PASSMSG( msg.str(), ret );
1207 parser.set_string( ptr->resc_hier() );
1211 std::stringstream msg;
1212 msg << __FUNCTION__;
1213 msg <<
" - Failed to get the next resource in hierarchy.";
1214 result =
PASSMSG( msg.str(), ret );
1219 std::stringstream msg;
1220 msg << __FUNCTION__;
1221 msg <<
" - Failed while calling child operation.";
1222 result =
PASSMSG( msg.str(), ret );
1239 ret = replCheckParams< irods::file_object >( _ctx );
1241 std::stringstream msg;
1242 msg << __FUNCTION__;
1243 msg <<
" - bad params.";
1244 result =
PASSMSG( msg.str(), ret );
1249 parser.set_string( file_obj->resc_hier() );
1253 std::stringstream msg;
1254 msg << __FUNCTION__;
1255 msg <<
" - Failed to get the next resource in hierarchy.";
1256 result =
PASSMSG( msg.str(), ret );
1261 std::stringstream msg;
1262 msg << __FUNCTION__;
1263 msg <<
" - Failed while calling child operation.";
1264 result =
PASSMSG( msg.str(), ret );
1280 const char* _cache_file_name ) {
1284 ret = replCheckParams< irods::file_object >( _ctx );
1286 std::stringstream msg;
1287 msg << __FUNCTION__;
1288 msg <<
" - bad params.";
1289 result =
PASSMSG( msg.str(), ret );
1294 parser.set_string( file_obj->resc_hier() );
1298 std::stringstream msg;
1299 msg << __FUNCTION__;
1300 msg <<
" - Failed to get the next resource in hierarchy.";
1301 result =
PASSMSG( msg.str(), ret );
1304 ret = child->call<
const char* >(
1310 std::stringstream msg;
1311 msg << __FUNCTION__;
1312 msg <<
" - Failed while calling child operation.";
1313 result =
PASSMSG( msg.str(), ret );
1326 const char* _cache_file_name ) {
1330 ret = replCheckParams< irods::file_object >( _ctx );
1332 std::stringstream msg;
1333 msg << __FUNCTION__;
1334 msg <<
" - bad params.";
1335 result =
PASSMSG( msg.str(), ret );
1340 parser.set_string( file_obj->resc_hier() );
1344 std::stringstream msg;
1345 msg << __FUNCTION__;
1346 msg <<
" - Failed to get the next resource in hierarchy.";
1347 result =
PASSMSG( msg.str(), ret );
1352 std::stringstream msg;
1353 msg << __FUNCTION__;
1354 msg <<
" - Failed while calling child operation.";
1355 result =
PASSMSG( msg.str(), ret );
1384 const std::string* _operation,
1385 const std::string* _curr_host,
1393 for (
auto&
entry : *cmap_ref) {
1398 return PASSMSG((boost::format(
1399 "[%s] - Failed calling redirect on the child \"%s\".") %
1400 __FUNCTION__ %
entry.first).str(), ret);
1403 _redirect_map.insert(std::pair<float, irods::hierarchy_parser>(out_vote,
parser));
1413 float* _out_vote ) {
1415 std::vector<std::pair<float, irods::hierarchy_parser>> items;
1416 redirect_map_t::const_iterator itr = _redirect_map.cbegin();
1417 for( ; itr != _redirect_map.cend(); ++itr ) {
1418 if(itr->first > 0) {
1419 items.push_back(std::make_pair(itr->first, itr->second));
1423 size_t rand_index = irods::getRandom<size_t>() % items.size();
1424 std::vector<std::pair<float, irods::hierarchy_parser>>::iterator a_itr = items.begin();
1425 std::advance(a_itr, rand_index);
1426 *_out_vote = a_itr->first;
1427 *_out_parser = a_itr->second;
1435 const std::string& _operation,
1438 float* _out_vote ) {
1440 if (_redirect_map.empty()) {
1447 std::string read_policy{};
1459 const auto& it{_redirect_map.begin()};
1460 const auto& vote{it->first};
1461 const auto&
parser{it->second};
1470 const std::string* _operation,
1471 const std::string* _curr_host,
1473 float* _out_vote ) {
1474 if (
nullptr == _operation ||
nullptr == _curr_host ||
nullptr == _inout_parser ||
nullptr == _out_vote) {
1477 "[%s]: null parameters passed to redirect") %
1478 __FUNCTION__).str().c_str() );
1489 ret =
resolve_children(_ctx, _operation, _curr_host, *_inout_parser, redirect_map);
1495 ret =
select_child(_ctx, *_operation, redirect_map, _inout_parser, _out_vote);
1506 for (
auto&
entry : *cmap_ptr) {
1520 if (!kvp_err.
ok()) {
1525 if (it != kvp.end()) {
1527 return boost::lexical_cast<int>(it->second);
1528 }
catch (
const boost::bad_lexical_cast&) {
1541 return PASS(result);
1547 char invocation_timestamp[50];
1550 std::string resource_name;
1553 return PASS(result);
1570 const std::string* _opr ) {
1572 irods::error ret = replCheckParams< irods::file_object >( _ctx );
1574 std::stringstream msg;
1575 msg << __FUNCTION__;
1576 msg <<
" - bad params.";
1577 result =
PASSMSG( msg.str(), ret );
1582 parser.set_string( file_obj->resc_hier() );
1586 std::stringstream msg;
1587 msg << __FUNCTION__;
1588 msg <<
" - Failed to get the next resource in hierarchy.";
1589 result =
PASSMSG( msg.str(), ret );
1594 std::stringstream msg;
1595 msg << __FUNCTION__;
1596 msg <<
" - Failed while calling child operation.";
1597 result =
PASSMSG( msg.str(), ret );
1613 const std::string& _inst_name,
1614 const std::string& _context ) :
1619 if ( _context.empty() ) {
1633 if ( kvp_map.find(
NUM_REPL_KW ) != kvp_map.end() ) {
1636 "[%s] - resource [%s] is using deprecated context string [%s]") %
1641 int num_repl = boost::lexical_cast< int >( kvp_map[
NUM_REPL_KW ] );
1642 if( num_repl <= 0 ) {
1645 "[%s] - [%s] for resource [%s] is 0" ) %
1654 catch (
const boost::bad_lexical_cast& ) {
1657 "[%s] - failed to cast [%s] for resource [%s] to value [%s]") %
1670 if ( int_retry_attempts < 0 ) {
1673 "[%s] - [%s] for resource [%s] is < 0; using default value [%d]" ) %
1680 retry_attempts =
static_cast< decltype( retry_attempts )
>( int_retry_attempts );
1683 catch (
const boost::bad_lexical_cast& ) {
1686 "[%s] - failed to cast [%s] for resource [%s] to value [%s]; using default value [%d]") %
1701 if ( int_retry_delay <= 0 ) {
1704 "[%s] - [%s] for resource [%s] is <= 0; using default value [%d]" ) %
1711 retry_delay_in_seconds =
static_cast< decltype( retry_delay_in_seconds )
>( int_retry_delay );
1714 catch (
const boost::bad_lexical_cast& ) {
1717 "[%s] - failed to cast [%s] for resource [%s] to value [%s]; using default value [%d]") %
1731 if ( backoff_multiplier < 1 ) {
1734 "[%s] - [%s] for resource [%s] is < 1; using default value [%d]" ) %
1742 catch (
const boost::bad_lexical_cast& ) {
1745 "[%s] - failed to cast [%s] for resource [%s] to value [%s]; using default value [%d]") %
1755 if ( kvp_map.find(
READ_KW ) != kvp_map.end() ) {
1794 using namespace irods;
1795 using namespace std;
1814 function<error(plugin_context&,void*,int)>(
1829 function<error(plugin_context&, struct stat*)>(
1844 function<error(plugin_context&,struct rodsDirent**)>(
1849 function<error(plugin_context&, const char*)>(
1859 function<error(plugin_context&, long long, int)>(
1874 function<error(plugin_context&, const char*)>(
1879 function<error(plugin_context&, const char*)>(
1899 function<error(plugin_context&, const std::string*)>(
1909 function<error(plugin_context&,const std::string*, const std::string*, irods::hierarchy_parser*, float*)>(